Knight's tour
A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. If the knight ends on a square that is one knight's move from the beginning square, the tour is closed; otherwise, it is open.
The knight's tour problem is the mathematical problem of finding a knight's tour. Creating a program to find a knight's tour is a common problem given to computer science students. Variations of the knight's tour problem involve chessboards of different sizes than the usual, as well as irregular boards.
Theory
The knight's tour problem is an instance of the more general Hamiltonian path problem in graph theory. The problem of finding a closed knight's tour is similarly an instance of the Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight's tour problem can be solved in linear time.History
The earliest known reference to the knight's tour problem dates back to the 9th century AD. In Rudraṭa's Kavyalankara, a Sanskrit work on Poetics, the pattern of a knight's tour on a half-board has been presented as an elaborate poetic figure called the turagapadabandha or 'arrangement in the steps of a horse'. The same verse in four lines of eight syllables each can be read from left to right or by following the path of the knight on tour. Since the Indic writing systems used for Sanskrit are syllabic, each syllable can be thought of as representing a square on a chessboard. Rudrata's example is as follows:transliterated:
For example, the first line can be read from left to right or by moving from the first square to the second line, third syllable and then to 1.5 to 2.7 to 4.8 to 3.6 to 4.4 to 3.2.
The Sri Vaishnava poet and philosopher Vedanta Desika during 14th century in his 1,008-verse magnum opus praising Lord Ranganatha's divine sandals of Srirangam, i.e. Paduka Sahasram has composed two consecutive Sanskrit verses containing 32 letters each where the second verse can be derived from the first verse by performing Knight's tour on a board, starting from the top-left corner. The transliterated 19th verse is as follows:
sThi | rA | ga | sAm | sa | dhA | rA | dhyA |
vi | ha | thA | ka | tha | thA | ma | thA |
sa | thpA | dhu | kE | sa | rA | sA | mA |
ran | ga | rA | ja | pa | dha | nna | ya |
The 20th verse that can be obtained by performing Knight's tour on the above verse is as follows:
sThi thA sa ma ya rA ja thpA
ga tha rA mA dha kE ga vi |
dhu ran ha sAm sa nna thA dhA
sA dhyA thA pa ka rA sa rA ||
It is believed that Desika composed all 1008 verses in a single night as a challenge.
A tour reported in the fifth book of Bhagavantabaskaraby by Bhat Nilakantha, a cyclopedic work in Sanskrit on ritual, law and politics, written either about 1600 or about 1700 describes three knight's tours. The tours are not only reentrant but also symmetrical, and the verses are based on the same tour, starting from different squares. The work by Bhat Nilakantha is an extraordinary achievement being a fully symmetric closed tour, predating the work of Euler by at least 60 years.
One of the first mathematicians to investigate the knight's tour was Leonhard Euler. The first procedure for completing the knight's tour was Warnsdorff's rule, first described in 1823 by H. C. von 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.
The sixth game of the World Chess Championship 2010 between Viswanathan Anand and Veselin Topalov saw Anand making 13 consecutive knight moves ; online commentators jested that Anand was trying to solve the knight's tour problem during the game.
Existence
Schwenk proved that for any board with m ≤ n, a closed knight's tour is always possible unless one or more of these three conditions are met:- m and n are both odd
- m = 1, 2, or 4
- m = 3 and n = 4, 6, or 8.
Number of tours
On an board, there are exactly 26,534,728,821,064 directed closed tours. The number of undirected closed tours is half this number, since every tour can be traced in reverse. There are 9,862 undirected closed tours on a board.n | Number of directed tours on an n × n board |
1 | 1 |
2 | 0 |
3 | 0 |
4 | 0 |
5 | 1,728 |
6 | 6,637,920 |
7 | 165,575,218,320 |
8 | 19,591,828,170,979,904 |
Finding tours with computers
There are several ways to find a knight's tour on a given board with a computer. Some of these methods are algorithms while others are heuristics.Brute-force algorithms
A brute-force search for a knight's tour is impractical on all but the smallest boards. For example, there are approximately 4×1051 possible move sequences on an board, and it is well beyond the capacity of modern computers to perform operations on such a large set. However, the size of this number is not indicative of the difficulty of the problem, which can be solved "by using human insight and ingenuity... without much difficulty."[Divide-and-conquer algorithm]s
By dividing the board into smaller pieces, constructing tours on each piece, and patching the pieces together, one can construct tours on most rectangular boards in linear time – that is, in a time proportional to the number of squares on the board.Warnsdorff's rule
Warnsdorff's rule is a heuristic for finding a single knight's tour. The knight is moved so that it always proceeds to the square from which the knight will have the fewest onward moves. When calculating the number of onward moves for each candidate square, we do not count moves that revisit any square already visited. It is possible to have two or more choices for which the number of onward moves is equal; there are various methods for breaking such ties, including one devised by Pohl and another by Squirrel and Cull.This rule may also more generally be applied to any graph. In graph-theoretic terms, each move is made to the adjacent vertex with the least degree. Although the Hamiltonian path problem is NP-hard in general, on many graphs that occur in practice this heuristic is able to successfully locate a solution in linear time. The knight's tour is such a special case.
The heuristic was first described in "Des Rösselsprungs einfachste und allgemeinste Lösung" by H. C. von Warnsdorff in 1823.
A computer program that finds a knight's tour for any starting position using Warnsdorff's rule was written by Gordon Horsington and published in 1984 in the book Century/Acorn User Book of Computer Puzzles.
Neural network solutions
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", with 1 implying that the neuron is part of the solution. Each neuron also has a state function 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 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, either the network encodes a knight's tour or a series of two or more independent circuits within the same board.
Variants
Joust
Joust is a two-player abstract strategy board game that may be considered a two-player variant of the knight's tour. It may also be considered a chess variant. It uses a 8 x 8 checkered board, and two Chess knights as the only game pieces. Each player has one knight of a different color from the other player. The knights move as in the game of Chess, but the square it leaves becomes "burned", that is, it can no longer be moved upon. As the game progresses, less squares are available to be moved upon. The objective is to prevent your opponent's knight from performing a move on its turn.Gerry Quinn created a freeware version of the game and referred to the game as Joust. Quinn based it off an old Amiga Public Domain computer game, although it is unsure if that is the ultimate origin of the game, and if Amiga called it that. According to Quinn, in the Amiga variant, each player's knights start on the center of the board. In Quinn's variant, the knights start on a random square on opposite sides of the board.
Joust should not be confused with the 1982 videogame of the same name.
Game of Knights
An Amiga game called Game of Knights created by Charles N. Jacob may have been the game Quinn was referring to. It was a shareware game played on Amiga's Workbench. The game states that "Game of Knights works on all Amigas with Workbench 1.3 or higher". The game unfortunately does not mention when it was created or published, therefore it is unknown if it precedes Quinn's version. The knights however begin on opposite sides of the board, and not in the center of the board as explicitly mentioned by Quinn. There is also an option for knights to capture one another and thus win in alternative fashion. The game is also partly narrated in French, and perhaps originates in Quebec, Canada as suggested by the author's contact information on the About tab.Several other variants exist such as a misere version where if your knight cannot perform a legal move, then you win. The starting position may also be at a different part of the board such as the corners. Different sizes of boards may be used. Instead of knights, other Chess pieces may be used such as the King, Queen, Rook, or Bishop. Grenading may also be added, that is a player may choose to "burn" another square that has not been burned yet and is not currently occupied. Grenading may be limited to the type of Chess piece used in the game, for example, when playing with knights, a player may only grenade a non-burned square that is a knight's move away. Or players can agree upon grenading any non-burned square that is not occupied anywhere on the board. Players can also choose to decide if grenading should be allowed before or after a move is completed.