Description

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:

  • e: move east (right) one position
  • w: move west (left) one position
  • n: move north (up) one position
  • s: move south (down) one position

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.