The Mind-Blowing Math Behind Chess

William McNamara • June 5, 2021

The game you're playing has probably NEVER been played before.

When I was little me and my cousins would bond with our grandfather through chess. He was very good, and challenged us to think not just about the next move, but the one that came after. It's a lesson that's very valuable in the life of anyone fortunate to play this ages-old game. But as I got older, I thought about how formulaic it is. I know games like Tic-Tac-Toe and Connect Four have been solved so that if you go first you can win every time, surely somebody could do that with chess if they haven't already, right?

Well let's break it down.

In order to "solve" chess, you'd need to figure out a combination of moves that wins in every game. How many possible games of chess are there? In 1950 an American mathematician named Claude Shannon came up with a way to answer this question. Shannon estimated that there are on average about 30 legal moves from any position in the game of chess, then your opponent goes and has about 30 more. So combined that creates about 900 combinations for a given "ply" (chess terminology for a move and its response).

Shannon then estimated that a typical game consists of 40 plys, which means about 80 moves! So the equation is kind of simple then, 30 potential moves raised to the 80th power, which is a 10 with 120 zeroes after it possible games in chess, known respectfully as Shannon's Number.

This number is massive, billions of times greater than the number of atoms in the observable universe (10^80). Let's say one were to build a chess computer and asked it to consider all outcomes and tell us the best first move in chess. It would still take that computer over 10^100 years just to figure out the first move, by which time most physicists agree the universe will have long ended.

This opened up another question. How many moves into a game can I reasonably assume that this game has never been played before? To answer this question, we can part's of Professor Shannon's methodology. Let's build around a potential model where Pr(u) is the probability that you're playing a unique game for m number of moves that have been played such that:

In this case the function P(m) will represent the number of games played and T(m) will represent the potential number of games. This ration will be expressed as X and for all value of X less than threshold z we will consider the game unique.


Chess is about 500 years old. Let's assume that 1% of all the people who have lived since then have played a game of chess every other day for 50 years. That means around 10 trillion games have been played (10^12). For starters that means an unimaginably small percentage of the total playable games of chess have been played (over 100 zeroes after the decimal point). But that's when m gets up to 80. how about for the first few moves.


If we model out how many potential combinations we get of the first, let's say 10 moves, we get the following table.

m Theoretical Combos
1 30
2 900
3 27,000
4 810,000
5 24 million
6 729 million
7 22 billion

Next we have to model how many games have been played for each value of m. Lets use a standard normal distribution for this function such that:

For N we can use our previously calculated estimate of played games at 10^12. We can use Professor Shannon's mean number of moves at 80, and we can use a standard deviation of 20 moves. From this we can calculate the probability that your game is unique:

m Theoretical Combos P(Unique)
1 30 <1%
2 900 <1%
3 27,000 <1%
4 810,000 <1%
5 24 million <1%
6 729 million <1%
7 22 billion <1%

As you can see nearly all of of the 10 trillion games have been played have made it to move 7 so the likelihood that your game has been played is high. But what's interesting is the ballooning denominator. It'll hit that 10 trillion number soon. So what if we look at the next 7 moves?

m Theoretical Combos P(Unique)
8 656 billion <1%
9 20 trillion <1%
10 590 trillion 5%
11 17 quadrillion >99%
12 531 quadrillion >99%
13 15 quintillion >99%
14 478 quintillion >99%

By the time you get to move 10 there are 590 trillion possible games to have played, against 10 trillion played all time, so there's now a high likelihood that your game is unique. Once you take the 11th and 12th move of the game it is a virtual certainty that your game of chess has never been played before!


Now obviously this isn't entirely true, if you're playing at high levels of competitive chess you may know theoretical openings and defenses that extend well into the 11th and 12th moves. But probabilistically, games that reach that point have an extremely high likelihood of being unique.


I decided to test my statistics by using chess.com's analysis engine. The engine has over a billion stored games from its players and you can see how many times your specific game has been played, and what the most common next move is. I decided to play the most theoretically common sequence of moves, the Sicilian Defense, and see how far I got before it was something new. I got 36 moves in before the most common line of moves became something the engine had never seen before, so this was an extreme upper bound. When I went back and decided to go with even the second most common next move, it was only 12 moves before it was a unique game. Confirming that even slightly varying from the common theoretical line almost always puts a chess player in the realm of unique games by move 12.


So for all you non chess grandmasters out there - next time you're playing chess, and you're 15 moves in, stop to think for a moment that you're probably facing a specific problem that has never been seen before, and may well never be seen again! It kind of makes the moment more interesting.

By William McNamara March 19, 2023
Like many music enthusiasts, the most used app on my phone by far is Spotify. One of my favorite features is their daily or weekly curated playlists based on your listening tastes. Spotify users can get as many as six curated ‘Daily Mixes’ of 50 songs, as well as a ‘Discover Weekly’ of 30 songs updated every Monday. That’s more than 2k songs a Spotify user will be recommended in a given week. Assuming an everage of 3 minutes per song, even a dedicated user would find themselves spending more than 15 hours a day to listen to all of that content. That…wouldn’t be healthy. But Spotify’s recommendations are good! And I always feel like I’m losing something when these curated playlists expire before I can enjoy all or even most of the songs they contain. Or at least I did, until I found a way around it. In this articule, I’m going to take you through Spotify’s API and how you can solve this problem with some beginner to intermediate Python skills. Introduction to Spotify’s API Spotify has made several public APIs for developers to interact with their application. Some of the marketed use cases are exploring Spotify’s music catalogue, queuing songs, and creating playlists. You can credential yourself using this documentation guide . I’d walk you through it myself but I don’t work for Spotify and I want to get to the interesting stuff. In the remainder of this article I will be talking leveraging Spotipy , an open source library for python developers to access Spotify’s Web API. NOTE : At the time of writing, Spotipy’s active version was 2.22.1, later versions may not have all of the same functionality available.
By William McNamara August 1, 2022
Speech given at the University of Virginia on July 31st, 2022
By William McNamara March 6, 2022
Online gaming communities need to work harder to close the gap for their female users.
By William McNamara February 15, 2022
Hospitals hold the key to predicting how long a product will be on the shelf.
By William McNamara December 21, 2020
Sometimes it's better to build it yourself.
By William McNamara April 6, 2020
Learn what steps you can take to get started as a Salesforce professional.
By William McNamara August 8, 2017
Originally published on govloop.com
By William McNamara August 3, 2017
Originally published on govloop.com
By William McNamara July 25, 2017
Originally published on govloop.com
Show More
Share by: