Exemple #1
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())
Exemple #2
0
 def getRules(self):
     """ generated source for method getRules """
     try:
         while i < len(list_):
             rules.add(GdlFactory.create(list_.get(i)))
             i += 1
         return rules
     except GdlFormatException as e:
         e.printStackTrace()
         return None
     except SymbolFormatException as e:
         e.printStackTrace()
         return None
Exemple #3
0
 def unscramble(self, x):
     """ generated source for method unscramble """
     return GdlFactory.create(x)
Exemple #4
0
 def __init___0(self, theJSON, theGame, authToken):
     """ generated source for method __init___0 """
     theMatchObject = JSONObject(theJSON)
     self.matchId = theMatchObject.getString("matchId")
     self.startClock = theMatchObject.getInt("startClock")
     self.playClock = theMatchObject.getInt("playClock")
     if theGame == None:
         self.theGame = RemoteGameRepository.loadSingleGame(theMatchObject.getString("gameMetaURL"))
         if self.theGame == None:
             raise RuntimeException("Could not find metadata for game referenced in Match object: " + theMatchObject.getString("gameMetaURL"))
     else:
         self.theGame = theGame
     if theMatchObject.has("previewClock"):
         self.previewClock = theMatchObject.getInt("previewClock")
     else:
         self.previewClock = -1
     self.startTime = Date(theMatchObject.getLong("startTime"))
     self.randomToken = theMatchObject.getString("randomToken")
     self.spectatorAuthToken = authToken
     self.isCompleted = theMatchObject.getBoolean("isCompleted")
     if theMatchObject.has("isAborted"):
         self.isAborted = theMatchObject.getBoolean("isAborted")
     else:
         self.isAborted = False
     self.numRoles = Role.computeRoles(self.theGame.getRules()).size()
     self.moveHistory = ArrayList()
     self.stateHistory = ArrayList()
     self.stateTimeHistory = ArrayList()
     self.errorHistory = ArrayList()
     theMoves = theMatchObject.getJSONArray("moves")
     i = 0
     while i < len(theMoves):
         while j < len(moveElements):
             theMove.add(GdlFactory.createTerm(moveElements.getString(j)))
             j += 1
         self.moveHistory.add(theMove)
         i += 1
     theStates = theMatchObject.getJSONArray("states")
     i = 0
     while i < len(theStates):
         while j < len(stateElements):
             theState.add(GdlFactory.create("( true " + stateElements.get(j).__str__() + " )"))
             j += 1
         self.stateHistory.add(theState)
         i += 1
     theStateTimes = theMatchObject.getJSONArray("stateTimes")
     i = 0
     while i < len(theStateTimes):
         self.stateTimeHistory.add(Date(theStateTimes.getLong(i)))
         i += 1
     if theMatchObject.has("errors"):
         while i < len(theErrors):
             while j < len(errorElements):
                 theMoveErrors.add(errorElements.getString(j))
                 j += 1
             self.errorHistory.add(theMoveErrors)
             i += 1
     self.goalValues = ArrayList()
     try:
         while i < len(theGoalValues):
             self.goalValues.add(theGoalValues.getInt(i))
             i += 1
     except JSONException as e:
         pass
     #  TODO: Add a way to recover cryptographic public keys and signatures.
     #  Or, perhaps loading a match into memory for editing should strip those?
     if theMatchObject.has("playerNamesFromHost"):
         self.thePlayerNamesFromHost = ArrayList()
         while i < len(thePlayerNames):
             self.thePlayerNamesFromHost.add(thePlayerNames.getString(i))
             i += 1
     if theMatchObject.has("isPlayerHuman"):
         self.isPlayerHuman = ArrayList()
         while i < len(isPlayerHumanArray):
             self.isPlayerHuman.add(isPlayerHumanArray.getBoolean(i))
             i += 1
Exemple #5
0
 def unscramble(self, x):
     """ generated source for method unscramble """
     return GdlFactory.create(self.UnscramblingRenderer().renderGdl(GdlFactory.create(x)))