Knight's Tour Applet


The Knight’s Tour In Chess a Knight moves in an L shape from its current position, either two cells vertical and one horizontal or two cells horizontal and one vertical. There is a maximum of 8 possible moves from any given position on the chess board. The problem is to find possible sequence of moves that allows the knight to visit every cell on the board once and only once and return to its initial cell.


Copyright 2004, Nasir Billoo. If you copy please include this copyright notice and the href

The Reset Button Resets the Board
The Step Button will take one step at a time, first tep is to identify the cells the knight can move to from its present position, The second step will move to the Knight to a square based on the algorithm
The Solve Animated button takes steps until the puzzle is solve, there is a 250 millisecond delay between each step.
The Solve Fast button will solve without the 250 millisecond delay.
The board size drop down will change the board size.
The Algorithm drop down will change the algorithm used to solve the puzzle.

Back Tracking Algorithm The obvious way to solve the Knights Tour problem is to use a back tracking algorithm. At each position, starting with the start position, a list of moves is selected; Knight is moved to the first position in that list. If the board is full then a tour was found, otherwise back tracking is used to go back to a position from which a choice of moves was available and the next move from the moves list is tried. Back tracking is achieved through recursion. Back tracking although an obvious solution is a very slow solution, because at each cell there can be a possible of 8 different moves; on an 8x8 board this can mean about 512 possible paths to try(Mathworld). Fortuantely there is help

Warnsdorf's heuristic A technique known as Warnsdorf's heuristic alleviates the problem of not reaching optimal conclusion. The heuristic, discovered by H. C. von Warnsdorf in 1823, is basically that from a list of available moves for the knight, the one leading to the fewest choices for moving on from there should be selected(Mathworld). Remarkably this algorithm works in linear time with respect to the number of cells on the chess board.