예제 #1
0
파일: Game.java 프로젝트: FransM22/GipfGame
  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();
  }
예제 #2
0
 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);
     }
   }
 }