diff --git a/src/backend/Board.java b/src/backend/Board.java index 38e23c2..e8a2eb0 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -524,12 +524,13 @@ public class Board { undoStack.push(toFileRep()); Piece piece = board[move.getFromX()][move.getFromY()]; + SpecialMoves specialMoves = new SpecialMoves(); // Handle en passant capture - if (SpecialMoves.isEnPassant(this, move)) { + if (specialMoves.isEnPassant(this, move)) { Piece capturedPawn = board[move.getToX()][move.getFromY()]; move.setCapturedPiece(capturedPawn); - SpecialMoves.handleEnPassant(this, move); + specialMoves.handleEnPassant(this, move); } // Move the piece @@ -539,17 +540,18 @@ public class Board { piece.y = move.getToY(); // Update en passant tracking - SpecialMoves.updateEnPassantTracking(this, move, piece); + specialMoves.updateEnPassantTracking(this, move, piece); // Handle pawn promotion if (piece.getType() == PieceType.Pawn && (piece.getY() == 0 || piece.getY() == height - 1)) { - board[piece.getX()][piece.getY()] = SpecialMoves.promotePawn(piece.isWhite(), piece.getX(), piece.getY()); + board[piece.getX()][piece.getY()] = specialMoves.promotePawn(piece.isWhite(), piece.getX(), piece.getY()); } turn++; } + //Finds the position of the king of a given color. public Piece findKing(boolean isWhite) { diff --git a/src/backend/SpecialMoves.java b/src/backend/SpecialMoves.java index a66316e..9018c32 100644 --- a/src/backend/SpecialMoves.java +++ b/src/backend/SpecialMoves.java @@ -1,90 +1,42 @@ package backend; public class SpecialMoves { - - /** - * Handles pawn promotion, returning a new Queen piece - * @param isWhite color of the pawn being promoted - * @param x x-coordinate of the pawn - * @param y y-coordinate of the pawn - * @return the new Queen piece that replaces the pawn - */ - public static Piece promotePawn(boolean isWhite, int x, int y) { + + // Pawn promotion: always promotes to Queen for simplicity + public Piece promotePawn(boolean isWhite, int x, int y) { return new Piece(isWhite, PieceType.Queen, x, y); } - - /** - * Checks if a move is an en passant capture - * @param board the current board state - * @param move the move being checked - * @return true if the move is an en passant capture - */ - public static boolean isEnPassant(Board board, Move move) { + + // Checks if a move is an en passant capture + public boolean isEnPassant(Board board, Move move) { Piece piece = board.getPieceAt(move.getFromX(), move.getFromY()); - - // Must be a pawn - if (piece == null || piece.getType() != PieceType.Pawn) { - return false; - } - - // Must be a diagonal move - if (move.getToX() == move.getFromX()) { - return false; - } - - // Must be moving to an empty square + if (piece == null || piece.getType() != PieceType.Pawn) return false; + if (move.getToX() == move.getFromX()) return false; return board.isEmpty(move.getToX(), move.getToY()); } - - /** - * Handles the en passant capture by removing the captured pawn - * @param board the current board state - * @param move the en passant move - */ - public static void handleEnPassant(Board board, Move move) { - // The captured pawn is on the same row as the starting position - // but on the same column as the destination + + // Handles the en passant capture + public void handleEnPassant(Board board, Move move) { board.removePieceAt(move.getToX(), move.getFromY()); } - - /** - * Tracks en passant opportunities after a pawn's double move - * @param board the current board state - * @param move the move that was just played - */ - public static void updateEnPassantTracking(Board board, Move move, Piece piece) { - // Reset en passant tracking + + // Updates en passant tracking after a pawn's double move + public void updateEnPassantTracking(Board board, Move move, Piece piece) { board.setEnPassantCol(-1); board.setEnPassantRow(-1); - - // Check if this is a pawn making a double move - if (piece.getType() == PieceType.Pawn && + if (piece.getType() == PieceType.Pawn && Math.abs(move.getFromY() - move.getToY()) == 2) { board.setEnPassantCol(move.getToX()); - board.setEnPassantRow((move.getFromY() + move.getToY()) / 2); // Middle square + board.setEnPassantRow((move.getFromY() + move.getToY()) / 2); } } - - /** - * Checks if a castling move is legal - * @param board the current board state - * @param king the king piece - * @param isKingside true for kingside castling, false for queenside - * @return true if castling is legal - */ - public static boolean canCastle(Board board, Piece king, boolean isKingside) { - // Implementation for castling checks - // This is a placeholder - you'll need to implement the full logic + + // (Optional) Placeholder for castling logic + public boolean canCastle(Board board, Piece king, boolean isKingside) { return false; } - - /** - * Executes a castling move - * @param board the current board state - * @param move the castling move - */ - public static void handleCastling(Board board, Move move, boolean isKingside) { - // Implementation for castling execution - // This is a placeholder - you'll need to implement the full logic + + public void handleCastling(Board board, Move move, boolean isKingside) { + // Implement castling logic if needed } }