Problem 3 (200pts): Thrower Throws
In order for a ThrowerAnt
to attack, it must know which bee it should hit.
The provided implementation of the nearest_bee
method in the ThrowerAnt
class only allows them to hit bees in the same Place
.
Your job is to fix it so that a ThrowerAnt
will throw_at
the nearest bee in front of it that is not still in the Hive
.
Go back to Core Concepts to review the definition of Hive
.
Hint: All Places have an
is_hive
attribute which isTrue
when that place is theHive
.
The nearest_bee
method returns a random Bee
from the nearest place that contains bees.
Places are inspected in order by following their entrance
attributes.
- Start from the current
Place
of theThrowerAnt
. - For each place, return a random bee if there is any, or consider the next place that is stored as the current place's
entrance
. - If there is no bee to attack, return
None
.
Hint1: The
random_bee
function provided inants.py
returns a random bee from a list of bees or None if the list is empty.Hint2: 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.
Hint3: Having trouble visualizing the test cases? Try drawing them out on paper! The example diagram provided in Game Layout shows the first test case for this problem.
Before
Before writing any code, read the instructions and test your understanding of the problem:
python ok -q 03 -u
After
After writing code, test your implementation:
python ok -q 03
After implementing nearest_bee
, a ThrowerAnt
should be able to throw_at
a Bee
in front of it that is not still in the Hive
. Make sure that your ants do the right thing! To start a game with ten food (for easy testing):
python gui.py --food 10
# or
python ants_gui.py --food 10
Now you have finished Phase One !