예제 #1
0
  private synchronized List<Move> sendPlayRequests()
      throws InterruptedException, MoveDefinitionException {
    List<PlayRequestThread> threads = new ArrayList<PlayRequestThread>(hosts.size());
    for (int i = 0; i < hosts.size(); i++) {
      List<Move> legalMoves =
          stateMachine.getLegalMoves(currentState, stateMachine.getRoles().get(i));
      if (playerPlaysRandomly[i]) {
        threads.add(new RandomPlayRequestThread(match, legalMoves));
      } else {
        threads.add(
            new PlayRequestThread(
                this,
                match,
                previousMoves,
                legalMoves,
                stateMachine.getRoles().get(i),
                hosts.get(i),
                ports.get(i),
                getPlayerNameFromMatchForRequest(i),
                playerGetsUnlimitedTime[i]));
      }
    }
    for (PlayRequestThread thread : threads) {
      thread.start();
    }

    if (forceUsingEntireClock) {
      Thread.sleep(match.getPlayClock() * 1000);
    }

    List<Move> moves = new ArrayList<Move>();
    for (PlayRequestThread thread : threads) {
      thread.join();
      moves.add(thread.getMove());
    }

    return moves;
  }
예제 #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);
  }