pormotion added

This commit is contained in:
Jérôme BEDIER 2025-05-21 19:39:47 +02:00
parent ebdfedd0a6
commit ad01fdd17b
1 changed files with 10 additions and 0 deletions

View File

@ -415,6 +415,12 @@ public class Board {
board[move.getFromX()][move.getFromY()] = null; board[move.getFromX()][move.getFromY()] = null;
piece.x = move.getToX(); piece.x = move.getToX();
piece.y = move.getToY(); piece.y = move.getToY();
if (piece.getType() == PieceType.Pawn &&
(piece.getY() == 0 || piece.getY() == height - 1)) {
board[piece.getX()][piece.getY()] = promotePawn(piece.isWhite(), piece.getX(), piece.getY());
}
turn++; turn++;
} }
@ -469,6 +475,10 @@ public class Board {
return false; // King is not in check return false; // King is not in check
} }
public static Piece promotePawn(boolean isWhite, int x, int y) {
return new Piece(isWhite, PieceType.Queen, x, y);
}
private void highlightKingInCheck() { private void highlightKingInCheck() {
// Check if white king is in check // Check if white king is in check
Piece whiteKing = findKing(true); Piece whiteKing = findKing(true);