当前位置: 首页>>代码示例>>Python>>正文


Python Brain.die方法代码示例

本文整理汇总了Python中brain.Brain.die方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.die方法的具体用法?Python Brain.die怎么用?Python Brain.die使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brain.Brain的用法示例。


在下文中一共展示了Brain.die方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Creature

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import die [as 别名]
class Creature(object):
    x = y = 0.0
    facing = 0.0 #In radians, 0 is facing east
    velocity = 0.0
    angularVelocity = 0.0 #positive is turning anticlockwise
    brain = None
    mouthPos = (0,0)
    age = 0
    EAT_RATE = 1
    MAX_ENERGY = 200
    energy = MAX_ENERGY
    ENERGY_USE_RATE = 0.07
    MAX_BOOST_FORCE = 5.0
    MAX_TURN_FORCE = 0.1
    MAX_ANTENNA_ANGLE = 90.0
    MAX_ANTENNA_LENGTH = 200

    ANTENNA_ANGLE = 40 #Degrees
    ANTENNA_LENGTH = 60

    def __init__(self, DNA=None, saveState=None):
        self.x = self.y = 0.0
        self.facing = 0.0 #In radians, 0 is facing east
        self.velocity = 0.0
        self.angularVelocity = 0.0 #positive is turning anticlockwise
        self.mouthPos = (0,0)
        self.energy = self.MAX_ENERGY

        self.pulser = Pulser()
        
        self.fAntenna = Antenna(self,0,10)
        self.lAntenna = Antenna(self,-5,7)
        self.rAntenna = Antenna(self,5,7)
        self.antennae = []
        
        self.lEye = Eye(self,10,8,500)
        self.rEye = Eye(self,-10,8,500)
        self.eyes = [self.lEye, self.rEye]

        self.fBooster = Booster(self)
        self.lTurn = AngularBooster(self, 0.05)
        self.rTurn = AngularBooster(self, -0.05)

        self.brain = Brain([self.pulser]+self.antennae+self.eyes,
                           5,
                           [self.lTurn, self.fBooster, self.rTurn])

        if saveState!=None:
            self.loadFromString(saveState)
        elif DNA!=None:
            self.loadFromDNA(DNA)

    def update(self):
        self.age += 1
        self.energy -= self.ENERGY_USE_RATE
        if self.energy < 0:
            self.energy = 0
            self.die()
            return 0
        
        self.brain.update()
        self.brain.update()
        
        cos = math.cos(self.facing)
        sin = math.sin(self.facing)

        dx = self.velocity * cos
        dy = - self.velocity * sin

        self.x += dx
        self.y += dy

        self.facing += self.angularVelocity
        if self.facing > math.pi:
            self.facing -= math.pi*2
        elif self.facing < -math.pi:
            self.facing += math.pi*2
        
        self.mouthPos = (self.x + 20*cos, self.y - 20*sin)

        l = self.ANTENNA_LENGTH
        a = math.radians(self.ANTENNA_ANGLE)
        
        self.fAntenna.x = self.x + l*cos
        self.fAntenna.y = self.y - l*sin

        cos2 = math.cos(self.facing+a)
        sin2 = math.sin(self.facing+a)
        self.lAntenna.x = self.x + l*cos2
        self.lAntenna.y = self.y - l*sin2

        cos2 = math.cos(self.facing-a)
        sin2 = math.sin(self.facing-a)
        self.rAntenna.x = self.x + l*cos2
        self.rAntenna.y = self.y - l*sin2

        self.velocity -= SPEED_DECAY
        if self.velocity < 0:
            self.velocity = 0

#.........这里部分代码省略.........
开发者ID:DiscoViking,项目名称:PyBrains,代码行数:103,代码来源:creature.py


注:本文中的brain.Brain.die方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。