package dev.kske.chess.board;
/**
* Project: Chess
* File: EnPassant.java
* Created: 2 Nov 2019
*
* @since Chess v0.5-alpha
* @author Kai S. K. Engelbart
*/
public class EnPassant extends Move {
private final Position capturePos;
/**
* Initializes an en passant move.
*
* @param pos the position of this move
* @param dest the destination of this move
*/
public EnPassant(Position pos, Position dest) {
super(pos, dest);
capturePos = new Position(dest.x, dest.y - ySign);
}
/**
* Initializes an en passant move.
*
* @param xPos the horizontal position of this move
* @param yPos the vertical position of this move
* @param xDest the horizontal destination of this move
* @param yDest the vertical destination of this move
*/
public EnPassant(int xPos, int yPos, int xDest, int yDest) {
this(new Position(xPos, yPos), new Position(xDest, yDest));
}
@Override
public void execute(Board board) {
super.execute(board);
board.set(capturePos, null);
}
@Override
public void revert(Board board, Piece capturedPiece) {
super.revert(board, capturedPiece);
board.set(
capturePos,
new Pawn(board.get(pos).getColor().opposite(), board)
);
}
/**
* @return the position of the piece captures by this move
*/
public Position getCapturePos() { return capturePos; }
}