{
"id": "138",
"prompt": "Stacker arcade game: a block sweeps side to side above the tower; tap to drop it. Overhang past the block below gets sliced off (within 2px counts as a perfect drop and keeps full width), the sweep speeds up as the tower grows, and a fully missed drop topples it - show the height and restart on tap. Keep the last 12 layers as x/width pairs in a ring of state slots for drawing; there are no persistent arrays.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, w / 2 - 60);\n host::display::state_set(2, 120);\n host::display::state_set(3, 1);\n host::display::state_set(4, 0);\n host::display::state_set(20, w / 2 - 60);\n host::display::state_set(21, 120);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(5) == 0;\n host::display::state_set(5, down);\n let height: i32 = host::display::state_get(3);\n if host::display::state_get(4) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(140, 170, \"IT TOPPLED\", 0xff4040, 4);\n host::display::draw_string(120, 240, \"TOWER HEIGHT\", 0x808080, 2);\n host::display::draw_number(360, 234, height, 0xffffff, 3);\n host::display::draw_string(130, 320, \"TAP TO STACK AGAIN\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let bx: i32 = host::display::state_get(1);\n let bw: i32 = host::display::state_get(2);\n let span: i32 = w - bw;\n let spd: i32 = 4 + height / 3;\n let mut m: i32 = (t * spd) % (2 * span);\n if m > span { m = 2 * span - m; }\n if tap {\n let mut off: i32 = m - bx;\n if off < 0 { off = -off; }\n if off <= 2 { off = 0; }\n let nw: i32 = bw - off;\n if nw <= 0 {\n host::display::state_set(4, 1);\n } else {\n let mut nx: i32 = bx;\n if m > bx { nx = m; }\n host::display::state_set(1, nx);\n host::display::state_set(2, nw);\n host::display::state_set(3, height + 1);\n host::display::state_set(20 + (height % 12) * 2, nx);\n host::display::state_set(21 + (height % 12) * 2, nw);\n }\n }\n host::display::clear(0x0e1218);\n let mut shown: i32 = height;\n if shown > 12 { shown = 12; }\n let mut k: i32 = 0;\n while k < shown {\n let lvl: i32 = height - shown + k;\n let lx: i32 = host::display::state_get(20 + (lvl % 12) * 2);\n let lw: i32 = host::display::state_get(21 + (lvl % 12) * 2);\n let mut col: i32 = 0x3a6ea5;\n if lvl % 2 == 1 { col = 0x4a86c5; }\n host::display::fill_rect(lx, h - 60 - k * 22, lw, 20, col);\n k = k + 1;\n }\n host::display::fill_rect(m, h - 60 - shown * 22, bw, 20, 0xffcc44);\n host::display::draw_string(8, 8, \"HEIGHT\", 0x808080, 2);\n host::display::draw_number(130, 8, height, 0xffffff, 2);\n host::display::draw_string(8, 40, \"TAP TO DROP THE BLOCK\", 0x506070, 1);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"loops",
"ui"
]
}