Toy Robot Code Challenge
You are free to set up locally in your own way (virtualenv
, venv
, pyenv
, docker
, etc.)
$ pip install -r requirements.txt
$ pip install -r dev-requirements.txt
$ pytest
$ python main.py
The application is a simulation of a toy robot moving on a square table top, of dimensions 5 units x 5 units. There are no other obstructions on the table surface. 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 the robot falling from the table must be prevented, however further valid movement commands must still be allowed.
Placing robot to the table specifying the initial coordinates.
PLACE X,Y,F
example:
PLACE 0,0,NORTH
Where:
X - horizontal position of the robot
Y - vertical position of the robot
F - facing position of the robot
Move the robot one unit forward in the direction it is currently facing.
MOVE
Rotate the robot -90 degrees without changing the position of the robot.
LEFT
Rotate the robot 90 degrees without changing the position of the robot.
RIGHT
Announce the X, Y and F of the robot.
REPORT
The game can run in three different ways.
You need to specify the file location. The file format should look like.
PLACE 0,0,NORTH
MOVE
REPORT
from main import GameRunner
game_runner = GameRunner()
game_runner.run_file("sample_input.txt")
from main import GameRunner
game_runner = GameRunner()
game_runner.run_string_commands([
"PLACE 0,0,NORTH",
"MOVE",
"RIGHT",
"MOVE",
"REPORT",
])
from main import GameRunner
from commands import (
MoveCommand,
PlaceCommand,
ReportCommand,
RightCommand,
)
game_runner = GameRunner()
game_runner.run_commands([
PlaceCommand(1, 1, Faces.SOUTH),
MoveCommand(),
RightCommand(),
MoveCommand(),
ReportCommand(),
])