{
"id": "043",
"prompt": "Reaction timer, three phases in a state slot: IDLE (\"TAP TO ARM\"), ARMED (red screen, random 30..150-frame delay from an LCG of the arm count), GO (green screen, count frames until the tap, show frames*16 as milliseconds). A tap during ARMED counts as a false start and returns to IDLE. Edge-detect every tap.",
"solution_rl": "fn hash(seed: i32) -> i32 {\n let mut h: i32 = seed * 747796405 + 2891336453;\n h = (h >> 16) ^ h;\n if h < 0 { h = 0 - h; }\n h\n}\n\nfn frame(t: i32) {\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(9);\n let tap: bool = down == 1 && prev == 0;\n host::display::state_set(9, down);\n let phase: i32 = host::display::state_get(0);\n if phase == 0 {\n host::display::clear(0x101020);\n host::display::draw_string(8, 10, \"TAP TO ARM\", 0xffffff, 2);\n host::display::draw_string(8, 40, \"LAST MS\", 0x808080, 1);\n host::display::draw_number(70, 40, host::display::state_get(4), 0x00ff00, 1);\n if tap {\n let n: i32 = host::display::state_get(5) + 1;\n host::display::state_set(5, n);\n host::display::state_set(1, 30 + hash(n) % 120);\n host::display::state_set(2, 0);\n host::display::state_set(0, 1);\n }\n }\n if phase == 1 {\n host::display::clear(0x400000);\n host::display::draw_string(8, 10, \"WAIT FOR GREEN\", 0xff8080, 2);\n let mut wait: i32 = host::display::state_get(2) + 1;\n host::display::state_set(2, wait);\n if tap {\n host::display::state_set(0, 0);\n } else {\n if wait >= host::display::state_get(1) {\n host::display::state_set(3, 0);\n host::display::state_set(0, 2);\n }\n }\n }\n if phase == 2 {\n host::display::clear(0x004000);\n host::display::draw_string(8, 10, \"TAP NOW\", 0x80ff80, 3);\n let mut gone: i32 = host::display::state_get(3) + 1;\n host::display::state_set(3, gone);\n if tap {\n host::display::state_set(4, gone * 16);\n host::display::state_set(0, 0);\n }\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"pointer"
]
}