4.6 MurderBot

Review exercises for class design.

MurderBot

  • A MurderBot is a kind of StrategyLayer with two additional abilities:

    • public void stab(): place two beepers
    • public void flee(): move one step
  • The KillerStrategy is a kind of Strategy that makes the robot it controls stab the first time the strategy is invoked (via doStrat, which will call doIt). Every subsequent time the robot is told to doStrat(), it should flee.

  • Make sure the same doStrat() call causes one stab or one flee each time.

  • Test your MurderBot with 8 calls to doStrat().

  • 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.

Last modified August 18, 2023: 2022-2023 End State (7352e87)