Compare commits
5 Commits
e515888649
...
28a768b132
| Author | SHA1 | Date |
|---|---|---|
|
|
28a768b132 | |
|
|
9233ca01be | |
|
|
2fe1694475 | |
|
|
b3b1673fcd | |
|
|
debffdd8b5 |
|
|
@ -415,7 +415,7 @@ public class Board {
|
|||
System.out.println("No moves to undo.");
|
||||
}
|
||||
}
|
||||
|
||||
//test
|
||||
public void playMove(Move move) {
|
||||
// Save current state before move for undo
|
||||
undoStack.push(toFileRep());
|
||||
|
|
@ -623,5 +623,32 @@ public class Board {
|
|||
// Replace highlights with filtered version
|
||||
highlightedSquares = newHighlights;
|
||||
}
|
||||
|
||||
public boolean isCheckmate(boolean isWhite) {
|
||||
if (!isKingInCheck(isWhite)) {
|
||||
return false; // Not in check, so not checkmate
|
||||
}
|
||||
|
||||
// Check if ANY legal move can get the king out of check
|
||||
for (Piece piece : getPieces()) {
|
||||
if (piece.isWhite() == isWhite) {
|
||||
ArrayList<Move> legalMoves = getLegalMoves(piece);
|
||||
|
||||
for (Move move : legalMoves) {
|
||||
// Simulate move
|
||||
Board simulatedBoard = new Board(this.toFileRep());
|
||||
simulatedBoard.playMove(move);
|
||||
|
||||
// If king is not in check after this move, it's not checkmate
|
||||
if (!simulatedBoard.isKingInCheck(isWhite)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // No legal move prevents check => checkmate
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue