Every time a new piece spawns, the AI considers every legal placement — each combination of hold-swap (yes/no), column (0–9), and rotation (0–3). That's at most 80 candidates. For each candidate it simulates dropping the piece straight down onto the current board and scores the resulting position with a penalty function. The placement with the lowest penalty wins.
The search depth is 1 ply — it doesn't look ahead at the next piece. Two hand-coded shortcuts come first: the very first piece is always swapped into the hold slot, and an I-piece is dropped vertically into column 8 whenever every other column is already at least 4 rows higher (preserving a "Tetris well" on the right edge).
The score is a sum of penalty terms, each multiplied by a weight. Lower is better — a perfectly flat empty board scores 0.
| Weight | Value |
|---|---|
| HEIGHT_DIFFERENCE_FACTOR | 5.27 |
| COVERED_PENALTY | 19.65 |
| COVER_RIGHTMOST_PENALTY | 50.00 |
| HEIGHT_RIGHTMOST_PENALTY | 5.00 |
| CONSECUTIVE_CHANGE_PENALTY | 1.71 |
| SMALL_PIT_PENALTY | 5.60 |
| BIG_PIT_PENALTY | 22.46 |
These weights were tuned by the original author with random search.
The Penalty readout in the stats panel shows the current
board's score using these weights — green is good, red is risky.