Afterglowscreensavers

2048 AI Screensaver

2048 AI is a free screensaver that plays the sliding-tile game 2048 with an expectimax search, showing each move it weighs, the score and a session tally of games, 2048s reached and best tile. It is a heuristic player that sometimes loses, shows Game Over briefly and starts again. Press ESC to exit.

Live preview

Puzzle 2048 AI screensaver — An expectimax AI plays 2048, loses sometimes, and keeps score.

Press ESC to leave fullscreen. Settings are saved in your browser only.

How the Puzzle 2048 AI screensaver works

The game follows the real rules: tiles slide as far as they can, equal neighbours merge once per move, a 2 (90%) or 4 (10%) appears in a random empty cell after each move, and the game ends when no move changes the board. The score is the sum of merged tile values, and the AI keeps playing past 2048 until it can no longer move. The slide and the new-tile pop are animated; the board logic itself was cross-checked in tests against a separate lookup-table implementation over tens of thousands of random moves.

The AI is an expectimax search. At a move node it tries the four directions and keeps the best; at a chance node it averages over every empty cell and both new-tile values, weighted 90/10. The search depth is how many of its own moves it looks ahead (1 to 3). Leaves are scored with a row-table heuristic of the kind used in nneonneo's open-source 2048 AI: a bonus for empty cells and merge potential, and penalties for non-monotonic rows and columns and for a large sum of tile ranks.

The search is split into small jobs, one per root move and possible new tile, and runs for about three milliseconds per frame so the animation stays smooth. The panel highlights the direction currently being evaluated and shows bars for the running value of each move; the chosen move is outlined when the search finishes, and a direction that would not change the board is marked blocked.

Because it is a heuristic search and not a solver, it loses. When it does, a Game Over banner shows for a few seconds and a new game starts. The session tally counts games played, games that reached the 2048 tile, the best tile and the best score. The tally lives in the page and resets when the saver restarts.

About the game and the search

2048 was written by Italian developer Gabriele Cirulli over a weekend and released on 9 March 2014 under the MIT licence. It descends from the mobile games 1024 and Threes.

The heuristic described here follows the structure published in nneonneo's open-source 2048 AI on GitHub, which scores each row through a precomputed table, with weights for empty cells, merges, monotonicity and a tile-sum penalty. This saver recomputes those tables at start-up and uses a shallow search so that it can run in a browser alongside other savers; it does not match the strength of that project's deep search and makes no claim to.

Results in the copy above come from headless test runs of the saver's own engine, with 20 games for depths 1 and 2 and 6 games for depth 3. They are small samples, not benchmarks.

A worked example

Sliding left, the row 2, 2, 4, empty becomes 4, 4, empty, empty and scores 4: the two 2s merge, and the new 4 does not merge again in the same move. In headless test games of this engine, depth 1 reached 2048 in 0 of 20 games, depth 2 in 13 of 20, and depth 3 in 6 of 6; depth 3 also took the longest per move, about 7 milliseconds at worst on the test machine.

Settings & tips

Frequently asked questions

Does the AI always win?
No. At the default depth of 2 it reached 2048 in 13 of 20 headless test games, and at depth 1 in none. Deeper search lost less often in the tests (depth 3 won all 6 games), but no setting here is a guaranteed win.
What is expectimax?
A game-tree search for games with chance. It maximises over the player's moves and averages over the random outcomes, here the position and value of the next tile.
What does the heuristic reward?
Empty cells and pairs that can merge, and rows and columns whose tiles run in one direction. It penalises tiles that break that order and a large sum of tile ranks.
Why do the bars change while it thinks?
The search is spread over several frames. Each bar is the running average value of that direction over the new-tile cases evaluated so far, and it settles when the search ends.
Does it keep playing after 2048?
Yes. Reaching 2048 is counted once for the tally, then the AI carries on until the board locks up.
Is the tally saved?
No. It covers the current session of the saver only and resets when it restarts.
Who made 2048?
The game was written by Gabriele Cirulli and released as open source on 9 March 2014. This saver is an independent implementation and copies none of its code.

← All Arcade screensavers