82 lines
1.7 KiB
Java
82 lines
1.7 KiB
Java
package chess.ai.minimax;
|
|
|
|
import java.util.List;
|
|
|
|
import chess.ai.actions.AIAction;
|
|
import chess.ai.actions.AIActions;
|
|
import chess.controller.CommandExecutor;
|
|
import chess.controller.CommandSender;
|
|
import chess.controller.commands.PromoteCommand.PromoteType;
|
|
import chess.controller.event.EmptyGameDispatcher;
|
|
import chess.controller.event.GameAdapter;
|
|
import chess.model.ChessBoard;
|
|
import chess.model.Color;
|
|
import chess.model.Game;
|
|
import chess.model.Move;
|
|
import chess.model.PermissiveGame;
|
|
|
|
public class GameSimulation extends GameAdapter implements CommandSender {
|
|
|
|
private final CommandExecutor simulation;
|
|
private final Game gameSimulation;
|
|
|
|
public GameSimulation() {
|
|
this.gameSimulation = new PermissiveGame();
|
|
this.simulation = new CommandExecutor(gameSimulation, new EmptyGameDispatcher());
|
|
}
|
|
|
|
@Override
|
|
public void onPawnPromoted(PromoteType promotion) {
|
|
sendPawnPromotion(promotion);
|
|
}
|
|
|
|
@Override
|
|
public void onCastling(boolean bigCastling) {
|
|
if (bigCastling)
|
|
sendBigCastling();
|
|
else
|
|
sendCastling();
|
|
}
|
|
|
|
@Override
|
|
public void onMove(Move move, boolean captured) {
|
|
sendMove(move);
|
|
}
|
|
|
|
@Override
|
|
public void onGameStart() {
|
|
sendStartGame();
|
|
}
|
|
|
|
@Override
|
|
public void onPlayerTurn(Color color, boolean undone) {
|
|
if (undone)
|
|
sendUndo();
|
|
}
|
|
|
|
public CommandExecutor getCommandExecutor() {
|
|
return simulation;
|
|
}
|
|
|
|
public Game getGame() {
|
|
return gameSimulation;
|
|
}
|
|
|
|
public ChessBoard getBoard() {
|
|
return this.gameSimulation.getBoard();
|
|
}
|
|
|
|
public Color getPlayerTurn() {
|
|
return this.gameSimulation.getPlayerTurn();
|
|
}
|
|
|
|
public List<AIAction> getAllowedActions() {
|
|
return AIActions.getAllowedActions(this.simulation);
|
|
}
|
|
|
|
public void close() {
|
|
this.simulation.close();
|
|
}
|
|
|
|
}
|