diff --git a/src/backend/CheckKing.java b/src/backend/CheckKing.java index b15fe0b..7eb94c2 100644 --- a/src/backend/CheckKing.java +++ b/src/backend/CheckKing.java @@ -61,45 +61,4 @@ public class CheckKing { 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 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; - } }