Problem 12 (300pts): QueenAnt
Finally, implement the QueenAnt
.
The queen is a waterproof ScubaThrower
that inspires her fellow ants through her bravery.
In addition to the standard ScubaThrower
action, the QueenAnt
doubles the damage of all the ants behind her each time she performs an action.
Once an ant's damage has been doubled, it is not doubled again for subsequent turns.
Note: The reflected damage of a
FireAnt
should not be doubled, only the extra damage it deals when its health is reduced to 0.
Class | Food Cost | Health | |
---|---|---|---|
![]() | QueenAnt | 7 | 1 |
However, with great power comes great responsibility.
The QueenAnt
is governed by three special rules:
- If the queen ever has its health reduced to 0, the ants lose.
You will need to override
Ant.reduce_health
inQueenAnt
and callants_lose()
in that case in order to signal to the simulator that the game is over. (The ants also still lose if any bee reaches the end of a tunnel.) - There can be only one queen.
A second queen cannot be constructed.
To check if an Ant can be constructed, we use the
Ant.construct()
class method to either construct an Ant if possible, or returnNone
if not. You will need to overrideAnt.construct
as a class method ofQueenAnt
in order to add this check. To keep track of whether a queen has already been created, you can use an instance variable added to the currentGameState
. - The queen cannot be removed.
Attempts to remove the queen should have no effect (but should not cause an error).
You will need to override
Ant.remove_from
inQueenAnt
to enforce this condition.
Hint 1: For doubling the damage of all ants behind her, you may fill out the
buff
method defined in theAnt
class. Thebuff
method can be used within the appropriateQueenAnt
instance method. To avoid doubling an ant's damage twice, mark the ants that have been double damaged in a way that persists across calls toQueenAnt.action
.Hint 2: When doubling the ants' damage, keep in mind that there can be more than one ant in a
Place
, such as if one ant is guarding another.Hint 3: Remember that
QueenAnt
'sreduce_health
method adds the additional task of callingants_lose
to the superclass'sreduce_health
method. How can we make sure we still do everything from the superclass's method without repeating code?Hint 4: Think about how you can call the
construct
method of the superclass ofQueenAnt
. Remember that you ultimately want to construct aQueenAnt
, not a regularAnt
or aScubaThrower
.Note: The
construct
method hascls
as an argument. This functions similar to how we useself
in instance methods. So when we call a class method, we do not need to call it withcls
as an argument. To read more about class methods. check out this online guide aboutcls
vs.self
.Hint 5: You can find each
Place
in a tunnel behind theQueenAnt
by starting at the ant'splace.exit
and then repeatedly following itsexit
. Theexit
of aPlace
at the end of a tunnel isNone
.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 12 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 12