Knight's Tour — Backtracking with Warnsdorff's Rule

The knight visits every square once. Each candidate shows its Warnsdorff degree (onward unvisited moves); the rule picks the lowest. Watch the path fill with order numbers and backtracking fire on dead ends.

step 0

Board — visit order & candidate degrees

visited (order #) knight here candidate (degree) chosen (min degree) backtrack

Search state

squares filled1
total squares36
moves made0
backtracks0
nodes expanded0
Press Step or Run. At each square we list legal unvisited moves, label each with its onward degree, and jump to the lowest. Dead ends trigger backtracking.

How to read this animation

The board is the knight graph drawn as a grid. The knight symbol ♞ marks the current square. Each candidate square shows a small orange number in its corner: that is its Warnsdorff degree — how many unvisited squares it could reach next.

On a score step, all candidates light up with their degrees. On a choose step, the minimum-degree candidate is outlined in green (ties go to the square farther from the center). On a move step, the knight jumps there and the square is stamped with its visit-order number. On a backtrack step, a failed branch flashes red and the search undoes the last move to try the next candidate.

The Search state panel tracks squares filled, moves made, backtracks, and nodes expanded. On a well-behaved board (try N = 6 or N = 8 from a corner), backtracks stay at 0 — Warnsdorff's first path completes the whole tour. Increase N or change the start to watch where the heuristic occasionally needs the backtracking safety net.

Tip: lower the Speed slider for a slow, readable walk; raise it to watch a large board fill quickly. Use Step to inspect a single decision at a time.

Why the lowest degree? A square with few onward moves is about to become a trap: every move you make elsewhere can only reduce its remaining exits, never add one. Visiting the most-constrained square first keeps the rest of the board flexible — that single idea is what turns an exponential search into a near-linear one.

Remember: this is a heuristic, not a guarantee. The backtracking fallback (the red flashes) is what makes the search always correct when the greedy choice stumbles.

Self-contained visualization. Move order uses Warnsdorff's rule (minimum onward degree first, ties broken toward the board edge) with a backtracking fallback. See junior.md, middle.md, and professional.md for the heuristic's intuition, tie-breaking, existence theorems, and why it carries no completeness guarantee.