fix en passant
This commit is contained in:
@@ -70,6 +70,7 @@ public class ChessBoard {
|
||||
pieceComes(movingPiece, move.getStart());
|
||||
pieceLeaves(move.getFinish());
|
||||
pieceComes(deadPiece, move.getDeadPieceCoords());
|
||||
assert movingPiece != null;
|
||||
movingPiece.unMove();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Move {
|
||||
int diffY = getFinish().getY() - getStart().getY();
|
||||
|
||||
assert Math.abs(diffX) < Coordinate.VALUE_MAX : "Move is too big!";
|
||||
assert Math.abs(diffX) < Coordinate.VALUE_MAX : "Move is too big!";
|
||||
assert Math.abs(diffY) < Coordinate.VALUE_MAX : "Move is too big!";
|
||||
|
||||
if (diffX == 0)
|
||||
return Math.abs(diffY);
|
||||
@@ -53,4 +53,11 @@ public class Move {
|
||||
return deadPieceCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Move other)
|
||||
return this.start.equals(other.start) && this.finish.equals(other.finish);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,14 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
if (pieceToEat.getColor() == pawn.getColor())
|
||||
return false;
|
||||
|
||||
if (lastMove.getMiddle().equals(this.move.getFinish())
|
||||
Direction lastMoveDir = Direction.findDirection(lastMove);
|
||||
|
||||
if ((lastMoveDir != Direction.Front && lastMoveDir != Direction.Back) || lastMove.traversedCells() != 2)
|
||||
return false;
|
||||
|
||||
Coordinate middle = lastMove.getMiddle();
|
||||
|
||||
if (middle.equals(this.move.getFinish())
|
||||
&& new PawnIdentifier(pieceToEat.getColor()).isPawn(pieceToEat)) {
|
||||
this.move.setDeadPieceCoords(lastMove.getFinish());
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user