Question: How to implement this?def nearest_bee(self): Return the nearest Bee in a Place that is not the HIVE, connected to the ThrowerAnt's Place by following entrances.

How to implement this?def nearest_bee(self): """Return the nearest Bee in a Place that is not the HIVE, connected to the ThrowerAnt's Place by following entrances. This method returns None if there is no such Bee (or none in range).

Problem 3 (2 pt) In order for a Thrower Ant to throw

Problem 3 (2 pt) In order for a ThrowerAnt to throw a Leaf, it must know which bee to hit. The provided implementation of the nearest7bee method in the ThrowerAnt class only allows them to hit bees in the same Place . Yourjob is to fix it so that a ThrowerAnt will throw7at the nearest bee in front of it that is not still in the Hive . This includes bees that are in the same Place as a ThrowerAnt Hint: All Place 3 have an isihive attribute which is True when that place is the Hive. Change nearestibee so that it returns a random Bee from the nearest place that contains bees. Your implementation should follow this logic: 0 Start from the current Place of the ThrowerAnt. - For each place, return a random bee if there is any, and if not, inspect the place in front of it (stored as the current place's entrance). - If there is no bee to attack, return None. Hint The random_bee function provided in ants.py returns a random bee from a list of bees or None if the list is empty. Hint As a reminder, if there are no bees present at a Place , then the bees attribute of that Place instance will be an empty list. Hint Having trouble visualizing the test cases? Try drawing them out on paper! The sample diagram provided in Game Layout shows the first test case for this

Problem 3 (2 pt) In order for a Thrower Ant to throw a leaf, it must know which bee to hit. The provided implementation of the nearest_bee method in the Thrower Ant class only allows them to hit bees in the same Place. Your job is to fix it so that a Thrower Ant will throw_at the nearest bee in front of it that is not still in the Hive. This includes bees that are in the same Place as a Thrower Ant Hint: All Places have an is_hive attribute which is True when that place is the Hive. Change nearest_bee so that it returns a random Bee from the nearest place that contains bees. Your implementation should follow this logic: Start from the current Place of the Thrower Ant. For each place, return a random bee if there is any, and if not, inspect the place in front of it (stored as the current place's entrance ). If there is no bee to attack, return None. Hint: The random_bee function provided in ants.py returns a random bee from a list of bees or None if the list is empty. Hint. As a reminder, if there are no bees present at a Place, then the bees attribute of that Place instance will be an empty list. Hint. Having trouble visualizing the test cases? Try drawing them out on paper! The sample diagram provided in Game Layout shows the first test case for this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the nearestbee method in the ThrowerAnt class according to the provided description you ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!