Exemple #1
0
 def testSimpleSigning(self):
     """ generated source for method testSimpleSigning """
     p = BaseCryptography.generateKeys()
     x = JSONObject("{3:{7:9,c:4,2:5,a:6},1:2,2:3,moves:14,states:21,alpha:'beta'}")
     assertFalse(SignableJSON.isSignedJSON(x))
     SignableJSON.signJSON(x, p.thePublicKey, p.thePrivateKey)
     assertTrue(SignableJSON.isSignedJSON(x))
     assertTrue(SignableJSON.verifySignedJSON(x))
     x2 = JSONObject(x.__str__().replace(",", ", ").replace("{", "{ ").replace("}", "} "))
     assertTrue(SignableJSON.isSignedJSON(x2))
     assertTrue(SignableJSON.verifySignedJSON(x2))
     x3 = JSONObject("{1:2,2:3,3:4}")
     assertFalse(SignableJSON.isSignedJSON(x3))
Exemple #2
0
 def renderSimpleCanonicalJSON(cls, x):
     """ generated source for method renderSimpleCanonicalJSON """
     try:
         if isinstance(x, (JSONObject, )):
             #  Sort the keys
             while i.hasNext():
             while keys.hasNext():
                 if 1 > len(sb):
                     sb.append(',')
                 sb.append(JSONObject.quote(o.__str__()))
                 sb.append(':')
                 sb.append(cls.renderSimpleCanonicalJSON(theObject.get(o.__str__())))
             sb.append('}')
             return sb.__str__()
         elif isinstance(x, (JSONArray, )):
             sb.append("[")
             while i < len:
                 if i > 0:
                     sb.append(",")
                 sb.append(cls.renderSimpleCanonicalJSON(theArray.get(i)))
                 i += 1
             sb.append("]")
             return sb.__str__()
         else:
             if x == None or x == None:
                 return "null"
             if isinstance(x, (JSONString, )):
                 try:
                     object_ = (x).toJSONString()
                 except Exception as e:
                     raise JSONException(e)
                 if isinstance(object_, (str, )):
                     return str(object_)
                 raise JSONException("Bad value from toJSONString: " + object_)
             if isinstance(x, (Number, )):
                 return JSONObject.numberToString(x)
             if isinstance(x, (bool, )) or isinstance(x, (JSONObject, )) or isinstance(x, (JSONArray, )):
                 return x.__str__()
             if isinstance(x, (Map, )):
                 return cls.renderSimpleCanonicalJSON(JSONObject(x)).__str__()
             if isinstance(x, (Collection, )):
                 return cls.renderSimpleCanonicalJSON(JSONArray(x)).__str__()
             if x.__class__.isArray():
                 return cls.renderSimpleCanonicalJSON(JSONArray(x)).__str__()
             return JSONObject.quote(x.__str__())
     except Exception as e:
         return None
 def loadParamsJSON(self, fromFile):
     """ generated source for method loadParamsJSON """
     if not fromFile.exists():
         return
     self.associatedFile = fromFile
     self.associatedFileField.setText(self.associatedFile.getPath())
     self.params = JSONObject()
     try:
         try:
             while (line = br.readLine()) != None:
                 pdata.append(line)
         finally:
             br.close()
         self.params = JSONObject(pdata.__str__())
         self.savedParams = self.params.__str__()
         self.setUIfromJSON()
         self.syncJSONtoUI()
     except Exception as e:
         e.printStackTrace()
Exemple #4
0
 def verifySignedJSON(cls, theJSON):
     """ generated source for method verifySignedJSON """
     if not theJSON.has("matchHostPK") or not theJSON.has("matchHostSignature"):
         raise RuntimeException("JSON not signed! Cannot verify.")
     thePK = theJSON.getString("matchHostPK")
     theSignature = theJSON.getString("matchHostSignature")
     if not theSignature.startsWith(cls.theCanonicalizationPrefix):
         return False
     theSignature = theSignature.replaceFirst(cls.theCanonicalizationPrefix, "")
     tempObject = JSONObject(theJSON.__str__())
     tempObject.remove("matchHostSignature")
     try:
         return BaseCryptography.verifySignature(thePK, theSignature, CanonicalJSON.getCanonicalForm(tempObject, CanonicalizationStrategy.SIMPLE))
     except InvalidKeyException as e:
         pass
     except SignatureException as e:
         pass
     except NoSuchAlgorithmException as e:
         pass
     except UnsupportedEncodingException as e:
         pass
     return False
