Package org.ggp.base.util.statemachine.implementation.prover

Examples of org.ggp.base.util.statemachine.implementation.prover.ProverStateMachine


        frame.setPreferredSize(new Dimension(1200, 900));
        frame.getContentPane().add(theVisual);
        frame.pack();
        frame.setVisible(true);

        StateMachine theMachine = new CachedStateMachine(new ProverStateMachine());
        theMachine.initialize(theGame.getRules());
        try {
            MachineState theCurrentState = theMachine.getInitialState();
            do {
                theVisual.observe(new ServerNewGameStateEvent(theCurrentState));
View Full Code Here


  }

  // This is the default State Machine
  @Override
  public StateMachine getInitialStateMachine() {
    return new CachedStateMachine(new ProverStateMachine());
  }
View Full Code Here

  /**
   * Uses a CachedProverStateMachine
   */
  @Override
  public StateMachine getInitialStateMachine() {
    return new CachedStateMachine(new ProverStateMachine());
  }
View Full Code Here

      List<Gdl> description = new TestGameRepository().getGame("test_clean_not_distinct").getRules();
        description = GdlCleaner.run(description);

        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));
        assertEquals(100, sm.getGoal(state, player));
    }
View Full Code Here

        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>();
View Full Code Here

  }

  @Override
  public List<ValidatorWarning> checkValidity(Game theGame) throws ValidatorException {
    try {
      StateMachine sm = new ProverStateMachine();
      sm.initialize(theGame.getRules());

      AimaProver prover = new AimaProver(theGame.getRules());
      GdlSentence basesQuery = GdlPool.getRelation(BASE, new GdlTerm[] {X});
      Set<GdlSentence> bases = prover.askAll(basesQuery, Collections.<GdlSentence>emptySet());
      GdlSentence inputsQuery = GdlPool.getRelation(INPUT, new GdlTerm[] {X, Y});
      Set<GdlSentence> inputs = prover.askAll(inputsQuery, Collections.<GdlSentence>emptySet());

      if (bases.size() == 0) {
        throw new ValidatorException("Could not find base propositions.");
      } else if (inputs.size() == 0) {
        throw new ValidatorException("Could not find input propositions.");
      }

      Set<GdlSentence> truesFromBases = new HashSet<GdlSentence>();
      for (GdlSentence base : bases) {
        truesFromBases.add(GdlPool.getRelation(TRUE, base.getBody()));
      }
      Set<GdlSentence> legalsFromInputs = new HashSet<GdlSentence>();
      for (GdlSentence input : inputs) {
        legalsFromInputs.add(GdlPool.getRelation(LEGAL, input.getBody()));
      }

      if (truesFromBases.isEmpty() && legalsFromInputs.isEmpty()) {
        return ImmutableList.of();
      }

      MachineState initialState = sm.getInitialState();
      MachineState state = initialState;
      long startTime = System.currentTimeMillis();
      while (System.currentTimeMillis() < startTime + millisecondsToTest) {
        //Check state against bases, inputs
        if (!truesFromBases.isEmpty()) {
          if (!truesFromBases.containsAll(state.getContents())) {
            Set<GdlSentence> missingBases = new HashSet<GdlSentence>();
            missingBases.addAll(state.getContents());
            missingBases.removeAll(truesFromBases);
            throw new ValidatorException("Found missing bases: " + missingBases);
          }
        }

        if (!legalsFromInputs.isEmpty()) {
          List<GdlSentence> legalSentences = new ArrayList<GdlSentence>();
          for (Role role : sm.getRoles()) {
            List<Move> legalMoves = sm.getLegalMoves(state, role);
            for (Move move : legalMoves) {
              legalSentences.add(GdlPool.getRelation(LEGAL, new GdlTerm[] {role.getName(), move.getContents()}));
            }
          }
          if (!legalsFromInputs.containsAll(legalSentences)) {
            Set<GdlSentence> missingInputs = new HashSet<GdlSentence>();
            missingInputs.addAll(legalSentences);
            missingInputs.removeAll(legalsFromInputs);
            throw new ValidatorException("Found missing inputs: " + missingInputs);
          }
        }

        state = sm.getRandomNextState(state);
        if (sm.isTerminal(state)) {
          state = initialState;
        }
      }
    } catch (MoveDefinitionException mde) {
      throw new ValidatorException("Could not find legal moves while simulating: " + mde);
View Full Code Here

  }

  @Override
  public List<ValidatorWarning> checkValidity(Game theGame) throws ValidatorException {
    for (int i = 0; i < numSimulations; i++) {
      StateMachine stateMachine = new ProverStateMachine();
      stateMachine.initialize(theGame.getRules());

      MachineState state = stateMachine.getInitialState();
      for (int depth = 0; !stateMachine.isTerminal(state); depth++) {
        if (depth == maxDepth) {
          throw new ValidatorException("Hit max depth while simulating: " + maxDepth);
        }
        try {
          state = stateMachine.getRandomNextState(state);
        } catch (MoveDefinitionException mde) {
          throw new ValidatorException("Could not find legal moves while simulating: " + mde);
        } catch (TransitionDefinitionException tde) {
          throw new ValidatorException("Could not find transition definition while simulating: " + tde);
        }
      }

      try {
        stateMachine.getGoals(state);
      } catch (GoalDefinitionException gde) {
        throw new ValidatorException("Could not find goals while simulating: " + gde);
      }
    }
    return ImmutableList.of();
View Full Code Here

            validate();
            runButton.setEnabled(false);
            if (theGame == null)
                return;

            StateMachine stateMachine = new ProverStateMachine();
            stateMachine.initialize(theGame.getRules());
            List<Role> roles = stateMachine.getRoles();

            int newRowCount = 11;
            for (int i = 0; i < roles.size(); i++) {
                roleLabels.add(new JLabel(roles.get(i).getName().toString() + ":"));
                playerFields.add(playerSelector.getPlayerSelectorBox());
View Full Code Here

*/
public class TransformTester {
  public static void main(String args[]) throws InterruptedException {

      final boolean showDiffs = false;
        final ProverStateMachine theReference = new ProverStateMachine();
        final ProverStateMachine theMachine = new ProverStateMachine();

        GameRepository theRepository = GameRepository.getDefaultRepository();
        for(String gameKey : theRepository.getGameKeys()) {
            if(gameKey.contains("laikLee")) continue;
            List<Gdl> description = theRepository.getGame(gameKey).getRules();
            List<Gdl> newDescription = description;

            // Choose the transformation(s) to test here
            description = DeORer.run(description);
            newDescription = VariableConstrainer.replaceFunctionValuedVariables(description);

            if(description.hashCode() != newDescription.hashCode()) {
                theReference.initialize(description);
                theMachine.initialize(newDescription);
                System.out.println("Detected activation in game " + gameKey + ". Checking consistency: ");
                StateMachineVerifier.checkMachineConsistency(theReference, theMachine, 10000);

                if(showDiffs) {
                    for(Gdl x : newDescription) {
View Full Code Here

        return false;
    }

    private boolean attemptLoadingProverMachine() {
        try {
            StateMachine theStateMachine = new ProverStateMachine();
            theStateMachine.initialize(gameDescription);
            theBackingMachine = theStateMachine;
            GamerLogger.log("StateMachine", "Failsafe Machine: successfully loaded traditional prover.");
            return true;
        } catch(Exception e1) {
        } catch(ThreadDeath d) {
View Full Code Here

TOP

Related Classes of org.ggp.base.util.statemachine.implementation.prover.ProverStateMachine

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.