DEV Community

Lucian (LKB)
Lucian (LKB)

Posted on • Originally published at lkforge.com

How an AI actually beats 2048 (expectimax, not an LLM)

Every number in this post comes from our own re-runnable 250-game self-play benchmark. Nothing here is estimated.

If you've ever asked "are there any AI tools that can actually beat 2048?", the answer is yes — and the interesting part is which kind of AI does it. It is not a language model. A 2048-solving AI is a small, deterministic search algorithm you can run in a browser tab with no network calls. Here is exactly how one works, and where it hits its ceiling.

Why not an LLM?

You could paste the board into a chat model and ask for a move. It will often give you a plausible one — and sometimes an illegal or losing one — because a language model predicts the next tokens of text, not the next move of a game tree. Winning a game of chance is a search problem, and we already have an exact algorithm for it.

Game-tree search A language model
How a move is chosen Search the tree, return a specific legal move Predict tokens; the "move" is whatever it writes
Determinism Same board → same move, every time Sampling is probabilistic
Latency Sub-millisecond, on your device An API round-trip
Cost / offline Free, offline, no key Hosted or paid API

The core idea: expectimax

2048 is a game against chance — you pick a direction, then the game drops a random tile (a 2 with 90% probability, a 4 with 10%) on a random empty square. The right tool is expectimax search, a tree that alternates two layer types:

  • On a max layer the AI tries all four moves and keeps the best.
  • On a chance layer it considers every square a new tile could land on and averages the outcomes, weighted by probability.

By looking several layers deep, it picks the move whose likely future is strongest — accounting for unlucky spawns instead of grabbing whatever looks good right now.

Why not minimax? Minimax assumes an adversary playing the worst tile against you. But 2048's tiles are random, not malicious. Averaging over outcomes (expectimax) models the real game; minimax would play far too defensively. This is the textbook split — minimax for chess, expectimax for games against nature.

The heuristic: scoring a board

Search needs a way to score a board it can't play all the way out. The whole evaluation is three terms:

score = positional + empties × 200000 + smoothness × 4000
Enter fullscreen mode Exit fullscreen mode
  • Positional (corner-snake) — each square has a fixed rank; a tile's value is multiplied by 4^rank. Because the weights grow as powers of four, one big tile in the corner dominates everything, so the search is rewarded for stacking value toward that corner in snake order.
  • Empty squares — every blank cell is worth a flat 200000. Empty space is what keeps future moves legal, so a nearly-full board scores as almost worthless no matter how large its tiles.
  • Smoothness — for each pair of neighbours, subtract |log2(a) − log2(b)|. Mergeable neighbours cost almost nothing; a 2 next to a 512 is punished. Jagged boards score lower.

How well does it actually play?

We ran the exact search code headless for 250 full games:

Who / what Top tile Notes
Theoretical maximum 131,072 Absolute ceiling on a 4×4 board
Best research AI (2025) 65,536 Reached ~8.4% of games; median score ~820,000
This browser solver 4,096 ~30% of games; reaches 2048 ~70% of the time
Most human players 2,048 The original win condition

So a simple expectimax solver clears the 2048 win condition in about 70% of games and pushes to 4096 in about 30% — and essentially never reaches 8192. The state-of-the-art research AIs (expectiminimax plus endgame tablebases) go two doublings higher, to 65,536, but even they hit that only ~8% of the time. The theoretical 131,072 ceiling is never reached in normal play.

Try it / reproduce it

You can watch this exact solver run by turning on Autoplay in the free browser game at lkforge.com/games/2048 — no install, no account, runs entirely on your device. The full heuristic breakdown and the benchmark methodology are in the original write-up.

The engine is also open source (MIT) if you want to read it, require() it, or run the benchmark yourself: github.com/lucian-devops/2048-ai-solver — and there's a live self-play demo that watches the AI play.

If you want to build your own: implement expectimax with a depth of 3–5, use the three-term heuristic above, and run a few hundred self-play games to measure your own reach rates. The whole thing fits in a couple hundred lines of JavaScript.

Top comments (0)