Pawn Promotion - Automatic Queen Promotion as there is nothing in GUI to

select it
This commit is contained in:
Yash Shah 2025-05-17 13:28:11 +02:00
parent 317260609a
commit 58dac05f95
2 changed files with 12 additions and 2 deletions

View File

@ -518,6 +518,14 @@ public void undoLastMove() {
// Update the moved piece's position
piece.setPosition(move.getToX(), move.getToY());
if (piece.getType() == PieceType.Pawn) {
// white promotes on y == height1, black on y == 0
int promotionRank = piece.isWhite() ? height - 1 : 0;
if (piece.getY() == promotionRank) {
piece.setType(PieceType.Queen);
}
}
// Save move in history for undo
moveHistory.add(move);

View File

@ -24,6 +24,9 @@ public class Piece {
public void setY(int y) {
this.y = y;
}
public void setType(PieceType newType) {
this.type = newType;
}
public PieceType getType() {
return type;
@ -57,5 +60,4 @@ public class Piece {
}
}