Lesson goal: The Knight's Tour & Vector Geometry

Previous: The Eight Queens puzzle and combinatorics | Home | Next: Chess openings, game trees, and loops

In 1759, the great mathematician Leonhard Euler presented the first rigorous mathematical analysis of the Knight's Tour to the Berlin Academy of Sciences.

A knight in chess moves in a distinctive "L-shape": two squares along one axis and one square along the perpendicular axis.

The Mathematics of the Knight Move

Mathematically, if a knight is at coordinate $(x, y)$, its move vector $(\Delta x, \Delta y)$ must satisfy: $$\Delta x^2 + \Delta y^2 = 1^2 + 2^2 = 5$$ The Euclidean distance of any knight leap is always exactly $\sqrt{5} \approx 2.236$ squares!

There are exactly 8 possible displacement vectors: $$\{(\pm 1, \pm 2), (\pm 2, \pm 1)\}$$

The Parity Principle

Because $1 + 2 = 3$ is an odd number, every single knight move inverts square color:
  • A knight on a light square must land on a dark square.
  • A knight on a dark square must land on a light square!
A Knight's Tour is a sequence of knight moves that visits every square on the board exactly once. Below, we program an animated sequence of knight leaps across the board!
chess_board("empty")
chess_put("wN", "a1")

chess_move("a1-b3")

chess_move("b3-c5")
Move the mouse over a dotted box for more information.

  • Playback Speed: Use chess_speed(400) to control animation timing in milliseconds between moves.
  • Array Moves: You can store a sequence of squares in a Lua table and loop through them to generate fluid paths!

Now you try. Add two more moves to the knight's journey: from e5 to d3, and then from d3 to b2! Does the knight land on a light or dark square?

Type your code here:


See your results here: