The Knight's Tour is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once.
The first algorithm for completing the Knight's Tour was Warnsdorff's algorithm, first described in 1823 by H. C. Warnsdorff.
In the 20th century the Oulipo group of writers used it among many others. The most notable example is the Knight's Tour which sets the order of the chapters in Georges Perec's novel Life: A User's Manual.
It is not hard to show that when condition 1 is true a closed knight's tour is impossible.
Imagine a chessboard colored black and white in the manner that we are all familiar with (alternating). Whenever a knight moves it lands on the opposite color. If it is on white, it moves to black. If it is on black, it moves to white.
Since m and n are both odd, the number of white squares and black squares are different. For example, in a checkerboard there are 13 of one color and 12 of the other.
For a knight to have a closed tour it must visit the same number of white squares and black squares. But we have just seen that boards have a different number of white squares and black squares, therefore closed tours do not exist. Open tours may still exist.
Condition 2 states that when the shorter side is length 1, 2, or 4, no closed tour is possible.
It is easy to see why when m = 1 or 2 that no knight's tour is possible: the knight would not be able to reach every square (with the exception of the trivial case ).
It can be shown that a board cannot have a closed tour.
Start by assuming that a board has a closed knight's tour. Let us construct 2 sets of squares, and , containing one half of the squares on the board and containing the other half of the squares on the board. If we color this board with a checkerboard pattern, we can define as the set of white squares and as the set of black squares. As previously established, the knight must alternate between white and black ( and ).
Consider the figure on the right. Define as the set of green squares and as the set of red squares in the figure. There are an equal number of red squares as green squares. Note that from a square in the knight must next jump to a square in . And since the knight must visit every square, when the knight is on a square in must move to an next (otherwise the knight will need to make a repeat on an square as well, but this is impossible).
If we follow the knight we will find a contradiction.
It follows that set has the same elements as set , and set has the same elements as set . But this is obviously not true, as the red and green pattern shown above is not the same as a checkerboard pattern; the set of red squares is not the same as the set of black squares (or white, for that matter).
So our above assumption was false and there are no closed knight's tours for and board, for any n.
Condition 3 may be proved using casework. Attempting to construct a closed knight's tour on a 3 by 4, 3 by 6, or 3 by 8 will lead to definite failure.
3 by n boards with n not equal to 4, 6, or 8 can be shown to be possible by using a repeating pattern (i.e., induction).
Simply proving the above three conditions does not prove the theorem; it is still required to prove that all rectangular boards that do not fall in one of the above three categories have closed knight's tours.
The Knight's Tour problem also lends itself to being solved by a neural network implementation. The network is set up such that every legal knight's move is represented by a neuron, and each neuron is initialized randomly to be either "active" or "inactive" (output of 1 or 0), with 1 implying that the neuron is part of the final solution. Each neuron also has a state function (described below) which is initialized to 0.
When the network is allowed to run, each neuron can change its state and output based on the states and outputs of its neighbors (adjacent knight's moves) according to the following transition rules:
where represents discrete intervals of time, is the state of the neuron connecting square to square , is the output of the neuron from to , and is the set of neighbors of the neuron.
Although divergent cases are possible, the network should eventually converge, which occurs when no neuron changes its state from time to . When the network converges, a solution is found. The solution found by the network will be either a knight's tour, or a series of two or more independent knight's tours within the same board.