Problem 4 (250pts): Short and Long Thrower

The ThrowerAnt is a great offensive unit, but it'd be nice to have a cheaper unit that can throw. Implement two subclasses of ThrowerAnt that are less costly but have constraints on the distance they can throw:

  • The LongThrower can only throw_at a Bee that is found after following at least 5 entrance transitions. It cannot hit Bees that are in the same Place as it or the first 4 Places in front of it. If there are two Bees, one too close to the LongThrower and the other within its range, the LongThrower should throw past the closer Bee and target the farther one, which is within its range.
  • The ShortThrower can only throw_at a Bee that is found after following at most 3 entrance transitions. It cannot throw at any bees further than 3 Places in front of it.

Neither of these specialized throwers can throw_at a Bee that is exactly 4 Places away.

ClassFood CostHealth
ShortThrower21
LongThrower21

A good way to approach the implementation to ShortThrower and LongThrower is to have it inherit the nearest_bee method from the base ThrowerAnt class. The logic of choosing which bee a thrower ant will attack is essentially the same, except the ShortThrower and LongThrower ants have maximum and minimum ranges, respectively.

To implement these behaviors, you will need to modify the nearest_bee method to reference min_range and max_range attributes, and only return a bee that is in range.

Make sure to give these min_range and max_range sensible defaults in ThrowerAnt that do not change its behavior. Then, implement the subclasses LongThrower and ShortThrower with appropriately constrained ranges and correct food costs.

Hint: float('inf') returns an infinite positive value represented as a float that can be compared with other numbers.

Don't forget to set the implemented class attribute of LongThrower and ShortThrower to True.

Note: Please make sure your attributes are called max_range and min_range rather than maximum_range and minimum_range or something. The tests directly reference the variable via this name.

Before

Before writing any code, read the instructions and test your understanding of the problem:

python ok -q 04 -u

After

After writing code, test your implementation (rerun the tests for 03 to make sure they still work):

python ok -q 03
python ok -q 04