public void startNGameCycles(Runnable finalAction, int nrOfRuns) { Class currWhitePlayer = whitePlayer.getClass(); Class currBlackPlayer = blackPlayer.getClass(); new Thread( () -> { for (int i = 0; i < nrOfRuns; i++) { progressOfNGames = OptionalDouble.of((double) i / nrOfRuns); GipfBoardState gipfBoardStateCopy = new GipfBoardState( getGipfBoardState(), gipfBoardState.getPieceMap(), gipfBoardState.players); Game copyOfGame = new BasicGame(); try { copyOfGame.whitePlayer = (ComputerPlayer) currWhitePlayer.newInstance(); copyOfGame.blackPlayer = (ComputerPlayer) currBlackPlayer.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } copyOfGame.loadState(gipfBoardStateCopy); GameLoopThread gameLoopThread = new GameLoopThread(copyOfGame, finalAction); gameLoopThread.start(); try { gameLoopThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } progressOfNGames = OptionalDouble.empty(); }) .start(); }
public void startGameCycle(Runnable finalAction) { GameLoopThread gameLoopThread = new GameLoopThread(this, finalAction); this.automaticPlayThread = gameLoopThread; gameLoopThread.start(); }