Esempio n. 1
0
  public GameServer(Match match, List<String> hosts, List<Integer> ports) {
    this.match = match;

    this.hosts = hosts;
    this.ports = ports;

    playerGetsUnlimitedTime = new Boolean[hosts.size()];
    Arrays.fill(playerGetsUnlimitedTime, Boolean.FALSE);

    playerPlaysRandomly = new Boolean[hosts.size()];
    Arrays.fill(playerPlaysRandomly, Boolean.FALSE);

    stateMachine = new ProverStateMachine();
    stateMachine.initialize(match.getGame().getRules());
    currentState = stateMachine.getInitialState();
    previousMoves = null;

    mostRecentErrors = new HashMap<Role, String>();

    match.appendState(currentState.getContents());

    observers = new ArrayList<Observer>();

    spectatorServerURL = null;
    forceUsingEntireClock = false;
  }
Esempio n. 2
0
  @Override
  public void run() {
    try {
      if (match.getAnalysisClock() >= 0) {
        sendAnalyzeRequests();
      }

      notifyObservers(new ServerNewMatchEvent(stateMachine.getRoles(), currentState));
      notifyObservers(new ServerTimeEvent(match.getStartClock() * 1000));
      sendStartRequests();
      appendErrorsToMatchDescription();

      while (!stateMachine.isTerminal(currentState)) {
        publishWhenNecessary();
        saveWhenNecessary();
        notifyObservers(new ServerNewGameStateEvent(currentState));
        notifyObservers(new ServerTimeEvent(match.getPlayClock() * 1000));
        notifyObservers(new ServerMatchUpdatedEvent(match, spectatorServerKey, saveToFilename));
        previousMoves = sendPlayRequests();

        notifyObservers(new ServerNewMovesEvent(previousMoves));
        currentState = stateMachine.getNextState(currentState, previousMoves);

        match.appendMoves2(previousMoves);
        match.appendState(currentState.getContents());
        appendErrorsToMatchDescription();
      }
      match.markCompleted(stateMachine.getGoals(currentState));
      publishWhenNecessary();
      saveWhenNecessary();
      notifyObservers(new ServerNewGameStateEvent(currentState));
      notifyObservers(new ServerCompletedMatchEvent(getGoals()));
      notifyObservers(new ServerMatchUpdatedEvent(match, spectatorServerKey, saveToFilename));
      sendStopRequests(previousMoves);
    } catch (InterruptedException ie) {
      if (match.isAborted()) {
        return;
      } else {
        ie.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }