Twos

Slide the tiles, merge equal numbers, reach 2048. A trained model plays the same tiles beside you.

You

Score0
Best0

Use the arrow keys or WASD.Swipe to move.

AI

Score0
Show what it's thinking

How it works

The rules are the classic ones. Each move slides every tile as far as it goes, equal tiles merge once, and a 2 or a 4 appears in an empty cell. Both boards draw new tiles from the same random sequence, so you and the AI share the luck as evenly as the game allows.

The models

Search + N-tuple
Looks a move or two ahead and asks the N-tuple network how good each possible board is.
N-tuple network
Scores boards with lookup tables it learned by playing 55,000 games against itself.
PPO
A neural network that learned how likely it should be to pick each move.
Deep Q-network
A neural network that predicts how many points each move will lead to.
Heuristic
A hand-written rule that keeps big tiles in one corner and leaves room to merge.

What it's thinking

The bars show how the model rated each move before choosing. The glow on its board marks the tiles that most influenced the decision.

Everything runs in your browser. The models were trained in Python with NumPy and PyTorch, and the code is on GitHub. The full story is in How I built it.