Skip to content

Example: a model that plays Tetris

tetris.py is Tetris for the terminal in which every falling piece is one decision. You can play it yourself, watch a built-in expert, train a decision model on the expert’s choices and watch that model play, or let TypeSafe’s Jev play. It is one file, standard library only.

Terminal window
curl -O https://turion.ai/docs/examples/tetris.py
python tetris.py play

On Windows PowerShell, use curl.exe -O …. The game runs on Python 3.9 or newer. Playing with a model also needs the turion package where the game runs and a turion login: start the game with uv run --with turion tetris.py …, or pip install turion first.

For the falling piece, the game finds every distinct place it can land: each rotation, dropped straight down in each column. Two landings that leave the same stack count once. It keeps at most 6, the ones with the fewest holes and then the lowest stack (the expert’s own move is among them in about 96% of positions), and asks one choice question. The state is the board:

Tetris board, 10 columns (col 1 is the leftmost), top row first; # is filled, . is empty.
..........
⋮
......##..
.....####.
.....####.
#....#####
#.##.#####
####.##.##
.#######.#
Falling piece: Z. Next piece: L.

The question asks where the piece should land, and each option says what that landing does to the stack:

col 1, turn 0: clears no lines, 1 new hole, stack +5, height 7, bumpiness 13
col 2, turn 1: clears no lines, no new holes, stack +4, height 7, bumpiness 14
col 3, turn 1: clears no lines, 1 new hole, stack +5, height 7, bumpiness 20
col 6, turn 1: clears no lines, no new holes, stack +4, height 9, bumpiness 18
col 7, turn 1: clears no lines, 1 new hole, stack +5, height 10, bumpiness 20
col 8, turn 0: clears no lines, 2 new holes, stack +6, height 8, bumpiness 13

turn counts quarter turns clockwise from the piece’s starting orientation, and col is the column of its leftmost cell. Each option says what that landing changes: the lines it clears, the holes it adds (a cleared line can also remove some), how much the ten column heights grow in total (stack), the tallest column afterwards and the bumpiness (the height differences between neighbouring columns). The expert picks col 2, turn 1 here. A person answers with a letter. A model answers through POST /v1/systemone with one option and a probability for every option, and the game shows the top three next to the board.

Terminal window
python tetris.py play # you pick each move, from the same options
python tetris.py watch # the built-in expert plays
python tetris.py watch --speed 3 # faster animation

The expert scores each option with four weighted features: lines cleared, holes, total height and bumpiness, using Yiyuan Lee’s tuned weights. It plays a very long game. watch stops after --pieces (300 by default); --seed picks the piece order.

Terminal window
python tetris.py data --out tetris.jsonl
# wrote 3600 decisions from 60 games to tetris.jsonl
turion train --base qwen3.5-2b --data tetris.jsonl --name tetris
turion deploy acme/tetris
python tetris.py watch --model acme/tetris

data plays 60 games and records the board, the options and the expert’s choice at each of the first 60 pieces. One move in five is played at random (--explore 0.2), so the data also covers the messy stacks the expert never builds itself; the label is always the expert’s choice. The file is decision data, so turion train picks --method decision on its own. See Train your own for what a decision job trains and how long it takes.

The question is worded the same way in the data and in the game, which is what a decision model needs: see Ask with the training wording.

Terminal window
python tetris.py bench --model acme/tetris
player games lines/game pieces/game
random 5 1.8 40.4
expert 5 57.0 150.0
acme/tetris 5 … …
(games stop at 150 pieces; the same seeds for every player)

Each player plays the same piece orders and picks from the same options; random picks one of them at random. A perfect game clears at most 60 lines in 150 pieces (each line takes 10 cells, each piece adds 4), so the expert’s figure is close to the ceiling.

For scale: qwen3.5-0.8b trained on just 480 positions (data --games 12 --pieces 40) picked the expert’s move in 67% of held-out positions, against 21% before training. Over two 60-piece games it cleared 12.5 lines a game and lasted every piece, where random play cleared 1.5 and lost after 41 pieces, and the expert cleared 22.5. More data and a larger base close the rest of the gap.

Jev answers the same question with no training. Store a TypeSafe or OpenRouter key, then:

Terminal window
turion providers set typesafe
python tetris.py watch --model typesafe/jev-1.13
# or, with an OpenRouter key:
python tetris.py watch --model openrouter/typesafe/jev-1.13

Every piece is one call, billed by the provider on your key.

  • A deployed model scales to zero, so the first move waits for a cold start. After that each move is one request.
  • turion undeploy acme/tetris stops the replicas when you are done.
  • The question offers at most 6 options; a model you train takes up to 26. When only one landing is left, the game plays it without asking.