Exemple #5
0
 def toXML(self):
     """ generated source for method toXML """
     try:
         theXML.append("<match>")
         for key in JSONObject.getNames(theJSON):
             if isinstance(value, (JSONObject, )):
                 raise RuntimeException("Unexpected embedded JSONObject in match JSON with tag " + key + "; could not convert to XML.")
             elif not (isinstance(value, (JSONArray, ))):
                 theXML.append(renderLeafXML(key, theJSON.get(key)))
             elif key == "states":
                 theXML.append(renderStateHistoryXML(self.stateHistory))
             elif key == "moves":
                 theXML.append(renderMoveHistoryXML(self.moveHistory))
             elif key == "errors":
                 theXML.append(renderErrorHistoryXML(self.errorHistory))
             else:
                 theXML.append(renderArrayXML(key, value))
         theXML.append("</match>")
         return theXML.__str__()
     except JSONException as je:
         return None
Exemple #6
0
 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__()
Exemple #7
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
 def __init__(self):
     """ generated source for method __init__ """
     super(ConfigurableConfigPanel, self).__init__(GridBagLayout())
     leftPanel = JPanel(GridBagLayout())
     leftPanel.setBorder(TitledBorder("Major Parameters"))
     self.rightPanel = JPanel(GridBagLayout())
     self.rightPanel.setBorder(TitledBorder("Minor Parameters"))
     self.strategy = JComboBox([None]*)
     self.metagameStrategy = JComboBox([None]*)
     self.stateMachine = JComboBox([None]*)
     self.cacheStateMachine = JCheckBox()
     self.maxPlys = JSpinner(SpinnerNumberModel(1, 1, 100, 1))
     self.heuristicFocus = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
     self.heuristicMobility = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
     self.heuristicOpponentFocus = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
     self.heuristicOpponentMobility = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
     self.mcDecayRate = JSpinner(SpinnerNumberModel(0, 0, 99, 1))
     self.name = JTextField()
     self.name.setColumns(20)
     self.name.setText("Player #" + Random().nextInt(100000))
     self.loadButton = JButton(loadButtonMethod())
     self.saveButton = JButton(saveButtonMethod())
     self.saveAsButton = JButton(saveAsButtonMethod())
     self.associatedFileField = JTextField()
     self.associatedFileField.setEnabled(False)
     buttons = JPanel()
     buttons.add(self.loadButton)
     buttons.add(self.saveButton)
     buttons.add(self.saveAsButton)
     nRow = 0
     leftPanel.add(JLabel("Name"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
     __nRow_0 = nRow
     nRow += 1
     leftPanel.add(self.name, GridBagConstraints(1, __nRow_0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
     leftPanel.add(JLabel("Gaming Strategy"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
     __nRow_1 = nRow
     nRow += 1
     leftPanel.add(self.strategy, GridBagConstraints(1, __nRow_1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
     leftPanel.add(JLabel("Metagame Strategy"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
     __nRow_2 = nRow
     nRow += 1
     leftPanel.add(self.metagameStrategy, GridBagConstraints(1, __nRow_2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
     leftPanel.add(JLabel("State Machine"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
     __nRow_3 = nRow
     nRow += 1
     leftPanel.add(self.stateMachine, GridBagConstraints(1, __nRow_3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
     __nRow_4 = nRow
     nRow += 1
     leftPanel.add(buttons, GridBagConstraints(1, __nRow_4, 2, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, Insets(5, 5, 0, 5), 0, 0))
     leftPanel.add(self.associatedFileField, GridBagConstraints(0, nRow, 2, 1, 1.0, 0.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.HORIZONTAL, Insets(0, 5, 5, 5), 0, 0))
     layoutRightPanel()
     add(leftPanel, GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(5, 5, 5, 5), 5, 5))
     add(self.rightPanel, GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(5, 5, 5, 5), 5, 5))
     self.params = JSONObject()
     syncJSONtoUI()
     self.strategy.addActionListener(self)
     self.metagameStrategy.addActionListener(self)
     self.stateMachine.addActionListener(self)
     self.cacheStateMachine.addActionListener(self)
     self.maxPlys.addChangeListener(self)
     self.heuristicFocus.addChangeListener(self)
     self.heuristicMobility.addChangeListener(self)
     self.heuristicOpponentFocus.addChangeListener(self)
     self.heuristicOpponentMobility.addChangeListener(self)
     self.mcDecayRate.addChangeListener(self)
     self.name.getDocument().addDocumentListener(self)
class ConfigurableConfigPanel(ConfigPanel, ActionListener, DocumentListener, ChangeListener):
    """ generated source for class ConfigurableConfigPanel """
    serialVersionUID = 1L
    associatedFile = File()
    associatedFileField = JTextField()
    params = JSONObject()
    savedParams = str()
    loadButton = JButton()
    saveAsButton = JButton()
    saveButton = JButton()
    name = JTextField()
    strategy = JComboBox()
    metagameStrategy = JComboBox()
    stateMachine = JComboBox()
    cacheStateMachine = JCheckBox()
    maxPlys = JSpinner()
    heuristicFocus = JSpinner()
    heuristicMobility = JSpinner()
    heuristicOpponentFocus = JSpinner()
    heuristicOpponentMobility = JSpinner()
    mcDecayRate = JSpinner()
    rightPanel = JPanel()

    def __init__(self):
        """ generated source for method __init__ """
        super(ConfigurableConfigPanel, self).__init__(GridBagLayout())
        leftPanel = JPanel(GridBagLayout())
        leftPanel.setBorder(TitledBorder("Major Parameters"))
        self.rightPanel = JPanel(GridBagLayout())
        self.rightPanel.setBorder(TitledBorder("Minor Parameters"))
        self.strategy = JComboBox([None]*)
        self.metagameStrategy = JComboBox([None]*)
        self.stateMachine = JComboBox([None]*)
        self.cacheStateMachine = JCheckBox()
        self.maxPlys = JSpinner(SpinnerNumberModel(1, 1, 100, 1))
        self.heuristicFocus = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
        self.heuristicMobility = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
        self.heuristicOpponentFocus = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
        self.heuristicOpponentMobility = JSpinner(SpinnerNumberModel(1, 0, 10, 1))
        self.mcDecayRate = JSpinner(SpinnerNumberModel(0, 0, 99, 1))
        self.name = JTextField()
        self.name.setColumns(20)
        self.name.setText("Player #" + Random().nextInt(100000))
        self.loadButton = JButton(loadButtonMethod())
        self.saveButton = JButton(saveButtonMethod())
        self.saveAsButton = JButton(saveAsButtonMethod())
        self.associatedFileField = JTextField()
        self.associatedFileField.setEnabled(False)
        buttons = JPanel()
        buttons.add(self.loadButton)
        buttons.add(self.saveButton)
        buttons.add(self.saveAsButton)
        nRow = 0
        leftPanel.add(JLabel("Name"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_0 = nRow
        nRow += 1
        leftPanel.add(self.name, GridBagConstraints(1, __nRow_0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
        leftPanel.add(JLabel("Gaming Strategy"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_1 = nRow
        nRow += 1
        leftPanel.add(self.strategy, GridBagConstraints(1, __nRow_1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
        leftPanel.add(JLabel("Metagame Strategy"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_2 = nRow
        nRow += 1
        leftPanel.add(self.metagameStrategy, GridBagConstraints(1, __nRow_2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
        leftPanel.add(JLabel("State Machine"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_3 = nRow
        nRow += 1
        leftPanel.add(self.stateMachine, GridBagConstraints(1, __nRow_3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, Insets(5, 5, 5, 5), 5, 5))
        __nRow_4 = nRow
        nRow += 1
        leftPanel.add(buttons, GridBagConstraints(1, __nRow_4, 2, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, Insets(5, 5, 0, 5), 0, 0))
        leftPanel.add(self.associatedFileField, GridBagConstraints(0, nRow, 2, 1, 1.0, 0.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.HORIZONTAL, Insets(0, 5, 5, 5), 0, 0))
        layoutRightPanel()
        add(leftPanel, GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(5, 5, 5, 5), 5, 5))
        add(self.rightPanel, GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, Insets(5, 5, 5, 5), 5, 5))
        self.params = JSONObject()
        syncJSONtoUI()
        self.strategy.addActionListener(self)
        self.metagameStrategy.addActionListener(self)
        self.stateMachine.addActionListener(self)
        self.cacheStateMachine.addActionListener(self)
        self.maxPlys.addChangeListener(self)
        self.heuristicFocus.addChangeListener(self)
        self.heuristicMobility.addChangeListener(self)
        self.heuristicOpponentFocus.addChangeListener(self)
        self.heuristicOpponentMobility.addChangeListener(self)
        self.mcDecayRate.addChangeListener(self)
        self.name.getDocument().addDocumentListener(self)

    def layoutRightPanel(self):
        """ generated source for method layoutRightPanel """
        nRow = 0
        self.rightPanel.removeAll()
        self.rightPanel.add(JLabel("State machine cache?"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_5 = nRow
        nRow += 1
        self.rightPanel.add(self.cacheStateMachine, GridBagConstraints(1, __nRow_5, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        if self.strategy.getSelectedItem().__str__() == "Heuristic":
        __nRow_6 = nRow
        nRow += 1
        __nRow_7 = nRow
        nRow += 1
        __nRow_8 = nRow
        nRow += 1
        __nRow_9 = nRow
        nRow += 1
        __nRow_10 = nRow
        nRow += 1
            self.rightPanel.add(JLabel("Max plys?"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.maxPlys, GridBagConstraints(1, __nRow_6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(JLabel("Focus Heuristic Weight"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.heuristicFocus, GridBagConstraints(1, __nRow_7, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(JLabel("Mobility Heuristic Weight"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.heuristicMobility, GridBagConstraints(1, __nRow_8, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(JLabel("Opponent Focus Heuristic Weight"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.heuristicOpponentFocus, GridBagConstraints(1, __nRow_9, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(JLabel("Opponent Mobility Heuristic Weight"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.heuristicOpponentMobility, GridBagConstraints(1, __nRow_10, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        if self.strategy.getSelectedItem().__str__() == "Monte Carlo":
        __nRow_11 = nRow
        nRow += 1
            self.rightPanel.add(JLabel("Goal Decay Rate"), GridBagConstraints(0, nRow, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
            self.rightPanel.add(self.mcDecayRate, GridBagConstraints(1, __nRow_11, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        __nRow_12 = nRow
        nRow += 1
        self.rightPanel.add(JLabel(), GridBagConstraints(2, __nRow_12, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, Insets(5, 5, 5, 5), 5, 5))
        self.rightPanel.repaint()

    @SuppressWarnings("unchecked")
    def getParameter(self, name, defaultValue):
        """ generated source for method getParameter """
        try:
            if self.params.has(name):
                return self.params.get(name)
            else:
                return defaultValue
        except JSONException as je:
            return defaultValue

    def actionPerformed(self, arg0):
        """ generated source for method actionPerformed """
        if arg0.getSource() == self.strategy:
            self.layoutRightPanel()
        syncJSONtoUI()

    def changedUpdate(self, e):
        """ generated source for method changedUpdate """
        syncJSONtoUI()

    def insertUpdate(self, e):
        """ generated source for method insertUpdate """
        syncJSONtoUI()

    def removeUpdate(self, e):
        """ generated source for method removeUpdate """
        syncJSONtoUI()

    def stateChanged(self, arg0):
        """ generated source for method stateChanged """
        syncJSONtoUI()

    def syncJSONtoUI(self):
        """ generated source for method syncJSONtoUI """
        if settingUI:
            return
        self.params = getJSONfromUI()
        self.saveButton.setEnabled(self.savedParams == None or not self.params.__str__() == self.savedParams)

    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

    settingUI = False

    def setUIfromJSON(self):
        """ generated source for method setUIfromJSON """
        self.settingUI = True
        try:
            if self.params.has("name"):
                self.name.setText(self.params.getString("name"))
            if self.params.has("strategy"):
                self.strategy.setSelectedItem(self.params.getString("strategy"))
            if self.params.has("metagameStrategy"):
                self.metagameStrategy.setSelectedItem(self.params.getString("metagameStrategy"))
            if self.params.has("stateMachine"):
                self.stateMachine.setSelectedItem(self.params.getString("stateMachine"))
            if self.params.has("cacheStateMachine"):
                self.cacheStateMachine.setSelected(self.params.getBoolean("cacheStateMachine"))
            if self.params.has("maxPlys"):
                self.maxPlys.getModel().setValue(self.params.getInt("maxPlys"))
            if self.params.has("heuristicFocus"):
                self.heuristicFocus.getModel().setValue(self.params.getInt("heuristicFocus"))
            if self.params.has("heuristicMobility"):
                self.heuristicMobility.getModel().setValue(self.params.getInt("heuristicMobility"))
            if self.params.has("heuristicOpponentFocus"):
                self.heuristicOpponentFocus.getModel().setValue(self.params.getInt("heuristicOpponentFocus"))
            if self.params.has("heuristicOpponentMobility"):
                self.heuristicOpponentMobility.getModel().setValue(self.params.getInt("heuristicOpponentMobility"))
            if self.params.has("mcDecayRate"):
                self.mcDecayRate.getModel().setValue(self.params.getInt("mcDecayRate"))
        except JSONException as je:
            je.printStackTrace()
        finally:
            self.settingUI = False

    def loadParamsJSON(self, fromFile):
        """ generated source for method loadParamsJSON """
        if not fromFile.exists():
            return
        self.associatedFile = fromFile
        self.associatedFileField.setText(self.associatedFile.getPath())
        self.params = JSONObject()
        try:
            try:
                while (line = br.readLine()) != None:
                    pdata.append(line)
            finally:
                br.close()
            self.params = JSONObject(pdata.__str__())
            self.savedParams = self.params.__str__()
            self.setUIfromJSON()
            self.syncJSONtoUI()
        except Exception as e:
            e.printStackTrace()

    def saveParamsJSON(self, saveAs):
        """ generated source for method saveParamsJSON """
        try:
            if saveAs or self.associatedFile == None:
                fc.setFileFilter(PlayerFilter())
                if returnVal == JFileChooser.APPROVE_OPTION and fc.getSelectedFile() != None:
                    if toFile.__name__.contains("."):
                        self.associatedFile = File(toFile.getParentFile(), toFile.__name__.substring(0, toFile.__name__.lastIndexOf(".")) + ".player")
                    else:
                        self.associatedFile = File(toFile.getParentFile(), toFile.__name__ + ".player")
                    self.associatedFileField.setText(self.associatedFile.getPath())
                else:
                    return
            bw.write(self.params.__str__())
            bw.close()
            self.savedParams = self.params.__str__()
            self.syncJSONtoUI()
        except IOException as ie:
            ie.printStackTrace()

    def saveButtonMethod(self):
        """ generated source for method saveButtonMethod """
        return AbstractAction("Save")

    def saveAsButtonMethod(self):
        """ generated source for method saveAsButtonMethod """
        return AbstractAction("Save As")

    def loadButtonMethod(self):
        """ generated source for method loadButtonMethod """
        return AbstractAction("Load")

    class PlayerFilter(FileFilter):
        """ generated source for class PlayerFilter """
        def accept(self, f):
            """ generated source for method accept """
            if f.isDirectory():
                return True
            return f.__name__.endsWith(".player")

        def getDescription(self):
            """ generated source for method getDescription """
            return "GGP Players (*.player)"
 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