def toJSON(self): """ generated source for method toJSON """ theJSON = JSONObject() try: theJSON.put("matchId", self.matchId) theJSON.put("randomToken", self.randomToken) theJSON.put("startTime", self.startTime.getTime()) theJSON.put("gameMetaURL", getGameRepositoryURL()) theJSON.put("isCompleted", self.isCompleted) theJSON.put("isAborted", self.isAborted) theJSON.put("states", JSONArray(renderArrayAsJSON(renderStateHistory(self.stateHistory), True))) theJSON.put("moves", JSONArray(renderArrayAsJSON(renderMoveHistory(self.moveHistory), False))) theJSON.put("stateTimes", JSONArray(renderArrayAsJSON(self.stateTimeHistory, False))) if len(self.errorHistory) > 0: theJSON.put("errors", JSONArray(renderArrayAsJSON(renderErrorHistory(self.errorHistory), False))) if len(self.goalValues) > 0: theJSON.put("goalValues", self.goalValues) theJSON.put("previewClock", self.previewClock) theJSON.put("startClock", self.startClock) theJSON.put("playClock", self.playClock) if self.thePlayerNamesFromHost != None: theJSON.put("playerNamesFromHost", self.thePlayerNamesFromHost) if self.isPlayerHuman != None: theJSON.put("isPlayerHuman", self.isPlayerHuman) theJSON.put("scrambled", self.theGdlScrambler.scrambles() if self.theGdlScrambler != None else False) except JSONException as e: return None if self.theCryptographicKeys != None: try: SignableJSON.signJSON(theJSON, self.theCryptographicKeys.thePublicKey, self.theCryptographicKeys.thePrivateKey) if not SignableJSON.isSignedJSON(theJSON): raise Exception("Could not recognize signed match: " + theJSON) if not SignableJSON.verifySignedJSON(theJSON): raise Exception("Could not verify signed match: " + theJSON) except Exception as e: System.err.println(e) theJSON.remove("matchHostPK") theJSON.remove("matchHostSignature") return theJSON.__str__()
def getJSONfromUI(self): """ generated source for method getJSONfromUI """ newParams = JSONObject() try: if not self.name.getText().isEmpty(): newParams.put("name", self.name.getText()) newParams.put("strategy", self.strategy.getSelectedItem().__str__()) newParams.put("metagameStrategy", self.metagameStrategy.getSelectedItem().__str__()) newParams.put("stateMachine", self.stateMachine.getSelectedItem().__str__()) newParams.put("cacheStateMachine", self.cacheStateMachine.isSelected()) newParams.put("maxPlys", self.maxPlys.getModel().getValue()) newParams.put("heuristicFocus", self.heuristicFocus.getModel().getValue()) newParams.put("heuristicMobility", self.heuristicMobility.getModel().getValue()) newParams.put("heuristicOpponentFocus", self.heuristicOpponentFocus.getModel().getValue()) newParams.put("heuristicOpponentMobility", self.heuristicOpponentMobility.getModel().getValue()) newParams.put("mcDecayRate", self.mcDecayRate.getModel().getValue()) except JSONException as je: je.printStackTrace() return newParams