📄 telent.java
字号:
a[0][0] = -1;
n++;
}
if(chess[8][3] != 32)
{
a[1][0] = -1;
n++;
}
}
if(x == 6)
{
a = new int[2][2];
a[0][0] = 7;
a[0][1] = 8;
a[1][0] = 7;
a[1][1] = 4;
if(chess[8][8] != 32)
{
a[1][0] = -1;
n++;
}
if(chess[8][7] != 32)
{
a[0][0] = -1;
n++;
}
}
}
}
else
{
if(y == 4)
{
if(x == 6)
{
a = new int[2][2];
a[0][0] = 2;
a[0][1] = 8;
a[1][0] = 2;
a[1][1] = 4;
if(chess[3][7] != 32)
{
a[0][0] = -1;
n++;
}
if(chess[3][5] != 32)
{
a[1][0] = -1;
n++;
}
}
if(x == 2)
{
a = new int[2][2];
a[0][0] = 2;
a[0][1] = 0;
a[1][0] = 2;
a[1][1] = 4;
if(chess[3][3] != 32)
{
a[1][0] = -1;
n++;
}
if(chess[3][1] != 32)
{
a[0][0] = -1;
n++;
}
}
}
if(y == 2)
{
if(x == 4)
{
a = new int[4][2];
a[0][0] = 4;
a[0][1] = 6;
a[1][0] = 0;
a[1][1] = 6;
a[2][0] = 4;
a[2][1] = 2;
a[3][0] = 0;
a[3][1] = 2;
if(chess[3][5] != 32)
{
a[0][0] = -1;
n++;
}
if(chess[3][3] != 32)
{
a[2][0] = -1;
n++;
}
if(chess[1][3] != 32)
{
a[3][0] = -1;
n++;
}
if(chess[1][5] != 32)
{
a[1][0] = -1;
n++;
}
}
if(x == 8)
{
a = new int[2][2];
a[0][0] = 4;
a[0][1] = 6;
a[1][0] = 0;
a[1][1] = 6;
if(chess[3][7] != 32)
{
a[0][0] = -1;
n++;
}
if(chess[1][7] != 32)
{
a[1][0] = -1;
n++;
}
}
if(x == 0)
{
a = new int[2][2];
a[0][0] = 4;
a[0][1] = 2;
a[1][0] = 0;
a[1][1] = 2;
if(chess[3][1] != 32)
{
a[0][0] = -1;
n++;
}
if(chess[1][1] != 32)
{
a[1][0] = -1;
n++;
}
}
}
if(y == 0)
{
if(x == 6)
{
a = new int[2][2];
a[0][0] = 2;
a[0][1] = 8;
a[1][0] = 2;
a[1][1] = 4;
if(chess[1][7] != 32)
{
a[0][0] = -1;
n++;
}
if(chess[1][5] != 32)
{
a[1][0] = -1;
n++;
}
}
if(x == 2)
{
a = new int[2][2];
a[0][0] = 2;
a[0][1] = 0;
a[1][0] = 2;
a[1][1] = 4;
if(chess[1][3] != 32)
{
a[1][0] = -1;
n++;
}
if(chess[1][1] != 32)
{
a[0][0] = -1;
n++;
}
}
}
}
//去掉落脚点有自己棋子的
for(int i = 0 ; i < a.length ; i++)
{
int c = a[i][0];
int d = a[i][1];
if(c != -1)
{
int temp = chess[c][d];
if(code > 15 && temp >15 || (code < 16 && temp < 16))
{
n++;
a[i][0] = -1;
continue;
}
}
}
int tempLength = a.length - n;
tempCollection = new int[tempLength][2];
n = 0;
for(int i = 0 ; i < a.length ; i++)
{
if(a[i][0] != -1)
{
tempCollection[n][0] = a[i][0];
tempCollection[n][1] = a[i][1];
n++;
}
}
//System.out.println("获取象走步集合完毕");
}
//马的走步集合
if(code == 26 || code == 27 || code == 10 || code == 11)
{
//System.out.println("开始获取马走步集合");
int[][] a = new int[8][2];
int n = 0;
a[0][0] = y - 2;
a[0][1] = x + 1;
a[1][0] = y - 1;
a[1][1] = x + 2;
a[2][0] = y + 1;
a[2][1] = x + 2;
a[3][0] = y + 2;
a[3][1] = x + 1;
a[4][0] = y + 2;
a[4][1] = x - 1;
a[5][0] = y + 1;
a[5][1] = x - 2;
a[6][0] = y - 1;
a[6][1] = x - 2;
a[7][0] = y - 2;
a[7][1] = x - 1;
//System.out.println("马走步集合的初始数组获取完毕");
//去掉边界不合格的落脚点
for(int i = 0 ; i < 8 ; i++)
{
if(a[i][0] < 0 || a[i][0] > 9 || a[i][1] < 0 || a[i][1] > 8 || !(Math.abs(a[i][0] - y) == 2 && Math.abs(a[i][1] - x) == 1 || Math.abs(a[i][0] - y) == 1 && Math.abs(a[i][1] - x) == 2))
{
n++;
a[i][0] = -1;
continue;
}
}
//System.out.println("去掉马走步集合中边界不合格的");
//将落脚点有自己的棋子的去掉
for(int i = 0 ; i < 8 ; i++)
{
int c = a[i][0];
int d = a[i][1];
if(c != -1)
{//在边界合格的情况下,检测落脚点是否有自己的棋子
int temp = chess[c][d];
if(temp != 32)
{
if(code > 15 && temp >15)
{
n++;
a[i][0] = -1;
continue;
}
if(code < 16 && temp < 16)
{
n++;
a[i][0] = -1;
continue;
}
}
}
}
//System.out.println("去掉马走步集合中,落脚点有自己的棋子的");
//将有绊马腿现象出现的去掉
for(int i = 0 ; i < 8 ; i++)
{
int c = a[i][0];
int d = a[i][1];
if(c != -1)
{//对边界合格的走步,检测绊马腿现象
int yabs = Math.abs(c - y);
int xabs = Math.abs(d - x);
if(yabs < xabs)
{//横跳
if(d < x)
{
if(chess[y][x-1] != 32)
{
a[i][0] =-1;
n++;
continue;
}
}
else
{
if(chess[y][x+1] != 32)
{
a[i][0] =-1;
n++;
continue;
}
}
}
else
{//纵跳
if(c > y)
{
if(chess[y+1][x] != 32)
{
a[i][0] =-1;
n++;
continue;
}
}
else
{
if(chess[y-1][x] != 32)
{
a[i][0] =-1;
n++;
continue;
}
}
}
}
}
//System.out.println("去掉马走步集合中绊马腿的");
tempCollection = new int[8 - n][2];
//System.out.println("**********************************************马的走共有"+ (8 - n));
n = 0;
for(int i = 0 ; i < 8 ; i++)
{
if(a[i][0] != -1)
{
tempCollection[n][0] = a[i][0];
tempCollection[n][1] = a[i][1];
n++;
}
}
//System.out.println("获取马走步集合完毕");
}
//车的走步
if(code == 8 || code == 9 || code == 24 || code == 25)
{
//System.out.println("开始获取车走步集合");
int i = 0, nAll = 0;
int nleft = 0;
int[][] leftArray = null;
int nright = 0;
int[][] rightArray = null;
int nup = 0;
int[][] upArray = null;
int ndown = 0;
int[][] downArray = null;
for(i = x; i >= 0; i--)
{
if(i != x && chess[y][i] != 32)
{
if(code < 16 && chess[y][i] < 16 || code > 15 && chess[y][i] > 15)
{
i++;
break;
}
else
break;
}
}
if(i == -1)
i++;
nleft = x - i;
if(nleft != 0)
{
leftArray = new int[nleft][2];
for(int j = 0; j < nleft; j++)
{
leftArray[j][0] = y;
leftArray[j][1] = i + j;
//System.out.println("车的第"+j+"个左走步集合y:"+leftArray[j][0]+"x:"+leftArray[j][1]);
}
}
//System.out.println("车的左走步集合获取完毕");
for(i = x; i < 9; i++)
{
if(i != x && chess[y][i] != 32)
{
if(code < 16 && chess[y][i] < 16 || code > 15 && chess[y][i] > 15)
{
i--;
break;
}
else
break;
}
}
if(i == 9)
i--;
nright = i - x;
if(nright != 0)
{
rightArray = new int[nright][2];
for(int j = 0; j < nright; j++)
{
rightArray[j][0] = y;
rightArray[j][1] = i - j;
//System.out.println("车的第"+j+"个右走步集合y:"+rightArray[j][0]+"x:"+rightArray[j][1]);
}
}
//System.out.println("车的右走步集合获取完毕");
for(i = y; i < 10; i++)
{
if(i != y && chess[i][x] != 32)
{
if(code < 16 && chess[i][x] < 16 || code > 15 && chess[i][x] > 15)
{
i--;
break;
}
else
break;
}
}
if(i == 10)
i--;
ndown = i - y;
if(ndown != 0)
{
downArray = new int[ndown][2];
for(int j = 0; j < ndown; j++)
{
downArray[j][0] = i - j;
downArray[j][1] = x;
//System.out.println("车的第"+j+"个下走步集合y:"+downArray[j][0]+"x:"+downArray[j][1]);
}
}
//System.out.println("车的下走步集合获取完毕");
for(i = y; i >= 0; i--)
{
if(i != y && chess[i][x] != 32)
{
if(code < 16 && chess[i][x] < 16 || code > 15 && chess[i][x] > 15)
{
i++;
break;
}
else
break;
}
}
if(i == -1)
i++;
nup = y - i;
if(nup != 0)
{
upArray = new int[nup][2];
for(int j = 0; j < nup; j++)
{
upArray[j][0] = i + j;
upArray[j][1] = x;
//System.out.println("车的第"+j+"个上走步集合y:"+upArray[j][0]+"x:"+upArray[j][1]);
}
}
//System.out.println("车的上走步集合获取完毕");
nAll = nleft + nright + nup + ndown;
tempCollection = new int[nAll][2];
if(nleft != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -