Compare commits

..

2 Commits

Author SHA1 Message Date
Jérôme BEDIER e515888649 test push 2025-05-21 20:31:54 +02:00
Jérôme BEDIER 8bcc9559de adding back removed stuffs 2025-05-21 20:30:01 +02:00
1 changed files with 8 additions and 28 deletions

View File

@ -415,7 +415,14 @@ public class Board {
System.out.println("No moves to undo.");
}
}
//test
public Board(Board board) {
//TODO
}//test
public void playMove(Move move) {
// Save current state before move for undo
undoStack.push(toFileRep());
@ -624,31 +631,4 @@ public class Board {
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
}
}