promotion
This commit is contained in:
parent
ba320bcdd6
commit
60e681207c
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package backend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Piece {
|
||||
|
||||
private int x;
|
||||
|
|
@ -44,5 +46,6 @@ public class Piece {
|
|||
this.x = piece.x;
|
||||
this.y = piece.y;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package backend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public enum PieceType {
|
||||
Pawn, Rook, Knight, Bishop, Queen, King;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue