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


Python Animal.teleport方法代码示例

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


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

示例1: insert_animal

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import teleport [as 别名]
 def insert_animal(self, genome):
     a = Animal(genome, PHEROMONES)
     a.teleport(
         random.randrange(0, self.width, 1),
         random.randrange(0, self.height, 1),
         random.uniform(0, 6.28)
     )
     self.animals.append(a)
     self.objects.append(Food(
         random.randrange(0, self.width, 1),
         random.randrange(0, self.height, 1),
         10
     ))
开发者ID:vberger,项目名称:evolving-project,代码行数:15,代码来源:__init__.py

示例2: update

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import teleport [as 别名]
    def update(self, timestep):
        
        self.next_food -= timestep
        if self.next_food <= 0.0:
            self.next_food = random.expovariate(1.0/FOOD_PERIOD)
            self.objects.append(Food(
                random.randrange(0, self.width, 1),
                random.randrange(0, self.height, 1),
                10
            ))

        self.next_poison -= timestep
        if self.next_poison <= 0.0:
            self.next_poison = random.expovariate(1.0/POISON_PERIOD)
            self.objects.append(Poison(
                random.randrange(0, self.width, 1),
                random.randrange(0, self.height, 1),
                10
            ))

        self.next_breed -= timestep
        if self.next_breed <= 0.0:
            self.next_breed = random.expovariate(1.0/BREEDING_PERIOD)
            self.animals.sort(key=lambda a: a.energy, reverse=True)
            # choose parents
            parentA = 0
            while random.uniform(0,1) >= BREEDING_FITNESS:
                parentA += 1
            if parentA >= len(self.animals):
                parentA = len(self.animals) - 1
            parentB = 0
            while random.uniform(0,1) >= BREEDING_FITNESS:
                parentB += 1
            if parentB >= len(self.animals):
                parentB = len(self.animals) - 1
            # breed
            self.new_genomes.append(self.pool.apply_async(
                breed,
                (self.animals[parentA].brain.genome, self.animals[parentB].brain.genome)
            ))

        if len(self.new_genomes) > 0 and self.new_genomes[0].ready():
            new_genome = self.new_genomes.pop(0)
            child = Animal(new_genome.get(), PHEROMONES)
            child.teleport(
                random.randrange(0, self.width, 1),
                random.randrange(0, self.height, 1),
                random.uniform(0, 6.28)
            )
            self.animals.append(child)

        result = list(zip(*(a for a in self.pool.starmap(update_animal,
            ((a, self.pheromones, timestep, self.width, self.height) for a in self.animals)
        ))))
        self.animals = [ a for a in result[0] if a.energy > 0 ]
        for fl in result[1]:
            self.pheromones.extend(fl)

        for f in self.objects:
            f.update(self.animals, self.pheromones, timestep)

        for p in self.predators:
            p.update(self.animals, self.pheromones, timestep, self.width, self.height)

        for f in self.pheromones:
            f.tick(timestep)

        # remove finished foods
        self.objects = [ f for f in self.objects if f.amount > 0.0 ]
        # remove vanished pheromones
        self.pheromones = [ f for f in self.pheromones if f.power() > 0.1 ]
开发者ID:vberger,项目名称:evolving-project,代码行数:73,代码来源:__init__.py


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