Answered step by step
Verified Expert Solution
Link Copied!

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).

image
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

Step: 1

To implement the nearestbee method in the ThrowerAnt class according to the provided description you ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structural Analysis And Synthesis A Laboratory Course In Structural Geology

Authors: Stephen M. Rowland, Ernest M. Duebendorfer, Ilsa M. Schiefelbein

3rd Edition

1405116528,9781405116527

More Books

Students also viewed these Programming questions