A small robot explores a two-dimensional word with mountains, gold, and other objects. The robot cannot escape the world or climb mountains. Being a good raider, it does pick up any gold it encounters. You are to write a simulator for the raider.
The raider's world is a grid 20 columns wide, 10 rows high. The following shows a sample world followed by initial coordinates for the robot and a series of instructions.
+--------------------+
| # |
| ** - |
| # # |
| |
| O |
| *# + # |
| |
| #### |
| ## |
| |
+--------------------+
1 1
ees
The dashes and vertical bars mark the edges of the world; the robot crashes if it attempts to leave. Pound signs (occasionally known as hashtags) mark mountains, asterisks mark gold, and other characters mark objects that have no value to the raider. The two numbers give the starting location as (x, y) values, where 0 0 is the upper left corner of the world and 19 9 is the lower right corner. The remaining text (which may be on more than one line) captures the list of commands:
Commands are written as "words" - a sequence of characters surrounded by whitespace. The robot and world state is printed after each sequence. Running the above example results in
Initial state: Robot at 1, 1 (0 gold)
Executing ees
Robot at 3, 2 (2 gold)
+--------------------+
| # |
| - |
| # R # |
| |
| O |
| *# + # |
| |
| #### |
| ## |
| |
+--------------------+
Robot has completed its task.
Note the robot picked the gold in row 1. Print an error message (and stop executing instructions) when the robot runs into a mountain or off the world. The above world followed by the input
4 5
seesw
results the output
Initial state: Robot at 4, 5 (1 gold)
Executing seesw
Error: robot with current status of Robot at 6, 7 (1 gold) broke while executing seesw
+--------------------+
| # |
| ** - |
| # # |
| |
| O |
| # + # |
| |
| ####R |
| ## |
| |
+--------------------+
Note the robot is shown at its last legal position.