本文整理汇总了Python中animal.Animal.birth_animal方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.birth_animal方法的具体用法?Python Animal.birth_animal怎么用?Python Animal.birth_animal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.birth_animal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: step_animals
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import birth_animal [as 别名]
def step_animals(self):
from animal import Animal
anim_to_remove = set() # dictionary cannot change size during iteration
# so we keep track of all the animals we have to
# remove at the end
anim_to_move = {} # mapping of animals : cell to be moved to
anim_killed = set() # keeps track of dead animals, so they're not moved
new_animals = {} # animals to be added, due to mating
for animal in self.animals:
if animal.last_step == self.world.steps:
continue
animal.last_step = self.world.steps
action = animal.act()
if animal.dead():
print '{} on cell ({},{}) died of {}'.format(
animal.get_name(), self.col, self.row, animal.death_cause)
anim_to_remove.add(animal)
continue
if type(action) is Move:
to_cell = self.get_relative_cell(action.direction)
if to_cell != self:
anim_to_remove.add(animal)
anim_to_move[animal] = to_cell
elif type(action) is Drink:
self.terrain.consume_resource(R.water)
elif type(action) is Eat:
if action.is_animal:
assert action.food in self.animals
action.food.be_eaten()
anim_to_remove.add(action.food)
anim_killed.add(action.food)
else:
self.terrain.consume_resource(action.food)
elif type(action) is Mate:
partner = action.partner
if (animal, partner) in new_animals or \
(partner, animal) in new_animals:
continue
else:
child = Animal.birth_animal(animal, partner)
new_animals[(animal, partner)] = child
elif type(action) is Sleep:
pass
for animal in anim_to_remove:
self.animals.remove(animal)
for animal,to_cell in anim_to_move.iteritems():
if animal not in anim_killed:
if to_cell:
to_cell.add_animal(animal)
for animal in new_animals.itervalues():
self.add_animal(animal)
self.world.animals.add(animal) # the world keeps track of all animals