Package org.ggp.base.util.statemachine

Examples of org.ggp.base.util.statemachine.MachineState


  private int stepCount = 1;
  @Override
  public void observe(Event event) {
    if (event instanceof ServerNewGameStateEvent)
    {
          MachineState s = ((ServerNewGameStateEvent)event).getState();
          // TODO: Perhaps this should run in a separate thread, as in the
          // VisualizationPanel, in case these states are very large.
          JPanel statePanel = new JPanel();
          List<String> sentences = new ArrayList<String>();
          for(GdlSentence sentence : s.getContents())
            sentences.add(sentence.toString());
          //The list of sentences is more useful when sorted alphabetically.
          Collections.sort(sentences);
          StringBuffer sentencesList = new StringBuffer();
          for(String sentence : sentences)
View Full Code Here


  private int stepCount = 1;
  @Override
  public void observe(Event event)
  {
      if (event instanceof ServerNewGameStateEvent) {
          MachineState s = ((ServerNewGameStateEvent)event).getState();
          rt.submit(s, stepCount++);
      } else if (event instanceof ServerTimeEvent) {
          timerBar.time(((ServerTimeEvent) event).getTime(), 500);
      } else if (event instanceof ServerCompletedMatchEvent) {
          rt.finish();
          timerBar.stop();
      } else if (event instanceof ServerNewMatchEvent) {
          MachineState s = ((ServerNewMatchEvent) event).getInitialState();
          rt.submit(s, stepCount);
    }
  }
View Full Code Here

        frame.setVisible(true);

        StateMachine theMachine = new CachedStateMachine(new ProverStateMachine());
        theMachine.initialize(theGame.getRules());
        try {
            MachineState theCurrentState = theMachine.getInitialState();
            do {
                theVisual.observe(new ServerNewGameStateEvent(theCurrentState));
                theCurrentState = theMachine.getRandomNextState(theCurrentState);
                Thread.sleep(250);
                System.out.println("State: " + theCurrentState);
View Full Code Here

     *
     * @param newStateMachine the new state machine
     */
    protected final void switchStateMachine(StateMachine newStateMachine) {
        try {
            MachineState newCurrentState = newStateMachine.getInitialState();
            Role newRole = newStateMachine.getRoleFromConstant(getRoleName());

            // Attempt to run through the game history in the new machine
            List<List<GdlTerm>> theMoveHistory = getMatch().getMoveHistory();
            for(List<GdlTerm> nextMove : theMoveHistory) {
View Full Code Here

        // have one legal move, and so calling "getRandomJointMove" with our move
        // fixed will always return the joint move consisting of our move and the
        // opponent's no-op. In a simultaneous-action game, however, the opponent
        // may have many moves, and so we will randomly pick one of our opponent's
        // possible actions and assume they do that.
        MachineState nextState = theMachine.getNextState(getCurrentState(), theMachine.getRandomJointMove(getCurrentState(), getRole(), moveUnderConsideration));

        // Does the move under consideration end the game? If it does, do we win
        // or lose? If we lose, don't bother considering it. If we win, then we
        // definitely want to take this move. If its goal is better than our current
        // best goal, go ahead and tentatively select it
        if(theMachine.isTerminal(nextState)) {
            if(theMachine.getGoal(nextState, getRole()) == 0) {
                continue;
            } else if(theMachine.getGoal(nextState, getRole()) == 100) {
                  selection = moveUnderConsideration;
                  break;
            } else {
              if (theMachine.getGoal(nextState, getRole()) > maxGoal)
              {
                selection = moveUnderConsideration;
                maxGoal = theMachine.getGoal(nextState, getRole());
              }
              continue;
            }
        }

        // Check whether any of the legal joint moves from this state lead to
        // a loss for us. Again, this only makes sense in the context of an alternating
        // play zero-sum game, in which this is the opponent's move and they are trying
        // to make us lose, and so if they are offered any move that will make us lose
        // they will take it.
        boolean forcedLoss = false;
        for(List<Move> jointMove : theMachine.getLegalJointMoves(nextState)) {
            MachineState nextNextState = theMachine.getNextState(nextState, jointMove);
            if(theMachine.isTerminal(nextNextState)) {
                if(theMachine.getGoal(nextNextState, getRole()) == 0) {
                    forcedLoss = true;
                    break;
                }
View Full Code Here

  private int[] depth = new int[1];
  int performDepthChargeFromMove(MachineState theState, Move myMove) {
      StateMachine theMachine = getStateMachine();
      try {
            MachineState finalState = theMachine.performDepthCharge(theMachine.getRandomNextState(theState, getRole(), myMove), depth);
            return theMachine.getGoal(finalState, getRole());
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
View Full Code Here

        StaticValidator.validateDescription(description);

        StateMachine sm = new ProverStateMachine();
        sm.initialize(description);
        MachineState state = sm.getInitialState();
        assertEquals(1, sm.getRoles().size());
        Role player = sm.getRoles().get(0);
        assertEquals(1, sm.getLegalMoves(state, player).size());
        state = sm.getNextStates(state).get(0);
        assertTrue(sm.isTerminal(state));
View Full Code Here

    @Test
    public void testProverOnTicTacToe() throws Exception {
        List<Gdl> ticTacToeDesc = new TestGameRepository().getGame("ticTacToe").getRules();
        sm.initialize(ticTacToeDesc);
        MachineState state = sm.getInitialState();
        assertFalse(sm.isTerminal(state));
        GdlConstant X_PLAYER = GdlPool.getConstant("xplayer");
        GdlConstant O_PLAYER = GdlPool.getConstant("oplayer");
        Role xRole = new Role(X_PLAYER);
        Role oRole = new Role(O_PLAYER);
View Full Code Here

    @Test
    public void testCase1A() throws Exception {
        List<Gdl> desc = new TestGameRepository().getGame("test_case_1a").getRules();
        sm.initialize(desc);
        MachineState state = sm.getInitialState();
        Role you = new Role(GdlPool.getConstant("you"));
        assertFalse(sm.isTerminal(state));
        assertEquals(100, sm.getGoal(state, you));
        assertEquals(Collections.singletonList(100), sm.getGoals(state));
        state = sm.getNextState(state, Collections.singletonList(move("proceed")));
View Full Code Here

    @Test
    public void testCase3C() throws Exception {
        List<Gdl> desc = new TestGameRepository().getGame("test_case_3c").getRules();
        sm.initialize(desc);
        MachineState state = sm.getInitialState();
        Role xplayer = new Role(GdlPool.getConstant("xplayer"));
        assertFalse(sm.isTerminal(state));
        assertEquals(1, sm.getLegalMoves(state, xplayer).size());
        assertEquals(move("win"), sm.getLegalMoves(state, xplayer).get(0));
        state = sm.getNextState(state, Collections.singletonList(move("win")));
View Full Code Here

TOP

Related Classes of org.ggp.base.util.statemachine.MachineState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.