Artificial Intelligence has crushed all human records in 2048. Here’s how the AI pulled it off.

By now, we’ve all heard of the addictive tile-mashing game called 2048. Last week, I picked up 2048 for the first time and — true to my nature — I started designing an AI to beat the game for me the following day. It didn’t take me long to find out that there’s already some pretty good AIs out there, so I picked up the best 2048 AI I could find and fired several instances of it to see what it could do. Much to my surprise, it not only beat 2048… it crushed every human record in 2048 that I could find.

Below is a video of the first 20 seconds of the AI hacking away at the game, mashing and merging tiles at superhuman speeds that we only wish we could match.

Like a multi-armed genius, the AI played 1,000 games of 2048 simultaneously without a hitch. Some games ended in a few minutes due to a series of unfortunate random tile spawns, while others nearly lasted 4 hours and reached scores previously thought impossible.

2048-ai-score-distribution

The worst instance achieved a score of 35,600, but even that instance managed to build the 2,048 tile and beat the game. Most instances ended with a score around 390,000 and a 16,384 tile, but the best instance built a 32,768 tile and stayed alive long enough to reach a score of 839,732.

As far as I know, this is the highest score achieved in 2048 without undos.

2048-ai-highest-tiles-reached

Perhaps even more impressive is how consistently the AI beats 2048. The AI reached the 2,048 tile — and even the 4,096 tile — in all 1,000 games, and reached the 16,384 tile in a large majority of them. In 1/3 of the games, the AI astonishingly reached the 32,768 tile, though it wasn’t able to make it much further past that. (Though it’s theoretically possible, if you’re lucky.)

2048-ai-moves-to-reach-tile

For the rest of this post, I’ll be looking at the game where the AI reached the high score of 839,732. In that instance, the AI beat the game in only 973 moves, which is about average for the AI.

What’s especially curious about the AI’s progression is that it tends to reach tile X in about (X / 2) moves. For example, the AI reached the 16,384 tile in about 8,000 moves. At that rate, the AI would theoretically reach the 131,072 tile (the theoretically largest tile) in about 65,500 moves — roughly 2x the number of moves it ended up lasting for — if the random tile spawns played out in its favor.

The AI’s 2048 strategy

To get a better understanding of how the AI managed to rack up such a high score, I analyzed its playing strategy on its highest-scoring game. Below, I’ll outline 4 useful playing tips that the AI adopted to beat 2048. Some of these tips are fairly well-known — and were even coded into the AI as heuristics — but I figured it’s good to cover the bases.

Following these tips will undoubtedly help you improve your game and — hopefully — beat 2048. Ultimately, however, your survival toward the end of the game relies heavily on the random tile spawns working out in your favor; one poorly placed tile can spell the doom of your game.

Tip #1: Keep your highest-value tile in one corner for the whole game

One of the earliest strategies that players discovered for beating 2048 was to keep your highest-value tile in one of the corners for the entire game and slowly build it up. Some writers even called this a major design flaw of 2048 because it tends to make the game (relatively) easy to beat.

2048-ai-1st-highest-tile-location

It’s no surprise, then, that the AI took advantage of this design flaw to beat 2048. In this game, the AI happened to choose the upper left corner, but all corners are equally viable. Pick one corner and stick to it.

Tip #2: Keep your highest-value tiles lined up

Another early strategy that 2048 players adopted was to maintain a row of monotonically increasing tiles as you build your main tile. I took a screenshot from my video above to demonstrate:

2048-ai-monotonic

Notice how the tiles are nicely lined up? The 64 is right next to the 32; the 32 is right next to the 16; and the 16 is right next to (what is about to become) the 8. When that line of 4s is combined into a 16, this configuration allows you to quickly compress the entire row into your next-highest tile and start again.

2048-ai-2nd-highest-tile-location

Unsurprisingly, the AI adopted this strategy as well. The AI chose the top row as its primary row and kept 2nd-highest-value tile on the board was consistently right next its highest-value tile…

2048-ai-3rd-highest-tile-location

… and kept the 3rd-highest-value tile right next to the 2nd-highest-value tile in the top row. And so on. You’ll also notice that the AI often had the 3rd-highest-value tile just under the highest-value tile as well, which I’m still trying to understand. Any thoughts?

Tip #3: Keep the squares occupied

Above, I mentioned that unfortunate random tile spawns can often spell the end of your game. One of the more interesting strategies that the AI seemed to adopt was to keep most of the squares occupied to reduce randomness and control where the tiles spawn.

2048-ai-num-tiles-on-board-over-time

For most of the game, the AI maintained 12-15 (out of 16) tiles on the board and avoided merging too many tiles at once. While risky, this strategy ensures that tiles will spawn where you want them on the board.

