Pawn Promotion - Automatic Queen Promotion as there is nothing in GUI to
select it
This commit is contained in:
parent
317260609a
commit
58dac05f95
|
|
@ -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 == height‐1, 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue