removed checkmate function - does not work, complex

This commit is contained in:
Marleen PETERSON 2025-05-18 17:27:41 +02:00
parent 14f4379ebf
commit 79e7aaaa49
1 changed files with 0 additions and 41 deletions

View File

@ -61,45 +61,4 @@ public class CheckKing {
return legalMoves; return legalMoves;
} }
// 3. Check if the given color is in checkmate
public static boolean isCheckmate(Board board, boolean white) {
// If the king is not in check, it's not checkmate
if (!isKingInCheck(board, white)) {
return false;
}
// Check if there are any valid moves for the given color
Piece[][] grid = board.getBoardMatrix();
// Iterate through all pieces of the given color
for (int y = 0; y < board.getHeight(); y++) {
for (int x = 0; x < board.getWidth(); x++) {
Piece piece = grid[y][x];
if (piece != null && piece.isWhite() == white) {
// Get the valid moves for this piece
Set<String> validMoves = board.getValidMoves(piece, true);
// If any valid move is available that does not leave the king in check, it's not checkmate
for (String move : validMoves) {
String[] parts = move.split(",");
int toX = Integer.parseInt(parts[0]);
int toY = Integer.parseInt(parts[1]);
// Simulate the move
Board copy = new Board(board);
copy.movePiece(piece.getX(), piece.getY(), toX, toY);
// Check if the move puts the king in check
if (!isKingInCheck(copy, white)) {
return false; // There's at least one valid move that doesn't leave the king in check
}
}
}
}
}
// If no valid moves are available, it's checkmate
return true;
}
} }