Skip to content

aleksandar-code/knights_travails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

Knights travails

Knights travails made with Ruby.

Assignment for the Ruby course of The Odin Project.

Specifications and details for the assignment can be found here.

Try here Knigths travails.

Features

This program finds the shortest path the knight can take to go from square A to square B.

The whole path is displayed with the number of required moves.

How to use

image

You can modify the bottom of the file "main.rb", with the command "board.knight_moves([3, 3], [0, 0])" [3, 3] corresponds to coordinates on the board, the coordinates start from 0 up to 7 for rows and columns, that is 64 squares in total like a class chess board.

Once you're in the replit you can just type "ruby main.rb" in the command line, or click on the green button Run.

ezgif com-gif-maker

Information

The only complex thing for me was explaining to the computer how to calculate the movement of the knight and to keep information about the path, getting the shortest path was easy.

I used a matrix and each of the 8 knight movements were in an array of numbers (near the bottom of the main.rb file), we have to move the knight on colums and rows at the same time.

Contact

@aleksandar_code

About

Assignment for the Ruby course of The Odin Project.

Topics

Resources

Stars

Watchers

Forks

Languages