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 can speed the search - it identifies there is no solution with the current search if it finds an empty square which cannot be reached from any other empty square or, if Closed, if cannot return to the start 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.

Board

Start at (r,c) Closed Tour Puzzle

Speedup: Check for Impossible Warnsdorff Heuristic