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!
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:
The code has ???? for the 8th move. Replace ???? with "g4-e5", then click Run to watch the knight gallop across the board!
1. Watch the knight leap across ranks and files in $\Delta x^2 + \Delta y^2 = 5$ vectors.
2. Notice how the square color strictly alternates between light and dark with each jump.
3. Use the playback controls to pause or step through the moves one at a time.
Share your code
Show a friend, family member, or teacher what you've done!