fix en passant

This commit is contained in:
2025-04-15 21:33:49 +02:00
parent 87992b181e
commit edf95a1691
3 changed files with 17 additions and 2 deletions

View File

@@ -70,6 +70,7 @@ public class ChessBoard {
pieceComes(movingPiece, move.getStart()); pieceComes(movingPiece, move.getStart());
pieceLeaves(move.getFinish()); pieceLeaves(move.getFinish());
pieceComes(deadPiece, move.getDeadPieceCoords()); pieceComes(deadPiece, move.getDeadPieceCoords());
assert movingPiece != null;
movingPiece.unMove(); movingPiece.unMove();
} }

View File

@@ -30,7 +30,7 @@ public class Move {
int diffY = getFinish().getY() - getStart().getY(); 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(diffX) < Coordinate.VALUE_MAX : "Move is too big!"; assert Math.abs(diffY) < Coordinate.VALUE_MAX : "Move is too big!";
if (diffX == 0) if (diffX == 0)
return Math.abs(diffY); return Math.abs(diffY);
@@ -53,4 +53,11 @@ public class Move {
return deadPieceCoords; 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;
}
} }

View File

@@ -96,7 +96,14 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
if (pieceToEat.getColor() == pawn.getColor()) if (pieceToEat.getColor() == pawn.getColor())
return false; 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)) { && new PawnIdentifier(pieceToEat.getColor()).isPawn(pieceToEat)) {
this.move.setDeadPieceCoords(lastMove.getFinish()); this.move.setDeadPieceCoords(lastMove.getFinish());
return true; return true;