supprime getValidMoves from board class

This commit is contained in:
carol 2025-05-13 16:07:03 +02:00
parent c2cf49475d
commit 7fa75a6862
1 changed files with 1 additions and 48 deletions

View File

@ -130,54 +130,7 @@ public class Board {
}
private ArrayList<int[]> getValidMoves(Piece piece) {
ArrayList<int[]> moves = new ArrayList<>();
int x = piece.getX();
int y = piece.getY();
PieceType type = piece.getType();
if (type == PieceType.Pawn) {
int dir = piece.isWhite() ? 1 : -1;
int startRow = piece.isWhite() ? 1 : 6;
// Normal forward moves
int oneStep = y + dir;
if (inBounds(x, oneStep) && board[x][oneStep] == null) {
moves.add(new int[]{x, oneStep});
// Two-step move from starting position
int twoStep = y + 2 * dir;
if (y == startRow && inBounds(x, twoStep) && board[x][twoStep] == null && board[x][oneStep] == null) {
moves.add(new int[]{x, twoStep});
}
}
// Capture diagonals (including en passant)
for (int dx : new int[]{-1, 1}) {
int nx = x + dx;
int ny = y + dir;
if (inBounds(nx, ny)) {
// Normal capture
if (board[nx][ny] != null && board[nx][ny].isWhite() != piece.isWhite()) {
moves.add(new int[]{nx, ny});
}
// En passant capture
else if (board[nx][ny] == null && enPassantTarget != null &&
nx == enPassantTarget[0] && ny == enPassantTarget[1]) {
// Verify there's an opponent pawn beside us
int pawnY = y; // The pawn to capture is beside us, not in front
if (inBounds(nx, pawnY) && board[nx][pawnY] != null &&
board[nx][pawnY].getType() == PieceType.Pawn &&
board[nx][pawnY].isWhite() != piece.isWhite()) {
moves.add(new int[]{nx, ny});
}
}
}
}
}
return moves;
}