Super IA (#5)

Reviewed-on: #5
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
This commit was merged in pull request #5.
This commit is contained in:
2025-04-30 18:28:01 +00:00
committed by Simon Pribylski
parent ecb0fdc623
commit 3b38e0da1f
26 changed files with 814 additions and 179 deletions

View File

@@ -2,6 +2,7 @@ package chess.controller;
import chess.controller.Command.CommandResult;
import chess.controller.commands.UndoCommand;
import chess.controller.event.AsyncGameDispatcher;
import chess.controller.event.GameDispatcher;
import chess.controller.event.GameListener;
import chess.model.Game;
@@ -17,9 +18,9 @@ public class CommandExecutor {
}
public CommandExecutor(Game game) {
this(game, new GameDispatcher());
this(game, new AsyncGameDispatcher());
}
public CommandExecutor(Game game, GameDispatcher dispatcher) {
this.game = game;
this.dispatcher = dispatcher;
@@ -52,19 +53,21 @@ public class CommandExecutor {
return;
case Moved:
boolean notifyPlayerTurn = true;
this.dispatcher.onBoardUpdate();
if (checkGameStatus()) {
if (!(command instanceof UndoCommand) && checkGameStatus()) {
this.dispatcher.onGameEnd();
return;
notifyPlayerTurn = false;
}
switchPlayerTurn(command instanceof UndoCommand);
switchPlayerTurn(command instanceof UndoCommand, notifyPlayerTurn);
return;
}
}
private void switchPlayerTurn(boolean undone) {
private void switchPlayerTurn(boolean undone, boolean notifyPlayerTurn) {
this.game.switchPlayerTurn();
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn(), undone);
if (notifyPlayerTurn)
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn(), undone);
}
/**
@@ -107,6 +110,6 @@ public class CommandExecutor {
}
public void close() {
this.dispatcher.stopService();
this.dispatcher.close();
}
}