Pawn Promotion - Automatic Queen Promotion as there is nothing in GUI to
select it
This commit is contained in:
parent
317260609a
commit
58dac05f95
|
|
@ -517,6 +517,14 @@ public void undoLastMove() {
|
||||||
|
|
||||||
// Update the moved piece's position
|
// Update the moved piece's position
|
||||||
piece.setPosition(move.getToX(), move.getToY());
|
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
|
// Save move in history for undo
|
||||||
moveHistory.add(move);
|
moveHistory.add(move);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ public class Piece {
|
||||||
public void setY(int y) {
|
public void setY(int y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
public void setType(PieceType newType) {
|
||||||
|
this.type = newType;
|
||||||
|
}
|
||||||
|
|
||||||
public PieceType getType() {
|
public PieceType getType() {
|
||||||
return type;
|
return type;
|
||||||
|
|
@ -55,7 +58,6 @@ public class Piece {
|
||||||
public void setHasMoved(boolean moved) {
|
public void setHasMoved(boolean moved) {
|
||||||
this.hasMoved = moved;
|
this.hasMoved = moved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue