Example #1
0
 def testSimpleRendering(self):
     """ generated source for method testSimpleRendering """
     renderer = GdlRenderer()
     repo = GameRepository.getDefaultRepository()
     for gameKey in repo.getGameKeys():
         for rule in game.getRules():
             assertEquals(rule.__str__(), renderer.renderGdl(rule))
Example #2
0
 def runScramblerTest(self, scrambler):
     """ generated source for method runScramblerTest """
     repo = GameRepository.getDefaultRepository()
     for gameKey in repo.getGameKeys():
         for rule in game.getRules():
             theScrambledRules.add(GdlFactory.create(renderedScrambledRule))
             #  If the scrambler claims that it scrambles the game, then the
             #  scrambled rules should be different than the original rules.
             #  Otherwise they should be identical.
             if scrambler.scrambles():
                 assertTrue(gameKey, not renderedRule == renderedScrambledRule)
             else:
                 assertEquals(gameKey, renderedRule, renderedScrambledRule)
             #  One important property for any scrambler is that the original
             #  and the unscrambled Gdl must be the same. This guarantees that
             #  the server can correctly unscramble responses from the players.
             assertEquals(gameKey, renderedRule, renderedUnscrambledRule)
         #  An important property for any scrambler is that the scrambled rules
         #  have the same physics as the regular rules. For example, the number
         #  of roles in each game should be the same, and the number of facts
         #  that are true in the initial state should be the same. There could
         #  be more thorough verification here, like looking at the number of
         #  legal joint moves in the first state, or simulating entire matches,
         #  but that would be expensive.
         pNormal.initialize(game.getRules())
         pScrambled.initialize(theScrambledRules)
         assertEquals(gameKey, pNormal.getRoles().size(), pScrambled.getRoles().size())
         assertEquals(gameKey, pNormal.getInitialState().getContents().size(), pScrambled.getInitialState().getContents().size())
Example #3
0
 def main(cls, args):
     """ generated source for method main """
     description = GameRepository.getDefaultRepository().getGame("conn4").getRules()
     flattener = PropNetFlattener(description)
     flattened = flattener.flatten()
     print "Flattened description for connect four contains: \n" + len(flattened) + "\n\n"
     strings = ArrayList()
     for rule in flattened:
         strings.add(rule.__str__())
     Collections.sort(strings)
     for s in strings:
         print s
Example #4
0
 def main(cls, args):
     """ generated source for method main """
     gameName = "tictactoe"
     theGame = GameRepository.getDefaultRepository().getGame(gameName)
     flow = GameFlow(theGame.getRules())
     print "Size of flow: " + flow.getNumTurns()
     print "Sentence forms in flow: " + flow.getSentenceForms()
     i = 0
     while i < flow.getNumTurns():
         print "On turn " + i + ": " + flow.getSentencesTrueOnTurn(i)
         i += 1
     print "Turn after last: " + flow.getTurnAfterLast()
Example #5
0
 def testMappingScramblerConsistency(self):
     """ generated source for method testMappingScramblerConsistency """
     aScrambler = MappingGdlScrambler(Random(123))
     bScrambler = MappingGdlScrambler(Random(123))
     cScrambler = MappingGdlScrambler(Random(234))
     repo = GameRepository.getDefaultRepository()
     for gameKey in repo.getGameKeys():
         for rule in game.getRules():
             aScrambledRules.append(aScrambler.scramble(rule) + "\n")
             bScrambledRules.append(bScrambler.scramble(rule) + "\n")
             cScrambledRules.append(cScrambler.scramble(rule) + "\n")
         for rule in game.getRules():
             dScrambledRules.append(aScrambler.scramble(rule) + "\n")
             eScrambledRules.append(bScrambler.scramble(rule) + "\n")
             fScrambledRules.append(cScrambler.scramble(rule) + "\n")
         assertEquals(aScrambledRules.__str__(), bScrambledRules.__str__())
         assertEquals(aScrambledRules.__str__(), dScrambledRules.__str__())
         assertEquals(aScrambledRules.__str__(), eScrambledRules.__str__())
         assertFalse(aScrambledRules.__str__() == cScrambledRules.__str__())
         assertEquals(cScrambledRules.__str__(), fScrambledRules.__str__())
Example #6
0
 def main(cls, args):
     """ generated source for method main """
     showDiffs = False
     theReference = ProverStateMachine()
     theMachine = ProverStateMachine()
     theRepository = GameRepository.getDefaultRepository()
     for gameKey in theRepository.getGameKeys():
         if gameKey.contains("laikLee"):
             continue 
         #  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)
             print "Detected activation in game " + gameKey + ". Checking consistency: "
             StateMachineVerifier.checkMachineConsistency(theReference, theMachine, 10000)
             if showDiffs:
                 for x in newDescription:
                     if not description.contains(x):
                         print "NEW: " + x
                 for x in description:
                     if not newDescription.contains(x):
                         print "OLD: " + x
Example #7
0
 def main(cls, args):
     """ generated source for method main """
     description = GameRepository.getDefaultRepository().getGame("conn4").getRules()
     aa = PropNetAnnotater(description)
     print "Annotations for connect four are: \n" + aa.getAnnotations()
Example #8
0
def load_game(game_name):
    game_description = GameRepository.getDefaultRepository().getGame(
        game_name).getRules()
    machine = ProverStateMachine()
    machine.initialize(game_description)
    return machine
Example #9
0
def load_game(game_name):
    game_description = GameRepository.getDefaultRepository().getGame(game_name).getRules()
    machine = ProverStateMachine()
    machine.initialize(game_description)
    return machine