ischeckmate implemnted
This commit is contained in:
parent
68d1136ff1
commit
ae3be7abb1
|
|
@ -757,4 +757,30 @@ public class Board {
|
||||||
highlightedSquares = newHighlights;
|
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