Back to Showcase

Knight's Tour

A knight must visit every square on the chessboard exactly once. Watch the algorithm solve it in real-time using Warnsdorff's heuristic.

Speed:Medium

Tour Type

Knight can end anywhere on the board

Progress

Squares visited1 / 64
Starting position(0, 0)

Options

Full Project Stats

Open tours found431,513
Closed tours found68,993
Search time~6 min
View Source Code

The Problem

The Knight's Tour is a classic chess puzzle: move a knight across an entire chessboard, visiting each square exactly once. On a standard 8×8 board, that's 64 squares to visit in a specific sequence.

There are two variants: Open tours where the knight can end anywhere, and Closed tours where the knight must end one move away from its starting position, forming a loop.

The Approach

Naive Backtracking

Try every possible move. When stuck, backtrack and try a different path. Works, but requires 10,000,000+ iterations for larger boards.

Warnsdorff's Heuristic

Always move to the square with the fewest onward moves. This simple rule dramatically reduces iterations needed, finding solutions almost instantly.

Results

BoardVariantTours FoundTime
8×8Open431,513315.92s
8×8Closed68,993405.73s
5×5Open1,728162.10s