GenerateRandomSearch

Knight's Tour Generator

A knight's tour is a route that lands on every square of the board exactly once, moving only as a knight moves. It is one of the oldest problems in recreational mathematics and a genuinely hard one to do by hand, because a knight that wanders into the middle early tends to strand itself in a corner with nowhere legal left to go. Warnsdorff's rule avoids that with a single idea: always move to the square with the fewest onward options.

What this generator does

Finds a knight's tour with Warnsdorff's rule, breaking ties at random so the same board can yield different tours, and reports whether the result is closed — able to return to its starting square in one more move. The finished path is then re-checked square by square rather than trusted.

How to use this tool

  1. Choose a board size and generate a tour.
  2. Follow the numbers from 1 upwards — each is a knight's move from the last.
  3. Check whether the tour is closed: can the knight jump from the final square back to the first?
  4. Try it yourself on a smaller board first, and see how quickly a knight strands itself.

Understanding the controls

Board size
Between 5 and 8 squares a side. No tour exists on a 3x3 board, and 4x4 has none either, which is why the range starts at 5.
Show every step
Lists the squares in visiting order in algebraic notation, for following along on a real board.
Seed
Any word reproduces the same starting square and the same tour, so one can be set and checked later.

Common use cases

  • Chess teaching, for building a feel for how the knight actually moves
  • A worked example of Warnsdorff's rule and greedy heuristics generally
  • Demonstrating a Hamiltonian path on a graph people can picture
  • Test instances for a tour-finding implementation
  • Setting the same tour twice from a seed

How this generator works

Warnsdorff's rule moves to whichever reachable square currently has the fewest onward moves of its own, which keeps the knight from leaving isolated squares behind. Ties are broken randomly so a board does not always produce the same tour. Validation ignores all of that: it confirms the path has exactly as many squares as the board, that none repeats, and that every consecutive pair really is a knight's move.

Randomness and fairness

The starting square and the tie-breaking are random; the tour itself is then computed and verified. A seed reproduces the same tour exactly and is therefore explicitly not cryptographically secure. Without a seed the browser's cryptographically secure generator is used.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • Square boards from 5x5 to 8x8 only.
  • Whether the tour comes out closed is not controllable — it is reported rather than requested.
  • Warnsdorff's rule occasionally fails and the search simply restarts from a new square.
  • Tours are not deduplicated between generations; the same one can appear twice.
  • Tours are not stored between visits; seed one you want again.

Privacy and your data

The tour is computed entirely in your browser. Nothing about the board or your seed is transmitted or kept.