classThrowerAnt(Ant): """ThrowerAnt throws a leaf each turn at the nearest Bee in its range."""
name = 'Thrower' implemented = True damage = 1 # ADD/OVERRIDE CLASS ATTRIBUTES HERE upper_bound = float('inf') lower_bound = 0 food_cost = 3 defnearest_bee(self) -> Bee | None: """Return a random Bee from the nearest Place (excluding the Hive) that contains Bees and is reachable from the ThrowerAnt's Place by following entrances. D This method returns None if there is no such Bee (or none in range). """ distance = 0 ifnotself.place: returnNone# An Ant that is not in a Place has no nearest Bee # BEGIN Problem 3 and 4 new_place = self.place whilenot new_place.is_hive: ifself.lower_bound <= distance <= self.upper_bound: if new_place.bees: return random_bee(new_place.bees) new_place = new_place.entrance distance += 1 returnNone # END Problem 3 and 4