Problem EC (200pts): Debuffs
The staff will prioritize helping students with required questions. TAs will not offer helps for this question (but senior students may).
Implement two final thrower ants that do zero damage, but instead apply a temporary "status" on the action
method of a Bee
instance that they throw_at
.
This "status" lasts for a certain number of turns, after which it ceases to take effect.
We will be implementing two new ants that inherit from ThrowerAnt
.
SlowThrower
throws sticky syrup at a bee, slowing it for 3 turns. When a bee is slowed, it can only move on turns whengamestate.time
is even, and can do nothing otherwise. If a bee is hit by syrup while it is already slowed, it is slowed for an additional 3 turns.ScaryThrower
intimidates a nearby bee, causing it to back away instead of advancing. (If the bee is already right next to theHive
and cannot go back further, it should not move. To check if a bee is next to theHive
, you might find theis_hive
instance attribute ofPlace
s useful). Bees remain scared until they have tried to back away twice. Bees cannot try to back away if they are slowed andgamestate.time
is odd. Once a bee has been scared once, it can't be scared ever again.
Class | Food Cost | Health | |
---|---|---|---|
![]() | SlowThrower | 4 | 1 |
![]() | ScaryThrower | 6 | 1 |
In order to complete the implementations of these two ants, you will need to set their class attributes appropriately and implement throw_at
methods.
To make bees move slower or scared, you can add custom attributes to Bee
class and update Bee.action
.
Extra Challenge!
Can you complete this problem without modifying any code outside the
SlowThrower
class? That means you may not modify theBee.action
method directly.Hint 1: Functions are first-class members.
Hint 2: Assign
target.action
to a function that sometimes callsBee.action
. You can use an instance attribute to track how many more turns the bee will be slowed, and once the effect is over,Bee.action
should be called every turn.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q EC -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q EC
Make sure to test your code! Your code should be able to apply multiple statuses on a target; each new status applies to the current (possibly previously affected) action method of the bee.