2048 - Solving 2048 with AI 🤖

Leveraging Monte-Carlo (MC) Move Evaluation

In today’s article, I am going to show you how to solve the famous 2048 game with Artificial Intelligence. You will learn the essentials behind the Monte-Carlo algorithm and at the end of this article, you will be able to create an agent that without any domain-specific knowledge beats average human scores in 2048.

AI gameplay

Table of Contents

If you are an iOS user, feel free to check my 2048 AI app that allows to both play 2048 and watch how AI solves it! It would definitely help you follow this article.

About 2048

2048 is a single-player sliding block puzzle game designed by Italian web developer Gabriele Cirulli. The game’s objective is to slide numbered tiles on a grid to combine them to create a tile with the number 2048. However, one can continue to play the game after reaching the goal, creating tiles with larger numbers.

“Candy Crush for math geeks”, Wall Street Journal

How to play?

Swipe ↑, →, ↓, or ← to move the tiles. Every move generates a new tile at a random unoccupied position.

Moving tiles with ← swipe

How to score?

Merge tiles with the same values. Every merged tile is added to your score.

Merging tiles with ↓ action

What’s the goal of the game?

To score as many points as possible.

Gameplay example

Before proceeding to the AI solver part, I would recommend you to play the game yourself. You will get more familiar with its rules and possibilites.

Monte-Carlo (MC)

One of the possible ways to solve the game of 2048 is to exploit the MC algorithm. Its biggest advantage is that it is a general-purpose solver, which means that it can yield output without any game specific input.

So how does it work?

Monte-Carlo is as a heuristic search algorithm that is based on applying the most promising moves.

But how can we determine which one of the available moves (↑, →, ↓, ←) is the most promising?

In order to do so, we can for every move: