add move preconditions

This commit is contained in:
2025-04-04 20:57:20 +02:00
parent 7b07423175
commit 63a1e261e8
2 changed files with 10 additions and 2 deletions

View File

@@ -4,10 +4,14 @@ import chess.io.OutputSystem;
import chess.io.PlayerCommand;
import chess.model.Game;
public class CastlingCommand extends PlayerCommand{
public class CastlingCommand extends PlayerCommand {
@Override
public CommandResult execute(Game game, OutputSystem outputSystem) {
// we must promote the pending pawn before
if (game.pawnShouldBePromoted())
return CommandResult.NotAllowed;
return CommandResult.NotAllowed;
}
@@ -16,5 +20,5 @@ public class CastlingCommand extends PlayerCommand{
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'undo'");
}
}

View File

@@ -8,6 +8,10 @@ public class GrandCastlingCommand extends PlayerCommand {
@Override
public CommandResult execute(Game game, OutputSystem outputSystem) {
// we must promote the pending pawn before
if (game.pawnShouldBePromoted())
return CommandResult.NotAllowed;
return CommandResult.NotAllowed;
}