Install & Use
Add the following code to your project's shard.yml under:
to use in production
- OR -
to use in development
I chose this one to learn and play a bit with Crystal language.
Since it is done in an earlier version of Crystal (0.25.1), language features could change.
Develop an api that moves a rover around on a grid.
- You are given the initial starting point (x,y) of a rover and the direction (N,S,E,W) it is facing.
- The rover receives a character array of commands.
- Implement commands that move the rover forward/backward (f,b).
- Implement commands that turn the rover left/right (l,r).
- Implement wrapping from one edge of the grid to another. (planets are spheres after all)
- Implement obstacle detection before each move to a new square. If a given sequence of commands encounters an obstacle,
the rover moves up to the last possible point and reports the obstacle.
The solution is a mixed paradigm approach of object oriented programming and functional programming with pure data structures.
Installation & Troubleshooting
Crystal 0.25.1 (2018-06-30)
Install crystal lang following instructions here :
It is an API of rover, take a look on the test to see how it looks.
Given it is an earlier version of crystal, IDEs as idea are not supporting it well yet.
I would recommend using atom.io with crystal packages.
crystal tool format src/
- Error handling: Crystal's way to do error handling is by raising and rescuing exceptions without typing methods,
could be improved with a using a simple wrapper or a monadic structure
- Mocking libraries: https://github.com/waterlink/mocks.cr is not working with crystal
0.25.1, so it was not possible to mock
- Fork it (https://github.com/your-github-user/kata-mars-rover/fork)
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request