def create(cls, description): """ generated source for method create """ try: GamerLogger.log("StateMachine", "Converting...") return PropNetConverter().convert(Role.computeRoles(description), flatDescription) except Exception as e: GamerLogger.logStackTrace("StateMachine", e) return None
def __init__(self, matchId, previewClock, startClock, playClock, theGame): """ generated source for method __init__ """ self.matchId = matchId self.previewClock = previewClock self.startClock = startClock self.playClock = playClock self.theGame = theGame self.startTime = Date() self.randomToken = getRandomString(32) self.spectatorAuthToken = getRandomString(12) self.isCompleted = False self.isAborted = False self.numRoles = Role.computeRoles(theGame.getRules()).size() self.moveHistory = ArrayList() self.stateHistory = ArrayList() self.stateTimeHistory = ArrayList() self.errorHistory = ArrayList() self.goalValues = ArrayList()
def create_0(cls, description, verbose): """ generated source for method create_0 """ print "Building propnet..." startTime = System.currentTimeMillis() description = GdlCleaner.run(description) description = DeORer.run(description) description = VariableConstrainer.replaceFunctionValuedVariables(description) description = Relationizer.run(description) description = CondensationIsolator.run(description) if verbose: for gdl in description: print gdl # We want to start with a rule graph and follow the rule graph. # Start by finding general information about the game model = SentenceDomainModelFactory.createWithCartesianDomains(description) # Restrict domains to values that could actually come up in rules. # See chinesecheckers4's "count" relation for an example of why this # could be useful. model = SentenceDomainModelOptimizer.restrictDomainsToUsefulValues(model) if verbose: print "Setting constants..." constantChecker = ConstantCheckerFactory.createWithForwardChaining(model) if verbose: print "Done setting constants" sentenceFormNames = SentenceForms.getNames(model.getSentenceForms()) usingBase = sentenceFormNames.contains("base") usingInput = sentenceFormNames.contains("input") # For now, we're going to build this to work on those with a # particular restriction on the dependency graph: # Recursive loops may only contain one sentence form. # This describes most games, but not all legal games. dependencyGraph = model.getDependencyGraph() if verbose: print "Computing topological ordering... ", System.out.flush() ConcurrencyUtils.checkForInterruption() topologicalOrdering = getTopologicalOrdering(model.getSentenceForms(), dependencyGraph, usingBase, usingInput) if verbose: print "done" roles = Role.computeRoles(description) components = HashMap() negations = HashMap() trueComponent = Constant(True) falseComponent = Constant(False) functionInfoMap = HashMap() completedSentenceFormValues = HashMap() for form in topologicalOrdering: ConcurrencyUtils.checkForInterruption() if verbose: print "Adding sentence form " + form, System.out.flush() if constantChecker.isConstantForm(form): if verbose: print " (constant)" # Only add it if it's important if form.__name__ == cls.LEGAL or form.__name__ == cls.GOAL or form.__name__ == cls.INIT: # Add it for trueSentence in constantChecker.getTrueSentences(form): trueProp.addInput(trueComponent) trueComponent.addOutput(trueProp) components.put(trueSentence, trueComponent) if verbose: print "Checking whether " + form + " is a functional constant..." addConstantsToFunctionInfo(form, constantChecker, functionInfoMap) addFormToCompletedValues(form, completedSentenceFormValues, constantChecker) continue if verbose: print # TODO: Adjust "recursive forms" appropriately # Add a temporary sentence form thingy? ... addSentenceForm(form, model, components, negations, trueComponent, falseComponent, usingBase, usingInput, Collections.singleton(form), temporaryComponents, temporaryNegations, functionInfoMap, constantChecker, completedSentenceFormValues) # TODO: Pass these over groups of multiple sentence forms if verbose and not temporaryComponents.isEmpty(): print "Processing temporary components..." processTemporaryComponents(temporaryComponents, temporaryNegations, components, negations, trueComponent, falseComponent) addFormToCompletedValues(form, completedSentenceFormValues, components) # if(verbose) # TODO: Add this, but with the correct total number of components (not just Propositions) # print " "+completedSentenceFormValues.get(form).size() + " components added"; # Connect "next" to "true" if verbose: print "Adding transitions..." addTransitions(components) # Set up "init" proposition if verbose: print "Setting up 'init' proposition..." setUpInit(components, trueComponent, falseComponent) # Now we can safely... removeUselessBasePropositions(components, negations, trueComponent, falseComponent) if verbose: print "Creating component set..." componentSet = HashSet(components.values()) # Try saving some memory here... components = None negations = None completeComponentSet(componentSet) ConcurrencyUtils.checkForInterruption() if verbose: print "Initializing propnet object..." # Make it look the same as the PropNetFactory results, until we decide # how we want it to look normalizePropositions(componentSet) propnet = PropNet(roles, componentSet) if verbose: print "Done setting up propnet; took " + (System.currentTimeMillis() - startTime) + "ms, has " + len(componentSet) + " components and " + propnet.getNumLinks() + " links" print "Propnet has " + propnet.getNumAnds() + " ands; " + propnet.getNumOrs() + " ors; " + propnet.getNumNots() + " nots" # print propnet; return propnet
def initialize(self, description): """ generated source for method initialize """ self.prover = AimaProver(description) self.roles = Role.computeRoles(description) self.initialState = computeInitialState()
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
def completeMetadataFromRulesheet(cls, theMetaJSON, theRulesheet): """ generated source for method completeMetadataFromRulesheet """ theRoles = Role.computeRoles(Game.createEphemeralGame(Game.preprocessRulesheet(theRulesheet)).getRules()) theMetaJSON.put("roleNames", theRoles) theMetaJSON.put("numRoles", len(theRoles))