KNIGHT'S TOUR
A CHESS PUZZLE, SEARCHED LIVE

Watch a knight visit every square once.

Pick a search method and a starting square, then watch it work: every jump, every dead end, every step back. Compare how much work each method does, and copy any tour straight into a spreadsheet.

THE RACE

Same board, same start, same pace. Who finishes?

Pick up to six methods and press Start. The fastest way to see how differently they work, before the step by step lab below.

Entrants 5 of 6 max
From (1, 1) on 8×8. Tap any board to move the start.
Dad's best methodbacktracking, moves 1 to 8
♞︎
Steps
0
Back-tracks
0
Squares
1/64
Backtracking + pruningskips dead branches
♞︎
Steps
0
Back-tracks
0
Squares
1/64
Warnsdorffgreedy
♞︎
Steps
0
Back-tracks
0
Squares
1/64
Warnsdorff + backtrackinggreedy, then recover
♞︎
Steps
0
Back-tracks
0
Squares
1/64
Random restarts (best overall)roll again
♞︎
Steps
0
Restarts
0
Squares
1/64

Every lane gets the same number of steps per second, so the order they finish in is the order of how much work they need. “Best overall” is measured: across all 238 starting squares that have a tour on 5×5, 6×6, 7×7, 8×8 and 10×10, random restarts found one from every square and never needed more than 191 steps. Try the trap square, a 5×5 board, or a random start.

THE LAB

Every decision, explained.

One method at a time, slowed down so you can see why each jump is chosen. Turn explanations off in the settings to run at full speed.

Ready1/64
Method

Warnsdorff picks the order, backtracking catches the rare dead end.

Advanced settings

The order moves are tried in, and the last word on any tie.

When two squares have the same number of onward moves.

Skip a jump that would leave a square no tour could reach.

Only count a tour that ends one jump from its start.

Used by shuffled order, random ties and restarts.

A ceiling so a hopeless search stops on its own.

ReadyTap a square to start thereSpace run → step R reset
8765432112345678155

Ready. The knight starts on (1, 1). Press Run, or Step to go one move at a time.

Steps
0
Back-tracks
0
Depth
1/64
Deepest
1/64
Tours
0
Time
0ms
The working
next = arg minc deg(c)

deg(c) is how many unvisited squares are one jump from c. Press Run and every decision is worked out here.

Search stacktree covered 0%
failed exploring to trydepth 1
Depth of the searchdashed line: full tour
As a spreadsheet
ABCDEFGHΣ
1
2
3
4
5
6
7
811
Σ1
YOUR TURN

Now try it by hand.

Put the knight down anywhere and tap your way round. Jumping at random, a knight on 8×8 gets stuck after 35 squares on average, and in 20,000 random tries never once finished. When you get stuck, the solver can finish from exactly where you are, or point to the move that made it impossible.

Tap any square to put the knight down.

Hint uses Warnsdorff's rule. Finish hands your squares to the solver, which keeps every one of them, and if no tour can be completed it finds the move that sealed it.

FOUR WAYS TO SEARCH

Same board, very different amounts of work.

Backtracking, from the original chat

Dad's best method

From each square, try move 1, then 2, up to 8. When none leads anywhere, step back one square and try that square's next move. It will find a tour if one exists, and it will prove there is none if not, but the order it tries things in has nothing to do with the board.

  • Complete, simple, every decision recorded
  • Leaves the corners for last, then pays for it
Greedy, 1823

Warnsdorff

Look at every square you could jump to and count how many onward moves each one has. Go to the one with the fewest. Awkward squares, corners and edges, get visited while they can still be reached.

  • Usually finishes in exactly one pass
  • Can strand itself: on 8×8 it fails from (2, 4) and (5, 3)
Best of both

Warnsdorff + backtracking

Backtracking decides what happens at a dead end. Warnsdorff decides the order moves are tried in. Most runs never back up at all, and the ones that would have failed now recover.

  • On 8×8, 62 of 64 starts finish in one pass
  • From (2, 4), recovering takes 6.1 million steps
Las Vegas

Random restarts (best overall)

Warnsdorff, with every tie settled by a seeded coin flip. If the knight strands itself, wipe the board and roll again. Each attempt is fast, and a fresh set of ties is usually all it takes.

  • At most 2 restarts from any 5×5, 7×7 or 10×10 start that has a tour
  • Gives up after a set number of attempts
Enumeration

Find many tours

When a tour is found, record it as one row, then carry on: back off the last square and look for the next. The export has three columns per square (x, y and the move number that arrived there), so 192 for an 8×8 board.

  • Each new tour is a few steps from the last
  • There are far too many to ever list them all
MEASURED HERE

Move order is everything.

Every number below came from the solver on this page, starting in the bottom-left corner. Set the same board and method above to watch it happen.

63jumps

Warnsdorff on 8×8. One jump per square after the first, no wrong turns.

375M+steps

Plain backtracking on 8×8, still without a tour after 30 seconds of searching.

78Msteps

Plain backtracking on 6×6 before its first tour. On 5×5 it takes 3,484.

32ksteps

To find 200 different 8×8 tours, with Warnsdorff choosing the order and backtracking doing the rest.

SETTINGS WORTH TRYING

Small rules, enormous differences.

All in Advanced settings in the lab. Every figure is from this page's solver, starting in the corner.

2,184×fewer steps

Prune dead ends

Plain backtracking on 6×6 takes 78 million steps. Skipping any jump that leaves a square unreachable cuts it to 35,789, and 7×7 to 306.

64/64starts

Roth's tie-break

Breaking Warnsdorff's ties by picking the square farthest from the centre finds an 8×8 tour from every start, with no going back at all.

4/64fail

Looking further can hurt

Breaking ties by looking one jump further sounds smarter. On 8×8 it strands the knight from four starts, twice as many as the plain rule.

66steps

Closed tours, pruned

Holding out for a closed 8×8 tour ran past 30 million steps. With pruning, which also guards the start's last free neighbour, it takes 66.

THE EIGHT MOVES

Two along, one across.

With (1, 1) in the bottom-left corner, a knight on (x, y) can reach up to eight squares. They are numbered here in the order backtracking tries them. Each is checked to stay on the board and to land on a square not yet visited.

Move12345678
x-1+2-1-2+1+1+2-2
y+2-1-2+1+2-2+1-1
12345678♞︎
WORTH KNOWING

Open and closed

A tour is closed when its last square is one knight's move from its first, so it could start again as a loop. The lab draws that final link when it happens, and marks closed tours in the list.

Why some starts are hopeless

Every knight move changes colour. On a 5×5 or 7×7 board there is one more square of the corner's colour than of the other, so a tour has to start and end on that colour. Start anywhere else and backtracking will search the whole tree to prove it.

How many tours are there

On 8×8, counting each route once whichever way round it runs: 13,267,364,410,532 closed tours, and about 19.6 quadrillion open ones. Listing 200 is the realistic goal.