Cite as
Birken, "Applying AI to Nintendo Tetris"
Original
https://meatfighter.com/nintendotetrisai/
sha256
9a09fb31e1de7ad77985ee030cff40fbd7a8d7c602b088d90bcaae85fb028b68
Archived
https://web.archive.org/web/20260827191216/https://meatfighter.com/nintendotetrisai/
Accessed
2026-10-20
Credit
Michael Birken (meatfighter.com), who read the game's code in FCEUX and wrote an AI that plays it.
Notes
A code-level account of NES Tetris's mechanics, quoting the game's 6502 code with his own comments, written for an AI that plays the game. Undated; the Wayback Machine's earliest capture is from 2014-01-28. Section names are used as locators.

Cited on

Claims (21)

Gravity comes from framesPerDropTable; a piece falls one row every 48 frames at level 0, never more slowly at a higher level, holding steady across levels 10–12, 13–15, and 16–18, down to 2 frames at levels 19–28, and 1 frame from level 29 on.Dropping TetriminosVerified
fallTimer counts frames, and when it reaches the level's value the piece moves down a row; if that row is blocked, the piece locks where it is, so a resting piece locks after one gravity interval.Dropping TetriminosCode
The first piece of a game hangs at the top for 96 frames before gravity starts, because autorepeatY starts at $A0 (−96) and gravity waits until it counts up to 0; pressing Down ends the wait.Gamepad VersionVerified
Holding Left or Right moves the piece at once, again 16 frames later, and then every 6 frames; the press zeroes autorepeatX, each held frame adds 1, and at DAS_RESET (16) the piece moves and the count drops to DAS_DELAY (10).Shifting TetriminosVerified
A soft drop can't start while Left or Right is held.Gamepad VersionCode
Holding Down drops the piece a row on its 3rd frame and then every 2nd frame, and each piece needs a fresh press, because spawning zeroes autorepeatY and only a new press starts the count.Gamepad VersionCode
The game has no hard drop; the only fast drop is the soft drop on Down.Dropping TetriminosWeb
Every new press of Left or Right zeroes the DAS count and moves the piece at once, so pressing on every other frame moves it every 2 frames.Dropping TetriminosVerified
The random number generator is a 16-bit linear feedback shift register at $0017; each step shifts it right and feeds bit 1 XOR bit 9 into the top bit, and from its seed, $8988, it repeats after 32,767 steps.Picking TetriminosVerified
The NMI handler steps the generator every frame, so the time a player takes to place a piece changes which piece comes next.Picking TetriminosCode
pickRandomTetrimino adds a pick counter to the generator's high byte and keeps the low 3 bits; a result of 7, or the same piece as last time, makes it step the generator and take the high byte's low 3 bits plus the previous piece's orientation id, modulo 7, with no further check.Picking TetriminosCode
The reroll adds the previous piece's orientation id, not its index, so one of its eight results is doubled; after an O ($0A) or an S ($0B) the doubled result is the same piece again.Picking TetriminosCode
In a long game the routine deals T and S most often (14.67% and 14.68%) and L and I least (13.89% each); J, Z, and O come 14.29–14.30% of the time.Picking TetriminosVerified
The level first rises at 10 × (start level + 1) lines from start levels 0–9, at 100 lines from 10–15, and at 110, 120, 130, and 140 lines from 16, 17, 18, and 19; after that it rises every 10 lines.Lines and StatisticsVerified
Each time the lines' ones digit turns 0, the level goes up by 1 if it is below the hundreds and tens digits read as one hexadecimal byte; 130 lines gives $13, which is 19.Lines and StatisticsCode
The NES draws 60.0988 frames per second.Dropping TetriminosWeb
Players call level 29 the "kill screen", although the game goes on.The Kill ScreenWeb
Engadget describes the level 29 kill screen as a wall for players who hold the D-pad, because DAS can't carry pieces to either edge in time.Dropping TetriminosMagazine
Birken reports that the game itself breaks down around 1,550 lines, usually freezing, sometimes resetting or going black, because the scoring loop runs once per level and takes longer than a frame at high levels.The Kill ScreenThe Kill ScreenWeb
In competitive classic Tetris, holding the D-pad to move pieces is called DAS, for delayed auto shift.Shifting TetriminosMagazine
Birken names Thor Aackerlund as a player who beat DAS at level 29 by vibrating the D-pad.Dropping TetriminosWeb