Knight's Tour Solver

Implementations and analysis of the Knight's Tour — Warnsdorff's heuristic, DFS backtracking, and a 3D generalization, with path visualizations across board sizes.

20241 min read#algorithms #python #optimization #data-viz
repo
Knight's Tour Solver cover

Overview

The Knight's Tour asks whether a knight can visit every square of a chessboard exactly once — an open tour ends anywhere, a closed tour returns to its start. This project collects several approaches to solving it, from a naive depth-first search to degree-based heuristics, alongside visualizations of the resulting paths.

Approach

A written guide (matrix overlays, degree heuristics, historical context) accompanies the code, and the work was presented as Hamiltonian Knight Tours (with Devin and Josh) — the full deck is below.

Tours, drawn

The path plots are the payoff — the same algorithm's character at three scales, then the jump to three dimensions.

Knight's tour on a 5×5 board with numbered move order
5×5 — every move numbered.
Knight's tour path on a 20×20 board
20×20 — Warnsdorff at speed.
Knight's tour path covering a 75×75 board
75×75 — 5,625 squares, one path.
3D knight's tour through a cubic lattice
The 3D generalization — a tour through a cubic lattice.
Knight's tour mapped onto a sphere
…and wrapped onto a sphere.

The presentation

Hamiltonian Knight Tours presentation title slide
Hamiltonian Knight Tours — the 23-slide deck: theory, heuristics, and the visualizations above. view full ↗

related

← back to tech