en passant rule

This commit is contained in:
2025-04-05 19:20:41 +02:00
parent 2ec7be27ca
commit d94f7d733b
9 changed files with 108 additions and 38 deletions

View File

@@ -10,7 +10,7 @@ import chess.model.Piece;
import chess.model.visitor.PiecePathChecker;
public class MoveCommand extends PlayerCommand {
private final Move move;
private Piece deadPiece;
@@ -42,7 +42,7 @@ public class MoveCommand extends PlayerCommand {
if (!valid)
return CommandResult.NotAllowed;
this.deadPiece = board.pieceAt(move.getFinish());
this.deadPiece = board.pieceAt(move.getDeadPieceCoords());
board.applyMove(move);
if (board.isKingInCheck(game.getPlayerTurn())) {
@@ -50,14 +50,15 @@ public class MoveCommand extends PlayerCommand {
return CommandResult.NotAllowed;
}
if (game.pawnShouldBePromoted())
if (game.pawnShouldBePromoted())
return CommandResult.ActionNeeded;
board.setLastMove(this.move);
return CommandResult.Moved;
}
@Override
public CommandResult undo(Game game, OutputSystem outputSystem) {
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
final ChessBoard board = game.getBoard();
board.undoMove(move, deadPiece);