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
FireAntshould 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_healthinQueenAntand 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 returnNoneif not. You will need to overrideAnt.constructas a class method ofQueenAntin 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_frominQueenAntto enforce this condition.
Hint1: Think about how you can call the
constructmethod of the superclass ofQueenAnt. Remember that you ultimately want to construct aQueenAnt, not a regularAntor aScubaThrower.Hint2: You can find each
Placein a tunnel behind theQueenAntby starting at the ant'splace.exitand then repeatedly following itsexit. Theexitof aPlaceat the end of a tunnel isNone.Hint3: To avoid doubling an ant's damage twice, mark the ants that have been buffed in some way, in a way that persists across calls to
QueenAnt.action.Hint4: When buffing 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.
Before
Before writing any code, read the instructions and test your understanding of the problem:
python ok -q 12 -u
After
After writing code, test your implementation:
python ok -q 12