2048-ai-squares-occupied

In this game, the AI kept the bottom-right corner of the board open so the low-value tiles would spawn around there, which it would then merge with nearby low-value tiles and move up the chain.

If you choose a different corner, make sure to use the diagonally opposite corner as your “spawning ground.”

Tip #4: Maximize the number of possible merges on the board

One of the mistakes that newer 2048 players tend to make is to try to merge everything quickly and leave as many squares open as possible. While such a strategy makes intuitive sense — more open squares means you’re less likely to get gridlocked — focusing on immediately merging everything actually leads to shorter games.

2048-ai-num-possible-merges

In its best game, 2/3 of the moves the AI made resulted in 2+ possible tiles that could be merged. At the extreme, some moves resulted in 6+ possible tile merges, but of course not all those merges could be made at once.

Try playing a few games where you keep tiles lined up to merge — but don’t merge them until you have to — and see if you last longer than usual.

Have you beat this high score?

If you’ve beaten this high score in 2048 (with an AI or otherwise) without undos, please let me know in the comments below! I’d love to hear how this AI can be beaten.

Dr. Randy Olson is a Senior Data Scientist at the University of Pennsylvania, where he develops state-of-the-art machine learning algorithms with a focus on biomedical applications.

Posted in analysis, data visualization Tagged with: , , ,
  • Kyle

    I have found it useful to keep the 3rd highest tile in the second row first spot so I can keep the 3rd space on the top row a high value. Then when I get the 3rd highest (Row 2 Column 1) equal to the 2nd highest tile the 3rd space on the top row becomes the 2nd highest value without having to start over. Hope that makes sense. I never made it past 100k, so I cant really compare to that AI haha

  • As someone with an interest in AI, but no practical knowledge yet on how to make one: Sweet! Now make it beat Super 2048!

  • Peter Hofman

    I cheated, and used undos, kept me busy 2 days to get to my score of about 1.05M.

    • @Aqeel_AT

      My friend used undo but got the highest possible score.

      • Peter Hofman

        and that was????

      • @Aqeel_AT

        not sure exactly, but I only have this picture of him which is old. He beat this score IIRC. The best score isn’t a lot great greater than this.

    • Ketan Mehta

      I too cheated, used lots of undos, even to get a desired 4 tile and finally got 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256,128, 64, 32,16, 8, 4 on the grid and a score of 3867416

  • Peter Hofman

    Undos are great when your touch screen acts as if you did something, but you didn’t intend to. That happens more often than real mistakes. I do follow a strategy though, which by looking at your screen shots could be partly the same as the AI one.
    Cool article though!

  • Jesper de Jong

    I’ve also seen an article somewhere (unfortunately can’t find it anymore…) about a variant of 2048 where the computer would deliberately try to put new tiles in the worst possible place, instead of placing them randomly. It made the game MUCH harder to play. I wonder how much harder that would make it for the AI.

    • That sounds evil. I’m pretty sure no one would get very far in that game. 🙂

    • acsmars

      Since that removes the randomness, the AI could be programmed to predicted that and quickly create the best possible game with those rules

      • dave

        But, if the computer knew where it was going, it would no longer be the worst possible square. 2048CEPTION!!!! lol

        • D.

          It’s just a minimizing function competing against a maximizing. It’s still the worst possible square. (Think about it like if the computer can choose a square worth [1 or 7], [2 or 6] or [3 or 4] points. The first computer will choose the [3 or 4] box because it knows the second computer is going to maximize out of the given choices.

          • doe

            It’s more complicated than that in a multi-round game because there is no possible way for either player to have enough computational power to know the true value of placing a tile somewhere – they have to rely on heuristics. Knowing where your opponent is going to place their tiles is going to allow your program to “read forward” a lot more dramatically and so might in fact improve its performance.

            • D.

              Right. My point was that a “worst possible square” actually does exist, even if players know what the other will choose.

            • Juan

              I disagree. Computers are now fast enough and 2048 is simple enough that both would have enough computational power to “play” optimally.

    • brekko

      Steve Mould discusses this program in his videos on youtube.

    • 2048 Windows Girls

      That’s the problem not only for AI vs. human comparisons, but also for bet-like or competition-like games. My diploma project is 2048 Game Girls Choice For Windows Desktop that targeted to solve this problem as well as many others. My 2048 game is completely free and open source. It has boards 4×4, 8×8, 16×16 and many useful benefits. Windows 10 ready.
      https://windows-2048.com
      https://win-2048.org

    • Cedric Mamo

      As it is, the game is one player versus a random element. One player is trying to maximize his score against rolls of the die, so to speak.

      In the more difficult version, the tile spawn isn’t random. It’s intentionally trying to mess you up. So it’s one player against another player, not a roll of the die. You have one player trying to maximize his score, and the opposing player trying to minimize it.

      The AI for the normal 2048 uses what’s called expectimax optimization, for this type of game. Where one player is trying to maximize his score and the “other player” (the random tile spawn) is playing randomly.

      The AI for the other more difficult 2048 variant would use what’s called minimax optimization where one player is trying to maximize the score, and the other is trying to minimize it.

      Now here’s the thing: both methods work in a similar way. They both look a certain number of moves ahead, look at the board at those positions and picks the best one. In the case of expectimax, the program computes the probability of arriving at that board position, because all random tile spawns are equally likely. However, in the other variant, not all tile spawns are equally likely. Ones which turn out bad for you are more likely than ones which result in a good position for you. That means that the program can try to predict where the opponent will spawn the tile (this prediction is impossible in normal 2048 because all tile spawns are equally likely and are random). The minimax algorithm can take this into account and in some cases deduce that certain moves are worse than others without having to even look at them. This type of optimization of minimax is called alpha-beta pruning. The program still gets the exact same result as minimax, but minimax with alpha-beta pruning looks at significantly less moves than the plain minimax. Meanwhile, again, expectimax has to look at all possible moves ll the time.

      So, while I haven’t tried it, I’d hazard a guess that the harder variant of 2048 would actually be easier for a computer, not harder. Because since it has to examine significantly less board positions, it can look more moves ahead as well, i.e. “see” further into the future of the game.

  • @Aqeel_AT

    For those who’s interested: this is what the ultimate game would look like. (I didn’t calculate the score but I guess it would be 8 digits.

    • Jonas Poffyn

      Interesting, you think you will get a 5th column at some point? xD

      • FTBC

        I wonder if he’s playing the same game we are playing.

      • You unlock the 5th column after acquiring the banana pendant.

    • knowbodies

      This is wrong as its a 4×4 grid not a 5×4 grid. The highest possible tile is 131,072. It’s unlikely anyone can get it without undo, but it’s theoretically possible.

      • frobnicator

        Yup, 131072 is the highest possible.

        The game occasionally throws a 4 rather than 2 for the tile. If your board was optimally filled when you are at 65536, and the numbers are all lined up sequentially, and the final space is filled with a 4 rather than a 2 (65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 4) it collapses to 131072.

        You cannot go higher on the 16-box grid. I’ve hit the 16K block a few times, but those stupid 4-drops tend to complicate things when you are in high numbers but with only one column of empty squares.

  • Marlon

    Now try it with Threes!, the original game that 2048 copied!

    • Andrew

      I’d love to see a Threes! AI. I find it a lot more difficult to play than 2048 😛

      • I think you’ll enjoy this video, then: https://www.youtube.com/watch?v=pmKtRxw_fsg

        • Andrew

          Oh wow, thanks! That’s really cool. I like how in-depth they went to talk about how they calculate maximum utility per move using the decision tree. The link is much appreciated!

  • Oliambert

    I wonder how it would perform in the quantum version of 2048 (http://uhyohyo.net/quantum2048/) and if it would find the same glitch as I did. My score was kinda insane, and I only stopped because I was bored.

  • frobnicator

    I followed the same pattern when I was addicted to the game, and could regularly get 4096 and occasional 8192 without undos, a few times getting 16K up in the corner. Highest in upper left, then snaking through down the leftmost column, up the second column, and back down the third. One key feature is you need to keep the rows filled so they don’t create holes. Sadly the stupid game occasionally throws in a 4 rather than a 2 that messes up the process.

  • Jerry Mcdurmott

    The real talent: Whoever wrote that algorithm

    • Chris Mannering

      Yes and that’s a point with its own point because algorithmic intelligence is much more what occupied what is now the AI seat, before AI showed up.
      Algorithmic intelligence is an invariant initial conditions and that’s exactly what AI has to be not, to be AI

  • George van den Driessche

    “What’s especially curious about the AI’s progression is that it tends to reach tile X in about (X / 2) moves.”

    Isn’t this necessarily the case, because every move a new tile appears and the tile adds 2 (or occasionally 4) to the total score on the board, which otherwise remains unchanged?

  • jasonlankow

    I read this after your marriage vs. divorce post, and at first glance I read this headline as a hypothetical news article from the year 2048, when AI will wipe out all recorded human history.

  • Mark Hilko

    It’s generally accepted to hire a smart writer via Internet. Everything you need you can find in uk essay writing services review, don’t hesitate to check it.

  • Pierre

    Very interesting. The score distribution seems to have two modes. Is that because the 500,000 score corresponds to the 32,768 threshold you need some luck to pass ? We can almost spot two other modes in the distribution, do they correspond to other power of 2 thresholds ?

    • Juan

      In a way, yes. Luck becomes a problem as there are more tiles on the board and that happens just before the 32,768 is created, and the 65,536 is almost created

  • 2048

    I’ll assume your AI has some way to calculate a score for a configuration and then checks a certain depth tree, and that finding the score function was the hardest part, so I’ll make some suggestions about that.

    1. Putting the second highest weight tile in a second corner (not diagonal to the one where the highest weight is), is almost as good as putting it directly near the highest weight. And its definitely better than putting it in distance 2.

    2. I find it quite beneficial to put a low tile (2 or 4) in the second corner, in certain parts of the game, say, when constructing 2048-equivalent tiles. It protects again “slippage” of the highest weight tile in the second row.

    (and I cannot beat your AI: my best is 16384+8192).

  • I’ve just done a 79,456 score, featuring a 4096, 2048, 1024, 512 and double 128. I had it pretty clean until the last few moves. I’ve never used undos.

    The don’t merge strategy sounds interesting. The thing is that I play very fast, so I often make mistakes. I try to never press key up, but sometimes I block all rows and get stuck.

  • DJ Toomey

    my high is 60732 with out any undos.

  • Alan Martin

    This is interesting. I have played a phone version of the game called TileUp where I can almost reach your AI’s median. There are no take backs and equal spawning of 2s and 4s, which I think makes a difference. I think that for analysis of what AI does well, you have to look at critical hurdles when the board is full of large numbers or to put another way, just before you make a big tile. Here the probability of failure is highest. Also it is interesting to understand how it avoids a 2×4 or 3×4 lockout or a tesselation of alternate 2s and 4s at the critical stages. Maybe understanding what it does (or ‘thinks’) at these ‘hurdles’ can help improve the AI.

  • justraley

    This will be my new personal high score (with undo)

  • Aimee Zemanek

    18 months without losing or starting over

  • Roger Rodriguez

    This is my hi score

  • Trenton Hulsey-Belt

    My High score is 1,152,280 so far i’m still going and i have the 65,536 tile as of this point.

  • Blythe Caracciolo

    I have a131072 tile with a 32768 tile. My score is 2547272. I don’t recall using the undo but I’ve also been playing the same game for 4 months.

  • Tamara Wanner

    I just finished my second round with a score of 797,176; highest tile is 32,768. I did not use undo in the three weeks it took. My strategy for this round was to “chase” the highest pair on the board, whether that was 2 512’s or 2 16’s. I ignored all other tiles and let them take care of themselves. I’m interested in trying the AI’s strategy…

  • Felix

    I love love these AIs, but it saddens me that none of them are better than this, not to say that they aren’t impressive mind you, but at the risk of flattering myself, I’ve been very close to hitting the 32k tile a number of times, though of course not as quickly or often. I am human after all, and during some 15k moves or more, you’re bound to make mistakes. And I’m convinced that I will succeed.
    I will say this however. Once I’ve hit that 32k, I will likely never play the game again, because there’s no chance in hell that I will be able to improve upon it.
    But an AI might. Sure there will be good and bad games, there is after all a random element, but still, as far as I know, no AI as of yet, have reached the next tile up, even after playing thousands or perhaps even millions of games, and that is disappointing.

  • David Brown

    I currently have the 32768 tile and score of 456,700 and counting….
    I’ve use 13 undos though.
    D

  • Emenike Mekese

    I just hit my first 32,768 and am so thrilled. Repping with the AIs
    #2048game

  • Gaurav Mehta

    https://uploads.disquscdn.com/images/8c9f536a94de356826f426079c49663c611664251976f23ebb1dd792a754809b.png

    I have a better score in this i have made 65536, below i am attachting the screen shot of the same

  • Fahmi Rosdiansyah Mahdani
  • RedFan2013

    I am on a 8×8 grid, but I currently have a 65,536 tile with a score of over 1.5 million.

  • Jean Daly

About this blog

This blog is my labor of love, and I've spent hundreds of hours working on the projects that you'll read about here. Generally, I write about data visualization and machine learning, and sometimes explore out-of-the-box projects at the intersection of the two. I hope you enjoy my projects as much as I have.

If you would like to use one of my graphs on your website or in a publication, please feel free to do so with appropriate attribution, but I would appreciate it if you email me first to let me know.

Archives

Subscribe

Enter your email address to subscribe to this blog and receive notifications of new posts by email.