GithubHelp home page GithubHelp logo

leila-alderman / knight_moves Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 6 KB

Returns the simplest possible set of moves for a knight in a chess to move from any board position to another

Ruby 100.00%

knight_moves's Introduction

Knight Moves

This project creates a function that returns the simplest possible set of moves that a knight in chess can travel from one board position to another. In chess, a knight can move forward two squares and then to the side one square, which gives a knight the ability to eventually reach every square.

This project is part of the The Odin Project curriculum.

For example, given @knight.knight_moves(["C", 3], ["D", 3]), the program will return,

"You made it in 3 moves! Here's your path:
[C, 3]
[A, 2]
[C, 1]
[D, 3]"

My solution for this problem relies on the principles of breadth-first search of a binary search tree. This application limits the exponential number of leaves (move options) created in each layer of the tree of possible moves, meaning that the tree doesn't get unreasonably deep before finding a solution. In addition, I added in some optimization to limit the addition of new nodes to only those that create moves to spaces that have not yet been visited. This limits redundancy in the tree, increasing the algorithm's performance.

Development versions

  • Ruby 2.5.3
  • RSpec 3.8

Using this code

  1. Fork this repository on GitHub.
  2. Clone your forked reposity onto your local computer.
  3. To run the tests, you need to have rspec installed.
  • First, check to see if rspec is already installed by typing rspec --version into the command line.
  • If the response is similar to the following, then you already have rspec installed and can continue.
RSpec 3.8
 - rspec-core 3.8.0
 - rspec-expectations 3.8.2
 - rspec-mocks 3.8.0
 - rspec-support 3.8.0
  • If you do not see output similar to the above, then you need to install rspec by typing gem install rspec into the command line.
  • Now, run rspec --version again to ensure that it installed correctly.
  1. Usecd to move into the main directory and then run rspec to show the tests.

knight_moves's People

Contributors

leila-alderman 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.