本文整理汇总了Python中brain.Brain.teach方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.teach方法的具体用法?Python Brain.teach怎么用?Python Brain.teach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.teach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ScarabBob
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import teach [as 别名]
class ScarabBob(Body):
def __init__(self,canvas,pos):
global icon
super(ScarabBob,self).__init__(canvas,pos)
self.name = "ScarabBob"
self.gl_shape.source='./icons/'+icon
Legs( self )
Mounth( self )
TouchSense( self )
try:
self.brain = pickle.load(open("./last_brain","r+"))
#self.brain.teach( int(b'010000',2), int(b'001111',2), int(b'10000',2), -50000000.0 ) #do not eat when is acid
except Exception:
self.brain = Brain( 6, 5, 1, 1, 0)
self.brain.teach( int(b'100000',2), int(b'001111',2), int(b'10000',2), 100000.0 ) #when is sweet eat
"""self.brain.teach( int(b'000001',2), int(b'110000',2), int(b'00001',2), 1000.0 ) #move to what you are touching
self.brain.teach( int(b'000010',2), int(b'110000',2), int(b'00010',2), 1000.0 )
self.brain.teach( int(b'000100',2), int(b'110000',2), int(b'00100',2), 1000.0 )
self.brain.teach( int(b'001000',2), int(b'110000',2), int(b'01000',2), 1000.0 )
self.brain.teach( int(b'001001',2), int(b'110000',2), int(b'00001',2), 1000.0 )
self.brain.teach( int(b'000101',2), int(b'110000',2), int(b'00001',2), 1000.0 )
self.brain.teach( int(b'000011',2), int(b'110000',2), int(b'00001',2), 1000.0 )
self.brain.teach( int(b'000110',2), int(b'110000',2), int(b'00010',2), 1000.0 )
self.brain.teach( int(b'001010',2), int(b'110000',2), int(b'00010',2), 1000.0 )
self.brain.teach( int(b'001100',2), int(b'110000',2), int(b'00100',2), 1000.0 )
self.brain.teach( int(b'000110',2), int(b'110000',2), int(b'00100',2), 1000.0 )
self.brain.teach( int(b'010000',2), int(b'001111',2), int(b'10000',2), -500000.0 ) #do not eat when is acid
self.brain.teach( int(b'010000',2), int(b'001110',2), int(b'00001',2), 1000.0 ) #walk away when acid
self.brain.teach( int(b'010000',2), int(b'001101',2), int(b'00010',2), 1000.0 ) #walk away when acid
self.brain.teach( int(b'010000',2), int(b'001011',2), int(b'00100',2), 1000.0 ) #walk away when acid
self.brain.teach( int(b'010000',2), int(b'000111',2), int(b'01000',2), 1000.0 ) #walk away when acid
self.brain.teach( int(b'000001',2), int(b'111110',2), int(b'00001',2), 500.0 )
self.brain.teach( int(b'000010',2), int(b'111101',2), int(b'00010',2), 500.0 )
self.brain.teach( int(b'000100',2), int(b'111011',2), int(b'00100',2), 500.0 )
self.brain.teach( int(b'001000',2), int(b'110111',2), int(b'01000',2), 500.0 )"""
def __del__(self):
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>saving brain")
pickle.dump(self.brain,open("./last_brain","w"))
def clock(self,modeler):
super(ScarabBob,self).clock(modeler)
inputs = (self.touch_sense.touch_state + (self.mounth.sense_status << 4)) & int(b'111111',2)
outs = self.brain.activateInput( inputs )
chkwalk = (outs&1) + (outs&2)>>1 + (outs&4)>>2 + (outs&8)>>3
if chkwalk <= 1:
if outs&1:
self.walk_right()
if outs&2:
self.walk_up()
if outs&4:
self.walk_left()
if outs&8:
self.walk_down()
if outs&16:
#print(">>>>>>>>>>>>>>>>>>>>>>>>>>>EAT<<<<<<<<<<<<<<<<<<<<<<<<<<<")
self.eat()
lbli = bin(inputs)
lbli = lbli.zfill(6)
lblo = bin(outs)
lblo = lblo.zfill(5)
self.name = "in: " + lbli + "\nout:" + lblo# + "\n" + self.info_lbl.text
self.info_lbl.text = self.name + '\nx: ' + str(self.pos_x) + '\ny: ' + str(self.pos_y) + '\npower: ' + str(self.power)
def is_acid(self):
return True