Giter VIP home page Giter VIP logo

toy_rubot's Introduction

ToyRubot

This is an implementation of the Toy Robot challenge in Ruby. It comes with the added condition that there can be multiple named robots on the board at a given time.

Running the simulation

bundle exec bin/toy_rubot example_input.txt

Testing

from the project root, run the following:

bundle exec rspec

Approach

  • Opted to use small, simple objects given the constraints of the problem.

  • State is centralised on table objects. Based on the robots on the table at a given time, the table can determine if it is valid or not (no overlapping robots, none have crossed the edge of the table). The trade-off for this simplicity is that we end up checking robots that have not moved between valid commands. For our case this is not an issue, but as a general approach it would be problematic in performance-sensitive contexts.

  • All that's needed to return a new state of the table, is the current table along with the next instruction to be run

  • Decided against modelling robots as discrete message receivers as there seemed to be minimal clarity or benefit from it. Instead they are modelled as key-value pairs (name => position).

  • The main test ensures it works end-to-end with a given file, while permutations of individual commands can be tested in the unit tests.

  • The intruction object is intended to capture the name and command together.

  • With more time, there would be value in refactoring instructions, and how they interact with the table. Given that the logic to validate the table lives outside instructions, the coupling between the table and the instruction is unecessary. It would be better to separate these abstractions properly so that instructions only deal with the robot the new command applies to, and the action it needs to take.

toy_rubot's People

Contributors

cursande avatar

Watchers

 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.