Chess-Math to Check-Mate: The Mathematics of Chess

James Ng
7 min readFeb 1, 2024

Introduction

The game of chess was adapted and born out of an Indian game called chaturanga before the 600s AD. By the end of 19th century, the rules of modern chess were standardized and universally accepted.

Indian game called “chaturanga”. Earliest form of modern chess.
Antiquated “chaturanga” board.

Here is a quick overview of the game:

  • Two (2) players, white and black. White always goes first.
  • Game board consists of 64 squares (8 rows by 8 columns). Learn how to set up the board here.
  • Starting game pieces per player: 8 pawns (♟), 2 rooks (♜), 2 knights (♞), 2 bishops (♝), 1 queen (♛), and 1 king (♚). Learn how each piece moves here.
  • The object of the game is to checkmate the opponent’s king, meaning to trap him so he cannot make any more moves to avoid capture.
Modern chessboard.
Modern chessboard.

Chess math

What has made chess one of the most popular strategy games for centuries is the mathematics behind the game. All the different combinations of possible moves influence the decision-making process, regarding trade-off and value of each piece.

Mathematicians, such as Euler and Gauss, and other renowned players have written literature regarding the optimal strategies to play the game, in what is known as chess theory. Chess theory divides the game into three phases: opening, middlegame, and endgame.

The Oxford Companion to Chess listed 1,327 named opening variations and sub-variations. The picture below shows a glimpse of the decision tree for just a few openings. A decision tree is a math model that uses a tree-like structure to represent different paths (decisions) and outcomes by using “branches”. Think of a family tree or a factor tree.

Can you try memorizing all of that? 👀

Decision tree of chess openings.
Decision tree of chess openings.

Each opening is a series of half-moves that each player makes, and results in a different board arrangement each time. A half-move, also known as a ply, refers to a move that one player makes. A move is when both players have moved a piece.

The table below shows the relationship between the number of half-moves and the number of possible games.

Number of half-moves compared to the number of possible games.

At the start of the game, white has 20 different options for the first ply (16 options for the 8 pawns + 4 options for the 2 knights). Then, black can respond with 20 different options for each move white makes. A quick calculation shows that there are 20 x 20 = 400 different variations of board positions!

Now, this is where the numbers blow up. In only 10 half-moves (5 full moves), there are 69,352,859,712,417 different possible games that can be played! Mind-blowing 🤯.

If the table above did not shake your socks off, then look at the graph of the plotted values created on Desmos. A line of best fit, in the form of an exponential function y=a(b)^x, a~0.201, b~28.4, was used as a model to represent this explosion of numbers.

Graph of an exponential line of best fit for the first 10 number of half-moves to the number of possible games.
Line of best fit (exponential) for first 10 half-moves and number of possible games.

Exercise: The average chess game is about 40 full moves, or 80 plies. Based on the line of best fit, try calculating the value y = (0.201)(28.4)⁸⁰. Hopefully, your calculator does not error out!

Shannon Number

In his paper “Programming a Computer for Playing Chess” written in 1950, American mathematician Claude Shannon made an estimate of 10¹²⁰ different game variations in chess. This number was calculated based on a typical game lasting about 40 moves — both white and black take a turn — and that each player can make on average 30 legal moves per turn (ply), approximately 30 x 30 = 900 (about 1000 = 10³) possible variations in one move.

Estimation: (10³)⁴⁰ = 10¹²⁰ different games

Let us attempt to put this number in some sort of context. According to scientists, the number of atoms in the observable universe is roughly 10⁸⁰. Shannon number is about 10¹²⁰ / 10⁸⁰ = 10⁴⁰ greater! 😵 What!?

Number of sensible chess games

The Shannon number accounts for all possible games, including ridiculous or non-sensical moves that lose games. This is why his number is extraordinary. A more sensible estimate is that a player has about three (3) reasonable moves for each ply (half-move), with the typical game lasting about 40 moves (80 plies). Each move will have about 3 x 3 = 9 (about 10) variations. Thus, the number of sensible games is about 10⁴⁰! Still a whopping number.

Picture of a man whose mind is boggled.

Artificial Intelligence (AI)

Dr. James Grime pointed out in his video that “if everyone in the world paired up and played a different game of chess every day to play all possible number of “sensible” games (10⁴⁰), then it will take trillions of years to play them all.”

Put in another way, all the games that have been played in the history of chess is only a fraction of all the possible games that can be played.

It is virtually impossible for any human to play or conceive of all the possible games in one’s lifetime. This is where artificial intelligence (AI) comes into the scene. AI supercomputers were designed to perform complex calculations and data processing tasks on large amounts of data at high speeds — perfect for something like learning chess.

In 1996, the world champion of chess Garry Kasparov faced off against IBM’s Deep Blue (AI) computer and won 4–2 in six games. After some upgrades in 1997, Deep Blue defeated Kasparov in a rematch, 3.5–2.5 (won 2 games, tied 3 games). This marked the first time a computer has defeated a world champion under tournament conditions in a classical match — the dawn of a new era.

Garry Kasparov faces IBM’s Deep Blue (AI) computer in 1997.
Garry Kasparov vs. Deep Blue (AI) Computer

Here’s a simple overview of Deep Blue’s learning techniques:

  • Tree search 🌲🔎 — as discussed earlier with the “decision tree”, the computer searches through each board arrangement (state) and the available legal moves for that state.
Tree searching of different chessboard arrangements.
Sample state (board arrangement) from a tree search.
  • Evaluation function 📜💪a math function that takes a state as an input and returns a score (material value) as an output. For the player of interest, it considers all the pieces for both players and assigns a score for the given board arrangement. The higher the number, the greater the likelihood of winning.
Evaluation function for a single state in chess.
Evaluation function.
  • Minimax algorithm 📉📈a series of calculations that attempts to minimize the maximum possible “loss” from making a particular move, given board arrangement. The algorithm will look ahead, as far as the computing power allows, to make such a decision that allows the player of interest to choose the best possible move to increase his/her odds of winning.
  • Optimization ⚡⚡essential technique of cutting out (pruning in computer science lingo) repetitive calculations in a decision tree. For example, it does not make sense to do 123 x 321 again two minutes and twelve minutes later if the problem was just calculated. The computer can store the result of 39,483 and reference it for later use. This saves on computing power and processing times.
Optimization of a decision tree.
Optimization by pruning.

AI is perfect for handling the sheer amount of possible game variations, numbers, and logical decisions needed to play a game like chess, optimally. Its potential is limitless as computing power, data storage, and algorithms continue to improve each year.

Phew! Mind-boggling eh? This is just the mathematics of chess. And we have not moved a single piece on the board yet!

Summary

  • Claude Shannon estimated the game of chess to have about 10¹²⁰ different possible games, considering all possible legal moves (silly ones too 😅), and about 10⁴⁰ sensible games, considering reasonable (🧠) moves.
  • Deep Blue (AI) defeated world champion Garry Kasparov in 1997. It was trained in using learning techniques, such as tree search, evaluation function, minimax algorithm, and optimization.
  • AI will continue to get better and better at learning as technology continues to improve.

--

--

James Ng

Software engineer, math & physics educator, mentor