Giter VIP home page Giter VIP logo

mars_rover's Introduction

MarsRover

In this directory, you'll find the files you need to be able to package up your Ruby library into a gem.

The program consists of two class lib/mars_rover/map.rb and lib/mars_rover/rover.rb.

The lib/mars_rover/map.rb class saves the state of the mars_rover map. It's max and min (x,y) co-ordinates. It also checks if the current position of rover is valid or not. Any other state or responsibility related to the map can be extended in this class.

The lib/mars_rover/rover.rb class is the class that represents the rover and its state such as current_postion and instructions. Each instruction from the instructions list is executed one by one sequentially. The rover is either rotated left, right or moved forward according to the instruction. This is done in execute! method. Also, for every unique instruction a method is created to peform that instruction. Any other state or responsibility related to the rover can be extended in this class.

The whole program is then run from the module method

MarsRover.run

in the lib/mars_rover.rb file.

Unit test of each class is placed in test/map_test.rb and test/rover_test.rb file. The intergration test of fully working program is in test/mars_rover_test.rb file.

To experiment with that code, run bin/console for an interactive prompt.

Installation

This program was built with Ruby 2.3.
Install bundle gem and run bundle install in working directory.

gem install bundle && bundle

Build and install the gem.

rake install

Usage

After the installation simply run the program with command:

marsrover

or you can execute the file directly:

ruby ./lib/mars_rover.rb

The program will read the input from STDIN and moves the mars rover according to given instruction string.

First line of input should be top right co-ordinate of mars map.

The bottom left is always assumed to be (0,0).

The second line should be the number of mars rover (test case) to be expected.

The second line is followed by the current postion of mars rover and the move instructions.

Allowed moves are:

R : Turns the direction of rover to right
L : Turns the direction of rover to left
M : Moves the rover one unit to current direction

For an example:

Test Input:
5 5
2
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
Expected Output:
1 3 N
5 1 E

Get the help message with:

marsrover -h

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bishwahang/mars_rover. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

mars_rover's People

Contributors

bishwahang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.