promotion

This commit is contained in:
aelga 2025-05-14 16:11:17 +02:00
parent ba320bcdd6
commit 60e681207c
3 changed files with 25 additions and 1 deletions

View File

@ -409,7 +409,26 @@ public class Board {
board[move.getFromY()][move.getFromX()].setY(move.getToY());
board[move.getToY()][move.getToX()] = board[move.getFromY()][move.getFromX()];
board[move.getFromY()][move.getFromX()] = null;
for (int x = 0; x < colNum; x++) {
for (int y = 0; y < lineNum; y++) {
canPromote(x, y);
}
}
this.states.add(toString());
}
}
ArrayList<Piece> promoPieces= new ArrayList<>();
boolean promotion;
private boolean canPromote(int x, int y) {
if (board[y][x] != null && board[y][x].getType() == PieceType.Pawn) {
boolean isWhite = board[y][x].isWhite(); // Declare 'isWhite' here
if ((isWhite && y == 0) || (!isWhite && y == 7)) {
board[y][x] = new Piece(isWhite, PieceType.Queen, x, y); // Now valid
return true;
}
}
return false;
}
}

View File

@ -1,5 +1,7 @@
package backend;
import java.util.ArrayList;
public class Piece {
private int x;
@ -45,4 +47,5 @@ public class Piece {
this.y = piece.y;
}
}

View File

@ -1,5 +1,7 @@
package backend;
import java.util.ArrayList;
public enum PieceType {
Pawn, Rook, Knight, Bishop, Queen, King;