defreduce_health(self, amount): # BEGIN Problem 5 place = self.place bees = place.bees[:] #非空说明还没死 Ant.reduce_health(self, amount) ifself.place: #找位置上的蜜蜂 for b in bees: Insect.reduce_health(b, amount) else: for b in bees: Insect.reduce_health(b, amount + self.damage)
defadd_to(self, place): if place.ant isNone: place.ant = self else: # BEGIN Problem 8b #之前的 if place.ant.is_container and place.ant.ant_contained isNone: ifself.is_container: assert place.ant isNone, 'Too many ants in {0}'.format(place) else: place.ant.store_ant(self) else: ifself.is_container: self.store_ant(place.ant) place.ant = self else: assert place.ant isNone, 'Too many ants in {0}'.format(place)
defadd_to(self, place): if place.ant isNone: place.ant = self else: # BEGIN Problem 8b #该地方的蚂蚁需要变成保护蚁 if place.ant.is_container : ifself.is_container: assert place.ant isNone, 'Too many ants in {0}'.format(place) elif place.ant.ant_contained isNone: place.ant.store_ant(self) else: assert place.ant isNone, 'Too many ants in {0}'.format(place) else: ifself.is_container: self.store_ant(place.ant) place.ant = self else: assert place.ant isNone, 'Too many ants in {0}'.format(place)