Package org.ggp.base.util.statemachine

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


      StateMachine theMachine = getStateMachine();
    long start = System.currentTimeMillis();
    long finishBy = timeout - 1000;

    List<Move> moves = theMachine.getLegalMoves(getCurrentState(), getRole());
    Move selection = (moves.get(new Random().nextInt(moves.size())));

    // Shuffle the moves into a random order, so that when we find the first
    // move that doesn't give our opponent a forced win, we aren't always choosing
    // the first legal move over and over (which is visibly repetitive).
    List<Move> movesInRandomOrder = new ArrayList<Move>();
    while(!moves.isEmpty()) {
        Move aMove = moves.get(theRandom.nextInt(moves.size()));
        movesInRandomOrder.add(aMove);
        moves.remove(aMove);
    }

    // Go through all of the legal moves in a random over, and consider each one.
View Full Code Here


     * Move to play is the goal of GGP.
     */
    List<Move> moves = getStateMachine().getLegalMoves(getCurrentState(), getRole());

    // SampleLegalGamer is very simple : it picks the first legal move
    Move selection = moves.get(0);

    // We get the end time
    // It is mandatory that stop<timeout
    long stop = System.currentTimeMillis();

View Full Code Here

      StateMachine theMachine = getStateMachine();
    long start = System.currentTimeMillis();
    long finishBy = timeout - 1000;

    List<Move> moves = theMachine.getLegalMoves(getCurrentState(), getRole());
    Move selection = moves.get(0);
    if (moves.size() > 1) {
        int[] moveTotalPoints = new int[moves.size()];
        int[] moveTotalAttempts = new int[moves.size()];

        // Perform depth charges for each candidate move, and keep track
View Full Code Here

public final class SampleNoopGamer extends SampleGamer
{
  @Override
  public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException
  {
    return new Move(GdlPool.getConstant("NOOP"));
  }
View Full Code Here

  }

  @Override
  protected void handleResponse(String response) {
    try {
      Move candidateMove = gameServer.getStateMachine().getMoveFromTerm(GdlFactory.createTerm(match.getGdlScrambler().unscramble(response).toString()));
      if (new HashSet<Move>(legalMoves).contains(candidateMove)) {
        move = candidateMove;
      } else {
        gameServer.notifyObservers(new ServerIllegalMoveEvent(role, candidateMove));
      }
View Full Code Here

        assertEquals(roles, sm.getRoles());

        assertEquals(9, sm.getLegalJointMoves(state).size());
        assertEquals(9, sm.getLegalMoves(state, xRole).size());
        assertEquals(1, sm.getLegalMoves(state, oRole).size());
        Move noop = new Move(GdlPool.getConstant("noop"));
        assertEquals(noop, sm.getLegalMoves(state, oRole).get(0));

        Move m11 = move("mark 1 1");
        assertTrue(sm.getLegalMoves(state, xRole).contains(m11));
        state = sm.getNextState(state, Arrays.asList(new Move[] {m11, noop}));
        assertFalse(sm.isTerminal(state));

        Move m13 = move("mark 1 3");
        assertTrue(sm.getLegalMoves(state, oRole).contains(m13));
        state = sm.getNextState(state, Arrays.asList(new Move[] {noop, m13}));
        assertFalse(sm.isTerminal(state));

        Move m31 = move("mark 3 1");
        assertTrue(sm.getLegalMoves(state, xRole).contains(m31));
        state = sm.getNextState(state, Arrays.asList(new Move[] {m31, noop}));
        assertFalse(sm.isTerminal(state));

        Move m22 = move("mark 2 2");
        assertTrue(sm.getLegalMoves(state, oRole).contains(m22));
        state = sm.getNextState(state, Arrays.asList(new Move[] {noop, m22}));
        assertFalse(sm.isTerminal(state));

        Move m21 = move("mark 2 1");
        assertTrue(sm.getLegalMoves(state, xRole).contains(m21));
        state = sm.getNextState(state, Arrays.asList(new Move[] {m21, noop}));
        assertTrue(sm.isTerminal(state));
        assertEquals(100, sm.getGoal(state, xRole));
        assertEquals(0, sm.getGoal(state, oRole));
View Full Code Here

    protected Move move(String description) {
        String[] parts = description.split(" ");
        GdlConstant head = GdlPool.getConstant(parts[0]);
        if(parts.length == 1)
            return new Move(head);
        List<GdlTerm> body = new ArrayList<GdlTerm>();
        for(int i = 1; i < parts.length; i++) {
            body.add(GdlPool.getConstant(parts[i]));
        }
        return new Move(GdlPool.getFunction(head, body));
    }
View Full Code Here

   * @param p
   * @return a PropNetMove
   */
  public static Move getMoveFromProposition(Proposition p)
  {
    return new Move(p.getName().get(1));
  }
View Full Code Here

    private MachineState stateFromServer;

    @Override
    public void observe(Event event) {
        if(event instanceof MoveSelectedEvent) {
            Move theMove = ((MoveSelectedEvent)event).getMove();
            if(theQueue.size() < 2) {
                theQueue.add(theMove);
            }
        } else if(event instanceof ServerNewGameStateEvent) {
            stateFromServer = ((ServerNewGameStateEvent)event).getState();
View Full Code Here

  public void stateMachineAbort() {
    // Add an "ABORT" move to the queue so that we don't wait indefinitely
    // for a human to submit a move for the aborted match; instead we should
    // finish it up as quickly as possible so we can display the next match
    // when it arrives.
    theQueue.add(new Move(GdlPool.getConstant("ABORT")));
    theGUI.showFinalMessage("Aborted");
  }
View Full Code Here

TOP

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

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.