4.6 MurderBot
MurderBot
-
A
MurderBot
is a kind ofStrategyLayer
with two additional abilities:public void stab()
: place two beeperspublic void flee()
: move one step
-
The
KillerStrategy
is a kind ofStrategy
that makes the robot it controlsstab
the 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
MurderBot
with 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
stab
action 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.