In computer science, chess is the quintessential study of Game Trees and combinatorial search spaces.
From the starting position, White has $20$ possible first moves ($16$ pawn moves and $4$ knight moves). Black also has $20$ responses, creating $400$ distinct positions after just one full turn.
After four moves each, there are over 84 billion possible game variations — leading to Claude Shannon's famous estimate that chess has a game-tree complexity of approximately $10^{120}$ possible games (the Shannon Number, which exceeds the number of atoms in the observable universe)!
To study chess, grandmasters categorize games into standardized openings. With CodeByMath, you can store game move sequences in Lua arrays and watch them play out automatically.
Move the mouse over a dotted box for more information.
Move List Navigation: Click any move in the notation bar above the board to jump directly to that point in history!
Auto-Capture: When a piece moves to an occupied square, the captured piece is automatically removed from the board.
Now you try. Change the 6th move from "g8-f6" to "g7-g6" (pawn blocks the Queen). What happens when Black plays g6 instead?
Type your code here:
See your results here:
The code has ???? for the checkmating move. Replace ???? with "h5-f7", then click Run to watch Scholar's Mate unfold!
1. Observe how the Queen and Bishop coordinate to attack square f7.
2. Notice the capture on the 7th move: when the Queen moves to f7, the black pawn is captured.
3. Click on any move in the history bar (like d1-h5) to jump to that moment in the game!
Share your code
Show a friend, family member, or teacher what you've done!