Skip to content

Knight's move distance calculator module. Calculates the minimum number of moves for a knight to reach any position on a chessboard of arbitrary size in constant time.

License

Notifications You must be signed in to change notification settings

KDJDEV/knightMoveDistances

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knight's move distance calculator module. Calculates the minimum number of moves for a knight to reach any position on a chessboard of arbitrary size in constant time. Also returns an impossible code if a position is unreachable.

The solution is mathematical rather than relying on a BFS, so it runs in constant time. In other words, it should be faster than pretty much any algorithm out there. It has been tested on all possible boards up to 15x15 (including non-square boards), but it is theoretically justified and should work on all possible board sizes.

This problem was inspired by the following Gregory the Grasshopper problem on Kattis: https://open.kattis.com/problems/grasshopper

Example with 9x9 board with knight starting in the center:

Figure_1

Example with 25x25 board with knight starting in the top left:

Figure_2

About

Knight's move distance calculator module. Calculates the minimum number of moves for a knight to reach any position on a chessboard of arbitrary size in constant time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages