Esempio n. 1
0
 def asXmlNode(self):
     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     xn = xp.xmlNode('<neuron id="%s" trainingRate="%f" activation="%f"/>' %
                     (self.id, self.trainingRate, self.activation))
     for i in self.inputs:
         xn.add(i.asXmlNode())
     return xn
Esempio n. 2
0
 def parse(self):
     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     try:
         self.nn = xmp.xmlNode(self.ss)
     except xmp.ExpatError, ex:
         s = rl.scanf("$$: line $$, column $$")
         self.error = s.scan(str(ex))
         raise xmlTemplateException("xmlTemplate Error")
Esempio n. 3
0
 def asXmlNode(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     """ save as xml returning an xml node object
     """
     xn = xp.xmlNode('<neural_net formatVersion="%s" name="%s" numHidden="%d"/>' % (self.formatVersion, self.name, self.numHidden))
     self.xmlLayer(xn, 'sensors', self.sensors)
     self.xmlHidden(xn)
     self.xmlLayer(xn, 'outputs', self.outputs)
     return xn
Esempio n. 4
0
 def asXmlNode(self):
     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     """ save as xml returning an xml node object
     """
     xn = xp.xmlNode(
         '<neural_net formatVersion="%s" name="%s" numHidden="%d"/>' %
         (self.formatVersion, self.name, self.numHidden))
     self.xmlLayer(xn, 'sensors', self.sensors)
     self.xmlHidden(xn)
     self.xmlLayer(xn, 'outputs', self.outputs)
     return xn
Esempio n. 5
0
    def save(self, fn=None):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        """ save the game to a file 
        """
        if fn is None:
            fn = self.display.getFileName("Save Game To:", exists=False)
            if not fn: 
                return

        with open(fn , 'w') as otf:
            xn = xp.xmlNode('<blocks ver="%s" round="%d" state="%d" sstate="%d"/>' % (__VERSION__, self.rnd, self.state, self.sstate))
    
            p1 = xn.add('<player1 type="%s"/>' % (self.player1.typ))
            self.player1.save(p1)
    
            p2 = xn.add('<player2 type="%s"/>' % (self.player2.typ))
            self.player2.save(p2)
    
            self.brd.save(xn)
            xn.writeFile(otf)
Esempio n. 6
0
    def __init__(self, inputFileName, fn):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        object.__init__(self)
        self.uid = 0
        self.uname = 0

        self.infn = inputFileName

        inf = file(inputFileName, "rU")
        self.xml = inf.read()
        self.root = xp.xmlNode(self.xml)
        inf.close()

        self.otf = file(fn + '.py', 'w')
        self.mixin = fn + '_mixin'

        self.panel = self.frame = None
        self.menuInit = ''
        self.menuFuncs = ''
        self.statusBar = ''
Esempio n. 7
0
    def restore(self, fn=None):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        """ restore the game from the file
        """
        if fn is None:
            fn = self.display.getFileName("Restore Game From:", exists=True)
            if not fn: 
                return

        with open(fn , 'rU') as inf:        
            xn = xp.xmlNode(inf.read())

        if not(xn['ver'] == __VERSION__):
            print('unable to restore file "%s"' % fn, file=oss.stderr)
            return

        self.rnd = int(xn['round'])

        p1 = xn.findChild('player1')
        self.player1 = player.PlayerFactory(self, p1['type'])

        p2 = xn.findChild('player2')
        self.player2 = player.PlayerFactory(self, p2['type'])

        b = xn.findChild('board')
        brd = board.Board(self.player1, self.player2, self.display)

        ## restore game state     
        brd.skip = xn['sstate'] == '1'
        self.state = int(xn['state'])

        brd.restore(b)
        self.player1.restore(p1)
        self.player2.restore(p2)
        self.play(brd)

        
Esempio n. 8
0
 def asXmlNode(self):
     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     return xp.xmlNode('<dendrite elem="%s" weight="%1.20f"/>' %
                       (self.elem.id, self.weight))
Esempio n. 9
0
 def asXmlNode(self):
     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     return xp.xmlNode('<sensor id="%s"/>' % (self.id))
Esempio n. 10
0
 def asXmlNode(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     return xp.xmlNode('<dendrite elem="%s" weight="%1.20f"/>' % (self.elem.id, self.weight))
Esempio n. 11
0
 def asXmlNode(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     xn = xp.xmlNode('<neuron id="%s" trainingRate="%f" activation="%f"/>' % (self.id, self.trainingRate, self.activation))
     for i in self.inputs:
         xn.add(i.asXmlNode())
     return xn
Esempio n. 12
0
 def asXmlNode(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     return xp.xmlNode('<sensor id="%s"/>' % (self.id))