en passant rule
This commit is contained in:
@@ -35,31 +35,27 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Bishop bishop) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(bishop))
|
||||
return false;
|
||||
return testPath(bishop.getColor());
|
||||
return basicCheck(bishop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(King king) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(king))
|
||||
return false;
|
||||
|
||||
Piece destPiece = board.pieceAt(this.move.getFinish());
|
||||
if (destPiece == null)
|
||||
return true;
|
||||
return destPiece.getColor() != king.getColor();
|
||||
return destCheck(king);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Knight knight) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(knight))
|
||||
return false;
|
||||
return destCheck(knight);
|
||||
}
|
||||
|
||||
Piece destPiece = board.pieceAt(this.move.getFinish());
|
||||
if (destPiece == null)
|
||||
return true;
|
||||
return destPiece.getColor() != knight.getColor();
|
||||
@Override
|
||||
public Boolean visitPiece(Queen queen) {
|
||||
return basicCheck(queen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Rook rook) {
|
||||
return basicCheck(rook);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +70,9 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
|
||||
assert moveDirection == Direction.FrontLeft || moveDirection == Direction.FrontRight;
|
||||
|
||||
if (checkEnPassant())
|
||||
return true;
|
||||
|
||||
Piece destPiece = this.board.pieceAt(this.move.getFinish());
|
||||
if (destPiece == null)
|
||||
return false;
|
||||
@@ -81,18 +80,44 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
return destPiece.getColor() != pawn.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Queen queen) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(queen))
|
||||
private boolean checkEnPassant() {
|
||||
Move lastMove = this.board.getLastMove();
|
||||
|
||||
if (lastMove == null)
|
||||
return false;
|
||||
return testPath(queen.getColor());
|
||||
|
||||
Piece pieceToEat = this.board.pieceAt(lastMove.getFinish());
|
||||
|
||||
if (pieceToEat == null)
|
||||
return false;
|
||||
|
||||
Piece pawn = this.board.pieceAt(this.move.getStart());
|
||||
|
||||
if (pieceToEat.getColor() == pawn.getColor())
|
||||
return false;
|
||||
|
||||
if (lastMove.getMiddle().equals(this.move.getFinish())
|
||||
&& new PawnIdentifier(pieceToEat.getColor()).isPawn(pieceToEat)) {
|
||||
this.move.setDeadPieceCoords(lastMove.getFinish());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Rook rook) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(rook))
|
||||
private boolean destCheck(Piece piece) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(piece))
|
||||
return false;
|
||||
return testPath(rook.getColor());
|
||||
|
||||
Piece destPiece = board.pieceAt(this.move.getFinish());
|
||||
if (destPiece == null)
|
||||
return true;
|
||||
return destPiece.getColor() != piece.getColor();
|
||||
}
|
||||
|
||||
private boolean basicCheck(Piece piece) {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(piece))
|
||||
return false;
|
||||
return testPath(piece.getColor());
|
||||
}
|
||||
|
||||
private boolean testPath(Color color) {
|
||||
|
||||
Reference in New Issue
Block a user