Tetris, as text

Every state fits on one line, and every move is a named action. Play with the keyboard, or drive it from outside.

0score
0lines
1level

Keys: ← → move, ↓ down, ↑ or X rotate, Z rotate back, Space drop, C hold.

Compact state

Board view

Send actions


  

Driving it from outside

Actions: left right cw ccw down drop hold tick noop (short forms: l r cw ccw d hd hold t).

Page API: tetris.step("left") returns {obs, reward, done, valid, cleared}. Also tetris.reset(seed), tetris.state(), tetris.load(line), tetris.text().

From an iframe parent or opener: postMessage({type:"tetris", cmd:"step", action:"hd", id:1}, "*"). Commands: step, reset, state, load. The reply is {type:"tetris-reply", id, ...}.

Add ?auto=0&seed=42 to the URL for turn-based, repeatable play with no timer. Add ?ws=ws://localhost:8765 (or ?ws=1 when the page is served by the agent script itself) to connect to a local agent server over WebSocket (JSON messages {id, cmd, action}; replies carry the same id).

State line: s score, l lines, o over, c piece+rotation@x,y, h hold, hc can hold, q next queue, g rest of the bag, rs RNG state, b board rows top to bottom (empty rows above are dropped).