AlphaZero for 2048

2026 · Reinforcement Learning

Python, PyTorch, MCTS, ResNet, Bitboards, Mixed precision (AMP)

An AlphaZero agent that learns 2048 from self-play alone with zero human gameplay heuristics. A 1-D bitboard engine runs at ~1,000 MCTS simulations/sec (~480k raw engine steps/sec), pairing chance-aware Monte Carlo Tree Search (MCTS) over a ResNet policy/value network with 8× board-symmetry augmentation and a reproducible train/evaluation pipeline. After 20 iterations it reaches 2048 in about 28% of late self-play games.

Problem

The record-holding 2048 agents lean on hand-tuned features: monotonicity, smoothness, empty cells. Change the rules and you retune them. I wanted an agent that is never told what a good board looks like. That means learning an evaluation over something like 10⁵² reachable boards, with a random 2 or 4 dropped in after every move.

Approach

  1. I replaced the 4×4 NumPy array with a flat 1-D bitboard and a row-shift cache, because NumPy's per-call overhead dominates at this board size.
  2. Tile powers go in as 16 one-hot channels to ZeroNet, a small residual network. MCTS stays on at inference, since endgames need lookahead the policy alone lacks.
  3. Random spawns feed the value estimates without expanding chance nodes, so the search stays cheap.
  4. Batching leaf evaluations across concurrent games lifted GPU utilisation from a few percent to over 80%. That was the biggest throughput win.
  5. Training used 8-fold board-symmetry augmentation, mixed precision, a cosine learning rate and a replay buffer, all in a reproducible pipeline.

Results

  • After 20 self-play iterations, about 20 hours on one workstation with a single GPU/MPS device, late-stage self-play reaches 2048 in about 28% of games and 4096 in about 1 in 17. In the first five iterations it rarely cleared 512.
  • Policy cross-entropy fell from ~ln 4 to ~0.5, value MSE from ~0.75 to under 0.15, with no collapse along the way. The 1-D engine is what made an overnight run possible instead of a long weekend.

Limits

  • This is nowhere near the TD + Expectimax record (32,768 in over 30% of games). What it has instead is a policy taught by nothing but play.

Metrics

late games reach 2048
28%
MCTS simulations (~480k raw steps/s)
~1,000/s
engine vs NumPy
20–51×
ZeroNet parameters
~2.5M
one workstation, single GPU/MPS
~20 h

Architecture

Loop diagram: inside self-play, the 1-D bitboard engine exchanges board states and moves with chance-aware MCTS, which sends leaf evaluations, batched across games, to ZeroNet. Search-improved targets go to a replay buffer with 8-fold symmetry augmentation, then to training, and the updated net goes back into self-play.
One training iteration. The run did 20.
  1. 1-D bitboard engine + row-shift cache
  2. ZeroNet (8×128 residual)
  3. Chance-aware MCTS (~1,000 sims/s)
  4. Batched concurrent self-play
  5. Replay buffer + 8-fold D4

From the report

From chapter 6 of the report: loss over 20 iterations, engine throughput against NumPy, and the max-tile distribution moving right as training goes on.

Line chart: total, policy, and value loss across 20 self-play iterations, all trending down without instability.
Figure 6.1: Training loss per iteration. Policy cross-entropy falls from ~ln 4 to ~0.5; value MSE from ~0.75 to under 0.15.
Log-scale bar chart comparing the 1-D Python list engine against a 2-D NumPy baseline across engine primitives.
Figure 6.2: Engine throughput, log scale. 1-D list versus NumPy: 20–51× on every primitive. A clone → move → spawn → legal-moves cycle runs at ~480k/s versus ~21k/s.
Grouped bar chart of the maximum tile reached at game end across early, middle, and late training stages, shifting right over training.
Figure 6.3: Max tile at game end, by training stage. Late training ends on exactly 2048 in about 28% of games and on 4096 in about 1 in 17.