Knights Tour Algorithm in Python

Here is the Knight’s tour algorithm implemented in Python. This is a very basic Brute Force algorithm – with no Algorithmic Optimization applied.

 

Solved it in 2 evenings about 4 hours of thinking and coding and some debugging.

Command Line

It takes 3 parameters

1st param – integer – size of the Grid ( always assumed it is a Square board )
2nd param – integer – starting location of the knight the x location
3rd param – integer – starting location of the knight the y location
( x, y ) start from 1 and the top left square is x = 1 and y = 2

The results are either
– No tour found
OR
an array of 2 Tuples ( x, y ) coordinates – which describe the Knight path move
from the starting location as specified in the input params

Code

https://github.com/palsumitpal/sumitpython/blob/master/KnightTourAgain.py

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s