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(); }
private void initPlugins() { for (Class<? extends ClientPlugin> clazz : clientPlugins) { try { ClientPlugin plugin = clazz.newInstance(); if (plugin instanceof ServiceFactoryProvider) { desktopServiceFactory.addServiceFactory( ((ServiceFactoryProvider) plugin).getServiceFactory()); } AfterburnerInjector.injectMembers(plugin); plugin.initialize(desktopServiceFactory, services.getEventDispatcher()); } catch (InstantiationException | IllegalAccessException e) { logger.error("failed to initialized plugin " + clazz.getName() + ": " + e.getMessage(), e); } } }