multithreading
This commit is contained in:
96
app/src/main/java/chess/ai/minimax/GameSimulation.java
Normal file
96
app/src/main/java/chess/ai/minimax/GameSimulation.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package chess.ai.minimax;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.GetPlayerMovesCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.UndoCommand;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.event.EmptyGameDispatcher;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
import chess.model.Move;
|
||||
|
||||
public class GameSimulation extends GameAdaptator {
|
||||
|
||||
private final CommandExecutor simulation;
|
||||
private final Game gameSimulation;
|
||||
|
||||
public GameSimulation() {
|
||||
this.gameSimulation = new Game();
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCastling(boolean bigCastling) {
|
||||
sendCommand(new CastlingCommand(bigCastling));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
sendCommand(new MoveCommand(move));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameStart() {
|
||||
sendCommand(new NewGameCommand());
|
||||
}
|
||||
|
||||
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<Move> getAllowedMoves() {
|
||||
GetPlayerMovesCommand cmd = new GetPlayerMovesCommand();
|
||||
sendCommand(cmd);
|
||||
return cmd.getMoves();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.simulation.close();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user