private void removeCapturedPiece(Move move) { Piece capturedPiece = null; if (MoveType.CAPTURE.equals(move.moveType())) { capturedPiece = ((CaptureMove) move).opposingPiece(); } else if (MoveType.EN_PASSANT.equals(move.moveType())) { capturedPiece = ((EnPassantMove) move).opposingPiece(); } else if (MoveType.PROMOTION.equals(move.moveType())) { capturedPiece = ((PromotionMove) move).opposingPiece(); } if (capturedPiece != null) { capturedPieces.get(capturedPiece.color()).remove(capturedPiece); } }
public Move move(Square startSquare, Square endSquare) { Move move = InvalidMove.execute(); if (startSquareContainsPlayersPiece(startSquare)) { move = executeMove(startSquare, endSquare); if (!move.moveType().equals(MoveType.INVALID)) { moves.add(move); changePlayersTurn(); } } return move; }
public Move promote(Square startSquare, Square endSquare, PieceType pieceType) { Move move = InvalidMove.execute(); if (PromotionMove.canBeExecuted(board, startSquare, endSquare, pieceType)) { move = PromotionMove.execute(board, startSquare, endSquare, pieceType); } if (MoveType.PROMOTION.equals(move.moveType())) { if (board.inCheck(playersTurn)) { move.undo(board); move = InvalidMove.execute(); } else { PromotionMove promotionMove = (PromotionMove) move; if (promotionMove.opposingPiece() != null) { capturedPieces .get(promotionMove.opposingPiece().color()) .add(promotionMove.opposingPiece()); } moves.add(move); changePlayersTurn(); } } return move; }