Why the 2048 board is a Python list

Published

I built an AlphaZero agent for 2048 that is never told what a good board looks like. The record-holding agents lean on hand-tuned features such as monotonicity, smoothness and empty cells. Mine learns from self-play alone: a residual network scores boards and suggests moves, and a Monte Carlo Tree Search plans around the random 2 or 4 that drops in after every move.

Self-play is engine-bound, so time saved in the game code is training time saved. The 1-D bitboard / 16-element flat-list engine uses a row-shift lookup cache instead of a 4×4 NumPy array. At 16 cells NumPy’s per-call overhead dominates the actual work: a full clone, move, spawn and legal-moves cycle runs at about 480k steps a second on the 1-D engine and 21k on NumPy (20–51× faster on every primitive), sustaining roughly 1,000 full MCTS simulations per second inside a reproducible train/evaluation pipeline with 8× board-symmetry augmentation.

The GPU needed batching. Running many games at once and sending their search leaves to the network together took utilisation from a few percent to over 80%. It was the single biggest throughput win.

After 20 self-play iterations, which took about 20 hours on one workstation with a single GPU/MPS device, roughly 28% of late-stage self-play games reach 2048. Around 1 in 17 reach 4096. In the first five iterations it rarely cleared 512.

That’s nowhere near the record. TD learning with Expectimax search reaches 32,768 in over 30% of games.

Training curves and the full setup are in the case study, the technical report (PDF) and the code on GitHub.

← Blog