Go to file
Chris Davoren a59cf70e9d Added more complex unit tests. 2023-10-07 18:12:26 +10:00
toyrobot Added unit tests and fixed rotate_right() incorrect check for 2023-10-07 18:05:45 +10:00
.gitignore Initial commit of files. 2023-09-27 09:07:09 +10:00
README.md Added README, command interpretion, and examples. 2023-10-07 17:07:44 +10:00
example_a.txt Added README, command interpretion, and examples. 2023-10-07 17:07:44 +10:00
example_b.txt Added README, command interpretion, and examples. 2023-10-07 17:07:44 +10:00
example_c.txt Added README, command interpretion, and examples. 2023-10-07 17:07:44 +10:00
example_d.txt Added README, command interpretion, and examples. 2023-10-07 17:07:44 +10:00
trexamples.py Added additional comments, removed redundant initializer code. 2023-10-07 17:26:17 +10:00
trtests.py Added more complex unit tests. 2023-10-07 18:12:26 +10:00

README.md

Toy Robot Simulator

Problem Statement

Initial problem description taken from https://github.com/xandeep/ToyRobot.

Create a library that can read in commands of the following form:

PLACE X,Y,DIRECTION 
MOVE 
LEFT 
RIGHT 
REPORT

The library allows for a simulation of a toy robot moving on a 6 x 6 square tabletop.

  1. There are no obstructions on the table surface.
  2. The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in this must be prevented, however further valid movement commands must still be allowed.
  3. PLACE will put the toy robot on the table in position X,Y and facing NORTH, SOUTH, EAST or WEST.
  4. (0,0) can be considered as the SOUTH WEST corner and (5,5) as the NORTH EAST corner.
  5. The first valid command to the robot is a PLACE command. After that, any sequence of commands may be issued, in any order, including another PLACE command. The library should discard all commands in the sequence until a valid PLACE command has been executed.
  6. The PLACE command should be discarded if it places the robot outside of the table surface.
  7. Once the robot is on the table, subsequent PLACE commands could leave out the direction and only provide the coordinates. When this happens, the robot moves to the new coordinates without changing the direction.
  8. MOVE will move the toy robot one unit forward in the direction it is currently facing.
  9. LEFT and RIGHT will rotate the robot 90 degrees in the specified direction without changing the position of the robot.
  10. REPORT will announce the X,Y and orientation of the robot.
  11. A robot that is not on the table can choose to ignore the MOVE, LEFT, RIGHT and REPORT commands.
  12. The library should discard all invalid commands and parameters.

Example Input and Output:

a)
PLACE 0,0,NORTH
MOVE
REPORT
Output: 0,1,NORTH
b)
PLACE 0,0,NORTH
LEFT
REPORT
Output: 0,0,WEST
c)
PLACE 1,2,EAST
MOVE
MOVE
LEFT
MOVE
REPORT
Output: 3,3,NORTH
d)
PLACE 1,2,EAST
MOVE
LEFT
MOVE
PLACE 3,1
MOVE
REPORT
Output: 3,2,NORTH