36 lines
924 B
Java
36 lines
924 B
Java
package dev.kske.chess.board;
|
|
|
|
/**
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>Castling.java</strong><br>
|
|
* Created: <strong>2 Nov 2019</strong><br>
|
|
*
|
|
* @since Chess v0.5-alpha
|
|
* @author Kai S. K. Engelbart
|
|
*/
|
|
public class Castling extends Move {
|
|
|
|
private final Move rookMove;
|
|
|
|
public Castling(Position pos, Position dest) {
|
|
super(pos, dest);
|
|
rookMove = dest.x == 6 ? new Move(7, pos.y, 5, pos.y) : new Move(0, pos.y, 3, pos.y);
|
|
}
|
|
|
|
public Castling(int xPos, int yPos, int xDest, int yDest) { this(new Position(xPos, yPos), new Position(xDest, yDest)); }
|
|
|
|
@Override
|
|
public void execute(Board board) {
|
|
// Move the king and the rook
|
|
super.execute(board);
|
|
rookMove.execute(board);
|
|
}
|
|
|
|
@Override
|
|
public void revert(Board board, Piece capturedPiece) {
|
|
// Move the king and the rook
|
|
super.revert(board, capturedPiece);
|
|
rookMove.revert(board, null);
|
|
}
|
|
}
|