String b = "无";// 初始化下棋是正确的
String str = "0123456789111111";
// 打印下第一行
System.out.print(" ");
for (int i = 0; istr.length(); i++) {
System.out.print(str.charAt(i));
}
System.out.println();
for (int i = 0; iqi.length; i++) {
System.out.print(str.charAt(i));
for (int j = 0; jqi[i].length; j++) {
if (name == '空') { // 还没开始下棋时,棋盘默认显示是'.'
qi[i][j] = '.';
}
if ((name == '黑')(i == row)(j == col)) {
if (qi[i][j] != '.') {// 下的位置已经有棋子了,返回false
b = "有棋";
} else {
qi[i][j] = '@';// 黑方下棋后的位置显示是'@'
if (win(qi, '@', row, col)) {
b = "黑棋子";
}
}
}
if ((name == '白')(i == row)(j == col)) {
if (qi[i][j] != '.') {
b = "有棋";
} else {
qi[i][j] = '*';// 黑方下棋后的位置显示是'*'
if (win(qi, '*', row, col)) {
b = "白棋子赢";
}
}
}
System.out.print(qi[i][j]);
}
System.out.println();
}
return b;
}
public static boolean win(char[][] qi, char ch, int row, int col) {
boolean b = false;
boolean ns = n2s(qi, ch, row, col);
boolean we = w2e(qi, ch, row, col);
boolean wnes = wn2es(qi, ch, row, col);
boolean enws = en2ws(qi, ch, row, col);
b = ns || we || wnes || enws;
return b;
}
/* 从北到南方向 */
public static boolean n2s(char[][] qi, char ch, int row, int col) {
boolean win = false;
int north = 0;// begin
int south = 0;// end
while (qi[row][col] == ch) {
row--;
if (row0) {
break;
}
}
row++;// row此时要++,不然等到下面的while(..)中的qi[row][col]永不会==ch
north = row;
while (qi[row][col] == ch) {
row++;
if (row15) {
break;
}
}
south = row;
if ((south - north) = 5) {
win = true;
}
return win;
}
/* 从西到东方向 */
public static boolean w2e(char[][] qi, char ch, int row, int col) {
boolean win = false;
int west = 0;// begin
int east = 0;// end
while (qi[row][col] == ch) {
col--;
if (col0) {
break;
}
}
col++;// col此时要++,不然等到下面的while(..)中的qi[row][col]永不会==ch
west = col;
while (qi[row][col] == ch) {
col++;
if (col15) {
break;
}
}
east = col;
if ((east - west) = 5) {
win = true;
}
return win;
}
/* 从西北到东南方向 */
public static boolean wn2es(char[][] qi, char ch, int row, int col) {
boolean win = false;
int wn = 0;// begin
int es = 0;// end
while (qi[row][col] == ch) {
row--;
col--;
if (row0 || col0) {
break;
}
}
row++;// row和col此时要++,不然等到下面的while(..)中的qi[row][col]永不会==ch
col++;
wn = row;
while (qi[row][col] == ch) {
row++;
col++;
if (row15 || col15) {
break;
}
}
es = row;
if ((es - wn) = 5) {
win = true;
}
return win;
}
/* 从东北到西南方向 */
public static boolean en2ws(char[][] qi, char ch, int row, int col) {
boolean win = false;
int en = 0;// begin
int ws = 0;// end
while (qi[row][col] == ch) {
row--;
col--;
if (row0 || col0) {
break;
}
}
row++;// row和col此时要++,不然等到下面的while(..)中的qi[row][col]永不会==ch
col++;
en = row;
while (qi[row][col] == ch) {
推荐阅读
- 保皇直播技巧,保皇游戏直播
- 云从科技新增ChatGPT概念,云从科技是什么公司
- 毕业设计模仿现有的网站吗,毕业设计论文去网上模仿
- 即时战略类游戏发展史小说,即时战略类的游戏
- linux命令逻辑符号 linux命令符号解释
- 电商如何发液体快递,液体怎么发国际快递
- 会展小程序开发功能,会展软件应用
- 无人直播图片动漫,无人直播效果怎么样
- php抓取首页数据 php获取当前页面url