Martian Robots is a Node.js program that helps us to model the Mars' surface and tell us how robots will be able to move according to instructions given by operators from Earth.
The main target of this program is to determine sequence of robot positions in the grid and report the final position of each robot
First of all we assume that Mars can be modelled by a rectangular and bounded grid and if a robot moves off a edge of the grid this is lost forever. Moreover if a robot is lost this one leave a "scent" that helps other robots to not fall at the same grid point. Then, if a robot will do the same action that make lost a robot previously, the robot will ignore this action and continue with its instructions.
For robots description, robot position consist of Cartesian coordinates and an orientation (north, west, east or south), and the actions it can do are:
- Turn 90 degrees to the left.
- Turn 90 degrees to the right.
- Moves forward one grid point in the current orientation direction maintaining the same orientation.
This actions are represented by a string of letters "L", "R" and "F" (turn left, turn right and move forward) given in the input next to the initial position of the robot. Besides, the actions' string cannot be larger than 99 instructions.
So the input we need for our program are:
- The size of the grid that describes Mars' surface.
- The starting positions of the robots in the grid.
- The actions that each robot will do.
Sample input:
5 3 (The upper-right coordinates of the grid)
1 1 E (Robot 1 position)
RFRFRFRF (Robot 1 actions)
3 2 N (Robot 2 position)
FRRFLLFFRRFLL (Robot 2 actions)
0 3 W (Robot 3 position)
LLFFFRFLFL (Robot 3 actions)
The output this program will show indicate the final grid position and orientation of each robot given in the input. Also, if a robot falls off the grid the word "LOST" is printed after the previous position and orientation.
Sample output:
1 1 E (Final position of robot 1)
3 3 N LOST (Position before robot 2's fall and word LOST)
4 2 N (Final position of robot 3)
First say that I use Docker to wrap and deploy this program for easy use. So the only thing you need in your computer to run this program is Docker. I leave here the official documentation for your help if you need it.
- Then when you have installed Docker, the first thing you need to do is download the program image. To do this, you need
to start a PowerShell terminal and type:
docker pull eduvilla97/martian-robots
- To check if you download the image you should type in your terminal:
docker images
- Then, we will run and get into a container of this image for using Martian Robots. For this we use the command:
docker run -it eduvilla97/martian-robots /bin/bash
- Now we are in the container and we can use the program, for this use:
node main.js
- Now just follow the instructions given and write the input for the program.
- Now, if you want to exit the container type:
exit
And now you are out of the container and this one is stopped.
I also wrote some unit test following the TDD mindset, these ones are in the folder "tests". You can also run them following the nexts steps:
-
Follow the steps 1-3 (included) of running instructions.
-
Move to the tests' folder using:
cd tests
- run the test using:
node grid.test.js (or)
node robot.test.js
If there is no message in the terminal that match the format of "Assertion failed: Problems in test...", it means that tests were successfully passed.
Thank you for your attention, and I hope you'll enjoy the program.