Exemplo n.º 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())
Exemplo n.º 2
0
 def parseMoves(self, symbol):
     """ generated source for method parseMoves """
     if isinstance(symbol, (SymbolAtom, )):
         return None
     else:
         while i < len(list_):
             moves.add(GdlFactory.createTerm(list_.get(i)))
             i += 1
         return moves
Exemplo n.º 3
0
Arquivo: Game.py Projeto: hobson/ggpy
 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
Exemplo n.º 4
0
 def createStart(self, gamer, list_):
     """ generated source for method createStart """
     if len(list_) < 6:
         raise IllegalArgumentException("Expected at least 5 arguments!")
     arg1 = list_.get(1)
     arg2 = list_.get(2)
     arg3 = list_.get(3)
     arg4 = list_.get(4)
     arg5 = list_.get(5)
     matchId = arg1.getValue()
     roleName = GdlFactory.createTerm(arg2)
     theRulesheet = arg3.__str__()
     startClock = Integer.valueOf(arg4.getValue())
     playClock = Integer.valueOf(arg5.getValue())
     #  For now, there are only five standard arguments. If there are any
     #  new standard arguments added to START, they should be added here.
     theReceivedGame = Game.createEphemeralGame(theRulesheet)
     return StartRequest(gamer, matchId, roleName, theReceivedGame, startClock, playClock)
Exemplo n.º 5
0
 def unscramble(self, x):
     """ generated source for method unscramble """
     return GdlFactory.create(x)
Exemplo n.º 6
0
Arquivo: Match.py Projeto: hobson/ggpy
 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
Exemplo n.º 7
0
 def unscramble(self, x):
     """ generated source for method unscramble """
     return GdlFactory.create(self.UnscramblingRenderer().renderGdl(GdlFactory.create(x)))