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

@@ -3,5 +3,12 @@ package chess.controller;
import chess.model.Game;
public abstract class PlayerCommand extends Command{
public abstract CommandResult undo(Game game, OutputSystem outputSystem);
public CommandResult undo(Game game, OutputSystem outputSystem) {
CommandResult result = undoImpl(game, outputSystem);
game.updateLastMove();
return result;
}
protected abstract CommandResult undoImpl(Game game, OutputSystem outputSystem);
}

View File

@@ -16,7 +16,7 @@ public class CastlingCommand extends PlayerCommand {
}
@Override
public CommandResult undo(Game game, OutputSystem outputSystem) {
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'undo'");
}

View File

@@ -16,7 +16,7 @@ public class GrandCastlingCommand extends PlayerCommand {
}
@Override
public CommandResult undo(Game game, OutputSystem outputSystem) {
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'undo'");
}

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);

View File

@@ -75,7 +75,7 @@ public class PromoteCommand extends PlayerCommand {
}
@Override
public CommandResult undo(Game game, OutputSystem outputSystem) {
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
final ChessBoard board = game.getBoard();
Piece promoted = board.pieceAt(this.pieceCoords);