예제 #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;
  }
예제 #2
0
  @Override
  public void stateMachineMetaGame(long timeout)
      throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException {
    System.out.println("Metagame. Preparing to test the state machine");

    StateMachine stateMachine = getStateMachine();
    ProverStateMachine psm = (ProverStateMachine) stateMachine;
    List gdlDescription = psm.gdlDescription;

    // The only line you have to adapt in this file
    StateMachine stateMachineX = new CachedStateMachine(new PropNetStateMachine());

    stateMachineX.initialize(gdlDescription);

    MachineState rootState = stateMachine.getInitialState();
    MachineState rootStateX = stateMachineX.getInitialState();
    if (!compare(rootState, rootStateX)) {
      System.out.println("Initial states are different");
      System.out.println(rootState);
      System.out.println(rootStateX);
      return;
    }

    long finishBy = timeout - 1000;

    int nbExpansion = 0;
    boolean abort = false;

    while (System.currentTimeMillis() < finishBy && !abort) {
      MachineState state = rootState;

      while (true) {
        boolean isTerminal = stateMachine.isTerminal(state);
        boolean isTerminalX = stateMachineX.isTerminal(state);
        if (!compare(isTerminal, isTerminalX)) {
          System.out.println("DISCREPANCY between isTerminal values");
          System.out.println("State : " + state);
          abort = true;
          break;
        }

        if (isTerminal) {
          List goal = stateMachine.getGoals(state);
          List goalX = stateMachineX.getGoals(state);
          if (!compare(goal, goalX)) {
            System.out.println("DISCREPANCY between goal values");
            System.out.println(goal);
            System.out.println(goalX);
            abort = true;
            break;
          }
          break;
        }

        for (Role role : stateMachine.getRoles()) {
          List moves = stateMachine.getLegalMoves(state, role);
          List movesX = stateMachineX.getLegalMoves(state, role);
          if (!compare(moves, movesX, role)) {
            System.out.println("DISCREPANCY between legal moves for role " + role);
            System.out.println(moves);
            System.out.println(movesX);
            abort = true;
            break;
          }
        }

        List jointMove = stateMachine.getRandomJointMove(state);

        MachineState nextState = stateMachine.getNextState(state, jointMove);
        MachineState nextStateX = stateMachineX.getNextState(state, jointMove);
        if (!compare(nextState, nextStateX)) {
          System.out.println("DISCREPANCY between next states");
          System.out.println("Previous state : " + state);
          System.out.println("Joint move : " + jointMove);
          System.out.println("New state : " + nextState);
          System.out.println("New stateX : " + nextStateX);

          abort = true;
          break;
        }

        state = nextState;
        nbExpansion++;
      }
    }

    System.out.println("Metagaming finished");
    System.out.println("Nb expansion : " + nbExpansion);
  }