4.6 MurderBot
MurderBot
-
A
MurderBotis a kind ofStrategyLayerwith two additional abilities:public void stab(): place two beeperspublic void flee(): move one step
-
The
KillerStrategyis a kind ofStrategythat makes the robot it controlsstabthe first time the strategy is invoked (viadoStrat, which will calldoIt). Every subsequent time the robot is told todoStrat(), it shouldflee. -
Make sure the same
doStrat()call causes one stab or one flee each time. -
Test your
MurderBotwith 8 calls todoStrat(). -
Challenge yourself: this can be done without variables (except what is built into the StrategyLayer).
-
Advanced: use the techniques the Spy in Section 4.8 to cause the
stabaction to find another robot on the same corner as the MurderBot and turn it off.
ViciousMurderBot
Create a kind of MurderBot that places six beepers when it is told to stab, instead of just two.