en passant rule
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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'");
|
||||
}
|
||||
|
||||
@@ -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'");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user