本文整理汇总了Python中brain.Brain.getDNA方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.getDNA方法的具体用法?Python Brain.getDNA怎么用?Python Brain.getDNA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.getDNA方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Creature
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import getDNA [as 别名]
#.........这里部分代码省略.........
self.velocity -= SPEED_DECAY
if self.velocity < 0:
self.velocity = 0
if self.angularVelocity < 0:
self.angularVelocity = min(0,
self.angularVelocity + ANGULAR_SPEED_DECAY)
elif self.angularVelocity > 0:
self.angularVelocity = max(0,
self.angularVelocity - ANGULAR_SPEED_DECAY)
return 1
def canEat(self, food):
if food.contains(self.mouthPos[0],self.mouthPos[1]):
return True
return False
def eat(self, food):
if food.size < self.EAT_RATE:
self.energy += food.size
food.size = 0
else:
food.size -= self.EAT_RATE
self.energy += self.EAT_RATE
if self.energy > self.MAX_ENERGY:
self.energy = self.MAX_ENERGY
def die(self):
self.brain.die()
def getDNA(self):
DNA = ""
a = (self.fBooster.force/self.MAX_BOOST_FORCE) * 255
DNA += brainUtils.intToBin(int(a),8)
a = (self.lTurn.force/self.MAX_TURN_FORCE) * 255
DNA += brainUtils.intToBin(int(a),8)
a = (self.ANTENNA_ANGLE/self.MAX_ANTENNA_ANGLE) * 255
DNA += brainUtils.intToBin(int(a),8)
a = (self.ANTENNA_LENGTH/self.MAX_ANTENNA_LENGTH) * 255
DNA += brainUtils.intToBin(int(a),8)
a = (self.fANTENNA_LENGTH/self.MAX_ANTENNA_LENGTH) * 255
DNA += brainUtils.intToBin(int(a),8)
DNA += self.brain.getDNA()
return DNA
def loadFromDNA(self, DNA):
self.fBooster.force = self.MAX_BOOST_FORCE * (brainUtils.binToInt(DNA[:8])/255.0)
self.fBooster.force = 3.0
DNA = DNA[8:]
turnSpeed = self.MAX_TURN_FORCE * (brainUtils.binToInt(DNA[:8])/255.0)
turnSpeed = 0.05
self.lTurn.force = turnSpeed
self.rTurn.force = -turnSpeed
DNA = DNA[8:]