【发布时间】:2015-07-16 16:50:41
【问题描述】:
我正在创建的国际象棋应用程序中的移动存在问题。这是检查移动是否有效的方法:
public boolean isMove(int row, int col, Pawn[][] board){
Pawn p = board[row][col];
int direction = 1;
if (this.color=='w') {
direction = -1;
}
if (p == null && this.col == col && ((this.row + direction) == row) || (this.row + 2 * direction) == row && ! this.hasMoved) { //can move
return true;
}
else if (p != null && p.color != this.color && row == (this.row + direction) && (col == (this.col - 1) || col == (this.col + 1))) { // can capture
return true;
}
return false;
}
这是我得到的一些输出:
这个移动应该是无效的,但它允许移动到那个方格。我认为我上面发布的方法有问题。
【问题讨论】:
-
你调试了吗?