Pawn promoted to a queen when reaches to top/bottom

This commit is contained in:
marce 2025-05-19 19:46:36 +02:00
parent c92c9d06e8
commit 972e29f6e3
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,9 @@
WR,WN,WB,WQ,WK,WB,WN,WR
WP,WP,WP,,WP,WP,WP,
,,,,,,,WP
,,,WP,,,,
,,,,BP,,,
,,,,,,,
BP,BP,BP,BP,,BP,BP,BP
BR,BN,BB,BK,BQ,BB,BN,BR
B

View File

@ -349,6 +349,23 @@ public class Board implements Cloneable {
pieces.remove(pieceToMove);
// Check if the moved piece is a pawn reaching the opposite end of the board
if (pieceToMove.getType() == PieceType.Pawn) {
if ((pieceToMove.isWhite() && move.getToRow() == 7) || (!pieceToMove.isWhite() && move.getToRow() == 0)) {
// Promote the pawn to a queen
Piece promotedPiece = makeNewPiece(PieceType.Queen, pieceToMove.isWhite(), move.getToCol(), move.getToRow());
pieces.add(promotedPiece);
// Update turn info
turnIsWhite = !turnIsWhite;
turnNumber++;
// Play move sound if enabled
playMoveSound();
return;
}
}
// Add moved piece at the new position
Piece movedPiece = makeNewPiece(pieceToMove.getType(), pieceToMove.isWhite(), move.getToCol(), move.getToRow());
pieces.add(movedPiece);