This commit is contained in:
parent
9fd67df3c8
commit
a9a8d42651
|
|
@ -10,23 +10,31 @@ public class Move {
|
|||
int y = piece.getY();
|
||||
|
||||
switch (piece.getType()) {
|
||||
case Pawn:
|
||||
int dir = piece.isWhite() ? -1 : 1;
|
||||
int ny = y + dir;
|
||||
if (isInsideBoard(board, x, ny) && board.getPieceAt(x, ny) == null) {
|
||||
moves.add(new int[]{x, ny});
|
||||
}
|
||||
// Capture diagonale
|
||||
for (int dx : new int[]{-1, 1}) {
|
||||
int cx = x + dx;
|
||||
if (isInsideBoard(board, cx, ny)) {
|
||||
Piece target = board.getPieceAt(cx, ny);
|
||||
if (target != null && target.isWhite() != piece.isWhite()) {
|
||||
moves.add(new int[]{cx, ny});
|
||||
}
|
||||
case Pawn:
|
||||
int dir = piece.isWhite() ? -1 : 1;
|
||||
int ny = y + dir;
|
||||
|
||||
// Single forward move
|
||||
if (isInsideBoard(board, x, ny) && board.getPieceAt(x, ny) == null) {
|
||||
moves.add(new int[]{x, ny});
|
||||
|
||||
// Double forward move from initial position
|
||||
int startRow = piece.isWhite() ? 6 : 1;
|
||||
int ny2 = y + 2 * dir;
|
||||
if (y == startRow && isInsideBoard(board, x, ny2) && board.getPieceAt(x, ny2) == null) {
|
||||
moves.add(new int[]{x, ny2});
|
||||
}
|
||||
}
|
||||
for (int dx : new int[]{-1, 1}) {
|
||||
int cx = x + dx;
|
||||
if (isInsideBoard(board, cx, ny)) {
|
||||
Piece target = board.getPieceAt(cx, ny);
|
||||
if (target != null && target.isWhite() != piece.isWhite()) {
|
||||
moves.add(new int[]{cx, ny});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Rook:
|
||||
addLinearMoves(board, piece, moves, new int[][]{{1,0},{-1,0},{0,1},{0,-1}});
|
||||
|
|
|
|||
Loading…
Reference in New Issue