How TETERI is built

How the CPU Opponent Searches

Enumerate every placement, score the resulting board on four weighted features, take the best.

The computer opponent is a one-ply heuristic search. No neural network, no tree, no lookahead beyond the held piece.

For the current piece and the held piece, for each of four rotations, for each column: drop the piece straight down, remove any complete rows, and score the resulting board. Roughly 80 candidates per turn, each evaluated in microseconds on a flat typed array.

The evaluation

Four features, linearly weighted:

Aggregate height — the sum of column heights. Lower is better.

Holes — empty cells with something above them. Heavily penalised, because a hole makes every row above it uncompletable.

Bumpiness — the sum of differences between adjacent column heights. Flat surfaces accept more pieces.

Well depth — how deep single-column gaps are, penalised beyond two cells.

Plus a bonus for lines cleared, an extra bonus for clearing four at once, and a sharp penalty for exceeding a height threshold.

These are close to a well-known published weighting for this problem, adjusted by playtesting.

Playing the move

The chosen placement is converted into a list of inputs — hold, rotations, moves, drop — and those are performed one at a time on a timer. That is deliberate: it makes the opponent watchable, and it means it is playing the same game you are rather than teleporting pieces.

Rotations take the shortest path around the ring, which is a small thing that makes the CPU look competent rather than robotic.

Difficulty

Not a speed multiplier. Rookie deliberately selects a worse-than-best placement about a third of the time and does not use hold. Nightmare never does either. The difference is decision quality, which is what makes lower difficulties genuinely beatable rather than merely slower.

What it cannot do

It has no multi-piece plan, so no T-spin setups and no openers. It never looks at your board. Both are real gaps, and both are where a human beats it.

PLAY TETERI ALL ARTICLES