Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
To implement the nearestbee method in the ThrowerAnt class according to the provided description you ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started