add CommanderSender (Fixes #9)
All checks were successful
Linux arm64 / Build (push) Successful in 36s
All checks were successful
Linux arm64 / Build (push) Successful in 36s
This commit is contained in:
@@ -4,15 +4,9 @@ import java.util.List;
|
||||
|
||||
import chess.ai.actions.AIAction;
|
||||
import chess.ai.actions.AIActions;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.CommandSender;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.commands.UndoCommand;
|
||||
import chess.controller.event.EmptyGameDispatcher;
|
||||
import chess.controller.event.GameAdapter;
|
||||
import chess.model.ChessBoard;
|
||||
@@ -21,7 +15,7 @@ import chess.model.Game;
|
||||
import chess.model.Move;
|
||||
import chess.model.PermissiveGame;
|
||||
|
||||
public class GameSimulation extends GameAdapter {
|
||||
public class GameSimulation extends GameAdapter implements CommandSender {
|
||||
|
||||
private final CommandExecutor simulation;
|
||||
private final Game gameSimulation;
|
||||
@@ -31,48 +25,33 @@ public class GameSimulation extends GameAdapter {
|
||||
this.simulation = new CommandExecutor(gameSimulation, new EmptyGameDispatcher());
|
||||
}
|
||||
|
||||
protected CommandResult sendCommand(Command command) {
|
||||
CommandResult result = this.simulation.executeCommand(command);
|
||||
if (result == CommandResult.NotAllowed) {
|
||||
System.out.println("eeeeee");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void tryMove(Move move) {
|
||||
sendCommand(new MoveCommand(move));
|
||||
if (this.gameSimulation.getBoard().pawnShouldBePromoted())
|
||||
sendCommand(new PromoteCommand(PromoteType.Queen));
|
||||
}
|
||||
|
||||
public void undoMove() {
|
||||
sendCommand(new UndoCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPawnPromoted(PromoteType promotion) {
|
||||
sendCommand(new PromoteCommand(promotion));
|
||||
sendPawnPromotion(promotion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCastling(boolean bigCastling) {
|
||||
sendCommand(new CastlingCommand(bigCastling));
|
||||
if (bigCastling)
|
||||
sendBigCastling();
|
||||
else
|
||||
sendCastling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move, boolean captured) {
|
||||
sendCommand(new MoveCommand(move));
|
||||
sendMove(move);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameStart() {
|
||||
sendCommand(new NewGameCommand());
|
||||
sendStartGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
if (undone)
|
||||
sendCommand(new UndoCommand());
|
||||
sendUndo();
|
||||
}
|
||||
|
||||
public CommandExecutor getCommandExecutor() {
|
||||
|
||||
Reference in New Issue
Block a user