{
"id": "126",
"prompt": "Wild-west quick-draw duel against the CPU, phases in a state slot: a face-off screen, a STEADY wait of random hash-picked length where tapping early forfeits the round, then DRAW with a high beep - I must tap before the CPU's hidden hash-picked reaction time expires. Rounds go to first-to-3 with a result flash between rounds and a rematch screen at the end.",
"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 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, 0);\n host::display::state_set(6, 0);\n host::display::state_set(7, 0);\n host::display::state_set(9, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(8) == 0;\n host::display::state_set(8, down);\n let phase: i32 = host::display::state_get(1);\n let mine: i32 = host::display::state_get(6);\n let ai: i32 = host::display::state_get(7);\n if phase == 0 {\n host::display::clear(0x181410);\n host::display::draw_string(140, 140, \"QUICK DRAW\", 0xffcc66, 3);\n host::display::draw_string(110, 200, \"FIRST TO 3 ROUNDS\", 0x808080, 2);\n host::display::draw_number(180, 250, mine, 0x00ff88, 4);\n host::display::draw_string(240, 256, \"VS\", 0x808080, 2);\n host::display::draw_number(300, 250, ai, 0xff4040, 4);\n host::display::draw_string(130, 340, \"TAP TO FACE OFF\", 0xffffff, 2);\n if tap {\n let rnd: i32 = host::display::state_get(9) + 1;\n host::display::state_set(9, rnd);\n host::display::state_set(3, 40 + hash(rnd) % 80);\n host::display::state_set(4, 16 + hash(rnd * 3) % 22);\n host::display::state_set(2, 0);\n host::display::state_set(1, 1);\n }\n } else if phase == 1 {\n host::display::clear(0x401810);\n host::display::draw_string(130, 200, \"STEADY...\", 0xff9070, 4);\n let timer: i32 = host::display::state_get(2) + 1;\n host::display::state_set(2, timer);\n if tap {\n host::display::state_set(7, ai + 1);\n host::display::state_set(10, 0);\n host::display::state_set(11, 70);\n host::display::state_set(1, 3);\n } else if timer >= host::display::state_get(3) {\n host::audio::tone(1046, 100, 1);\n host::display::state_set(5, 0);\n host::display::state_set(1, 2);\n }\n } else if phase == 2 {\n host::display::clear(0x104018);\n host::display::draw_string(160, 190, \"DRAW!\", 0xffffff, 6);\n let dtimer: i32 = host::display::state_get(5) + 1;\n host::display::state_set(5, dtimer);\n if tap {\n host::display::state_set(6, mine + 1);\n host::display::state_set(10, 1);\n host::display::state_set(11, 70);\n host::display::state_set(1, 3);\n } else if dtimer >= host::display::state_get(4) {\n host::display::state_set(7, ai + 1);\n host::display::state_set(10, 0);\n host::display::state_set(11, 70);\n host::display::state_set(1, 3);\n }\n } else {\n host::display::clear(0x101018);\n if host::display::state_get(10) == 1 {\n host::display::draw_string(110, 200, \"YOU FIRED FIRST\", 0x00ff88, 3);\n } else {\n host::display::draw_string(120, 200, \"CPU TAKES IT\", 0xff4040, 3);\n }\n host::display::draw_number(180, 260, mine, 0x00ff88, 4);\n host::display::draw_number(300, 260, ai, 0xff4040, 4);\n let rt: i32 = host::display::state_get(11) - 1;\n host::display::state_set(11, rt);\n if rt <= 0 {\n if mine >= 3 || ai >= 3 {\n host::display::state_set(1, 4);\n } else {\n host::display::state_set(1, 0);\n }\n }\n }\n if phase == 4 {\n host::display::clear(0x101018);\n if mine >= 3 {\n host::display::draw_string(90, 190, \"YOU WIN THE DUEL\", 0x00ff88, 3);\n } else {\n host::display::draw_string(90, 190, \"CPU WINS THE DUEL\", 0xff4040, 3);\n }\n host::display::draw_string(130, 260, \"TAP FOR A REMATCH\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"audio"
]
}