Autoplayer can detect and use en passant and castling

This commit is contained in:
manon 2025-05-20 11:50:29 +02:00
parent 58f038d0f2
commit 06ed1a0ffb
2 changed files with 19 additions and 2 deletions

View File

@ -20,9 +20,26 @@ public class AutoPlayer {
int[] moveCoords = moves.get(j);
int toX = moveCoords[0];
int toY = moveCoords[1];
int fromX = piece.getX();
int fromY = piece.getY();
Piece captured = board.getPieceAt(toX, toY);
Move move = new Move(piece, piece.getX(), piece.getY(), toX, toY, captured);
// Detect en passant
if (piece.getType() == PieceType.Pawn && board.isEnPassant() && toX == board.getXCoordinatePawn() &&
toY == (piece.isWhite() ? board.getYCoordinatePawn() - 1 : board.getYCoordinatePawn() + 1)) {
captured = board.getPieceAt(board.getXCoordinatePawn(), board.getYCoordinatePawn());
}
// --- Castling detection ---
if (piece.getType() == PieceType.King && Math.abs(toX - fromX) == 2 && toY == fromY) {
System.out.println("AI considering castling move.");
// No need to set captured, just allow the move
}
Move move = new Move(piece, piece.getX(), piece.getY(), toX, toY, captured);
allMoves.add(move);
}
}

View File

@ -10,7 +10,7 @@ public class Game extends Thread {
private MyInterface mjf;
private int COL_NUM = 8;
private int LINE_NUM = 8;
private int loopDelay = 250;
private int loopDelay = 1000;
boolean[] activationAIFlags;
public Game(MyInterface mjfParam) {