Autoplayer can detect and use en passant and castling
This commit is contained in:
parent
58f038d0f2
commit
06ed1a0ffb
|
|
@ -20,9 +20,26 @@ public class AutoPlayer {
|
||||||
int[] moveCoords = moves.get(j);
|
int[] moveCoords = moves.get(j);
|
||||||
int toX = moveCoords[0];
|
int toX = moveCoords[0];
|
||||||
int toY = moveCoords[1];
|
int toY = moveCoords[1];
|
||||||
|
|
||||||
|
int fromX = piece.getX();
|
||||||
|
int fromY = piece.getY();
|
||||||
|
|
||||||
Piece captured = board.getPieceAt(toX, toY);
|
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);
|
allMoves.add(move);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class Game extends Thread {
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
private int COL_NUM = 8;
|
private int COL_NUM = 8;
|
||||||
private int LINE_NUM = 8;
|
private int LINE_NUM = 8;
|
||||||
private int loopDelay = 250;
|
private int loopDelay = 1000;
|
||||||
boolean[] activationAIFlags;
|
boolean[] activationAIFlags;
|
||||||
|
|
||||||
public Game(MyInterface mjfParam) {
|
public Game(MyInterface mjfParam) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue