Knights Tour Problem

The puzzle is to try to move a Knight on a chess board using its normal moves (one or two rows and two or one columns) so that each square is visited once only. If the last square is a knight's move from the first, the tour is closed.

You select various board size and the start square as row,col.

Backtracking is used to try to find a solution, though this is aborted if it is taking too long. You may need to change the start square to find a solution, or use a speed up option.

If Closed is ticked then the program keeps looking for a closed tour. Note there is no closed tour if the board size is odd.

Check for Impossible identifies if there is no solution with the current search : if an empty square or, if closed, the start square, is not reachable from an empty square.

Warnsdorff's heuristic is much better. It looks at the possible moves and ranks them according to the fewest number of moves from each next position.

Press ShowMoves to see how it does it - using backtracking - where each move is shown - note this takes a long time! Use the slider to adjust the animation speed.

Toggle Route Option to see the tour as a series of lines, and for valid closed tours, Duplicate Closed to see the closed tour duplicated - split from original to other, then return.

If you select a Puzzle some of the knights are hidden and you interactively solve by clicking on a square and entering the number of the knight to go there.

Board

Start at (r,c) Closed Tour Puzzle

Speedup: Check for Impossible Warnsdorff Heuristic