I Built Jupiter – A Machine Learning Based 2048 AI that Runs on the Web
Tags: javascript, machinelearning, ai
Published: 2020-09-13 03:16:00

---
title: "I Built Jupiter – A Machine Learning Based 2048 AI that Runs on the Web"
published: true
description: "Today I'm proud to release my online 2048 AI, Jupiter. Jupiter uses a machine learning method called the Monte Carlo Tree Search (MCTS) algorithm. I've released an article detailing the algorithm and implementation used in Jupiter: Using the Monte Carlo Tree Search (MCTS) Algorithm in an AI to Beat 2048 (and other games). Jupiter (formerly known as Jacob) started as a small AI project in January 2018. I got the idea of using Monte Carlo simulations and search trees as a method to play 2048 from this StackOverflow answer."
tags: #javascript, #ml, #ai
series: jupiter
---

Today I'm proud to release my online 2048 AI, [Jupiter](https://jupiter.xtrp.io/). Jupiter uses a machine learning method called the Monte Carlo Tree Search (MCTS) algorithm.

Check it out:

[![Jupiter Screenshot](https://raw.githubusercontent.com/xtrp/jupiter/master/demo-image.png)](https://jupiter.xtrp.io/)

## A Quick Preview of the AI

This is a snippet of some of what you'll see when you go to [the Jupiter website](https://jupiter.xtrp.io/).

![AI Preview Animated GIF](https://xtrp.io/api/content/static_files/jupiter-project-release-my-open-sourced-2048-ai-and-first-machine-learning-project/thumbnail.gif)

## Relevant Links

 - **[Jupiter (Website)](https://jupiter.xtrp.io/)** &mdash; run the AI on your browser and see realtime AI statistics.
 - **[Jupiter GitHub Repo and Source Code](https://github.com/xtrp/jupiter)** &mdash; check out the code and feel free to submit a PR or issue.

## More About This Project

Jupiter (formerly known as Jacob) started as a small AI project in January 2018. I got the idea of using Monte Carlo simulations and search trees as a method to play 2048 from [this StackOverflow answer](https://stackoverflow.com/a/23853848/10007107).

I wrote a basic clone of what was described in the answer and built on the idea with an interactive console and my own 2048 game implementation, in contrast to the existing open sourced game code used in other AI projects. At this time, Jupiter ran on the main JavaScript thread, and had decent performance and speed: it was able to run \~800 Monte Carlo simulations of possible games per second. Running the game at 200 simulations per move gave roughly 4 moves per second. This amount of simulations reaches the winning 2048 tile about 65-75% of the time.

In August 2020, I took a look at the project once again and noticed the potential to improve both performance and speed of the AI. I did some more research on Monte Carlo simulations and search trees, notably watching [a great lecture](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0002-introduction-to-computational-thinking-and-data-science-fall-2016/lecture-videos/lecture-6-monte-carlo-simulation/) by MIT Prof. Guttag in MIT's 6.0002 undergraduate course. In the one and a half years since I had first started the project, I'd also learned and used numerous modern JavaScript features, frameworks, and libraries. This put in me the unique position to use these new skills to extend this project vastly from performance, speed, bundle size, and design perspectives.

So, I spent time refactoring existing code and replacing older algorithms with newer and more performant ones. In particular, I took advantage of modern JavaScript features like [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) to differ tasks to new threads and utilize concurrency capabilities. I also added Webpack to the project for the automated speed and bundle size optimizations built into many of its loaders. With new CSS and design skills I had learned over the past one and half years, I built a new design for the site, with a clearer console and mobile responsiveness. And finally, among many other features, I added "tile milestones" to let users know how fast the AI had reached certain tiles in the game.

With the numerous updates to the project in 2020, Jupiter was now able to run \~2650 simulations of possible games per second. Running the game at 200 simulations per move gave around 13 moves per second. This indicated that **performance had more than tripled** with the new updates. Moreover, a new addition to the code allowed for performance to grow and scale horizontally by adding Web Workers and threads as general computing speed increases over time.

All in all, the two year gap in which I learned invaluable frontend development and programming skills allowed me to improve the AI drastically in many areas while maintaining the original, extremely effective Monte Carlo based algorithm which stayed the same throughout the development process.

I hope you find this project interesting and take the time to check it out!

If you liked this post, consider following me on DEV.

Thanks for scrolling.

*&mdash; Gabriel Romualdo, September 12, 2020*