Main menuGallery

Knight's tour

Knight's tour

Visit every square exactly once, moving only in (±1, ±2) jumps.

8 × 8 board
1 of 64 squares visited
Knight on (0, 0). Click a glowing square.
Drag to orbit · scroll or pinch to zoom · click a glowing square to jump · before your first jump, click any square to start there
Where the knight can go — the move vectors
Each button is a translation (dx, dy) from the knight's square. Two of one, one of the other — always (±1, ±2) or (±2, ±1). Greyed‑out vectors leave the board or land on a square you have already used.
Tour status
Pick a square to start from, then jump.
Euler path vs Hamiltonian path

Turn the board into a graph: every square is a vertex, and two squares are joined by an edge when one knight move links them. A knight's tour is a walk that uses every vertex exactly once — a Hamiltonian path. Bridges of Königsberg asks for a walk that uses every edge exactly once — an Euler path. They sound like twins. They are not.

Euler pathHamiltonian path
uses every…edge, oncevertex, once
testcount odd‑degree vertices: 0 or 2 ⇒ yesno such test is known
workone pass over the graphsearch, with backtracking
settled byEuler, 1736still open (NP‑complete)

So a question you can answer by counting sits next to a question that, in general, nobody can answer without searching. That gap is one of the famous unsolved problems of mathematics.

What's the maths?

Where's the maths? This is graph theory — the mathematics of dots joined by lines — wearing a chessboard as a disguise. Each square of the board is a point given by a coordinate pair (x, y), and a knight's move is a translation by the vector (±1, ±2) or (±2, ±1), so the eight jumps you see highlighted are just eight vectors added to the knight's current position. Draw a line between every pair of squares one knight move apart and the board becomes a network with n² points; the puzzle "visit every square exactly once" becomes "find a path through the network that uses every point exactly once". Mathematicians call that a Hamiltonian path, and finding one is famously hard — there is no formula, only clever searching. Along the way the board's two colours give a piece of pure reasoning: a knight always lands on the opposite colour, so the tour must alternate black, white, black, white… and on odd boards that alternation forces where a tour can begin. Coordinates, vectors, colouring and counting — four school ideas — between them decide a 300‑year‑old puzzle.

📚 On the Sec 1–4 syllabus
  • Sec 1 · N6 — 6.1 Cartesian coordinates (a square is a coordinate pair)
  • Sec 3/4 · G7 — 7.3 translation by a vector (a knight move is the vector (±1, ±2) or (±2, ±1))

Beyond the syllabus: Hamiltonian paths are enrichment.

The move as a vector. If the knight stands on (x, y), the squares it can reach are (x, y) + (dx, dy) for the eight vectors with {|dx|, |dy|} = {1, 2}. Every one of them has length √(1² + 2²) = √5, so the knight always jumps exactly √5 squares — the same distance, in eight different directions.

The colouring argument. Since dx + dy is always odd (1 + 2 = 3), every jump changes the colour of the square. A tour of an n × n board makes n² − 1 jumps and so the colours alternate all the way through. On an even board there are equally many of each colour and all is well. On an odd board — 5 × 5, say — there are 13 squares of the corner colour and only 12 of the other, so a tour must start and finish on the majority colour: on an odd board no tour can begin on a minority-colour square. Try starting a 5 × 5 tour on one of those squares and the app will tell you it is hopeless before you begin — not from searching, but from counting.

Closed tours. A tour is closed (or re‑entrant) if the last square is one knight move from the first, so the knight could go round and round for ever. The same colouring argument kills closed tours on every odd board: a closed tour is a loop of n² squares alternating in colour, which needs n² to be even. 6 × 6 and 8 × 8 have closed tours; 5 × 5 and 7 × 7 have none.

Warnsdorff's rule (1823). A greedy strategy: always jump to the square that has the fewest onward moves left. It deals with the awkward corners early, and on an 8 × 8 board it usually walks a whole tour without a single mistake. Switch the hint on and the number written on each glowing square is that count. It is a heuristic, not a theorem — it can still fail, so the auto‑tour keeps a backtracking search in reserve.

How big is the haystack? An 8 × 8 board has 26 534 728 821 064 closed directed tours. Yet nobody knows a quick way to decide whether an arbitrary graph has a Hamiltonian path — see the "Euler path vs Hamiltonian path" panel above.

Try this. Set the board to 5 × 5 and start from a corner — a tour exists, and Warnsdorff will find it. Now restart and click a square next to the corner to start there instead: the status box says no tour is possible, and colouring tells you why before any searching happens. Then go back to 8 × 8, tick "aim for a closed tour", and watch the knight finish one jump away from where it began.

Drag to orbit · scroll or pinch to zoom · click a glowing square (or a vector button) to jump · before your first jump, click any square to start there.