← All animations

♞ The Knight's Tour

A knight moves in an L: two squares one way, one square the other. The puzzle is ancient and deceptively hard — can the knight hop around an empty board so that it lands on every square exactly once? Try it by hand below and you'll almost certainly strand yourself in a corner. Then watch a single, almost suspiciously simple rule find a complete tour every time.

1. Try it yourself — visit every square once

The knight starts on the highlighted square. Its legal L-moves are ringed; click one to hop there. Visited squares go dark and can't be reused. Fill all 64 to win — but watch how quickly your options collapse. Most people get stuck in the teens or twenties.

Move 1 of 64 63 squares remaining

2. Warnsdorff's rule — always move to the most-constrained square

The trick (H. C. von Warnsdorff, 1823): from each square, look at every square you could jump to next, and count how many onward moves each of those would have — its "degree". Always go to the one with the fewest. Tend to the hardest-to-reach squares first and you rarely trap yourself. The numbers below show those degree counts; the board fills 1…N as the knight traces a full tour.

Ready

3. Why it works — a Hamiltonian path in disguise

Picture every square as a dot, and draw an edge between two dots whenever a knight can leap from one to the other. That's the knight's-move graph. A knight's tour is then exactly a Hamiltonian path — a walk that visits every vertex of a graph once and only once. If the tour also returns to its starting square it's a closed (re-entrant) tour, i.e. a Hamiltonian cycle; otherwise it's open.

Finding Hamiltonian paths is, in general, a famously hard (NP-complete) problem — there's no known fast, always-correct method. So why does the dead-simple greedy rule above almost always succeed? Warnsdorff's heuristic works because corner and edge squares have few knight connections; if you don't visit them early, they get cut off and become unreachable. By always stepping toward the most-constrained square, the knight services those fragile squares while it still can, and keeps the well-connected middle for later when it has nowhere urgent to be. It can occasionally fail and need a tie-break or a little backtracking — but on the 8×8 board it finds a complete tour with striking reliability.

Not every board cooperates. Small boards can have no tour at all: a 5×5 board has open tours but no closed one; a 6×6 has tours; a 4×4 has none whatsoever. The 8×8 chessboard has an astronomical number of them — well over 13 trillion directed open tours.

People have been entranced by this for centuries. The earliest known references go back over a thousand years to Indian and Islamic chess literature; in 1759 Leonhard Euler wrote a substantial paper analysing it, and it remains a favourite playground for graph theory, recreational mathematics, and search algorithms to this day.