{
"id": "131",
"prompt": "Snap-judgement sorter: a square or a triangle (LCG-hashed per round) appears mid-screen with a draining timer bar; tap the LEFT half for square, RIGHT for triangle. Correct picks score and shave the time limit down toward a floor; a wrong pick or a timeout ends it with the score and a tap-to-restart. Use fill_triangle for the triangle.",
"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, 1);\n host::display::state_set(2, 90);\n host::display::state_set(3, 90);\n host::display::state_set(4, 0);\n host::display::state_set(5, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(6) == 0;\n host::display::state_set(6, down);\n let score: i32 = host::display::state_get(4);\n if host::display::state_get(5) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(150, 180, \"SORTED OUT\", 0xff4040, 3);\n host::display::draw_string(140, 250, \"CORRECT\", 0x808080, 2);\n host::display::draw_number(300, 244, score, 0xffffff, 3);\n host::display::draw_string(130, 320, \"TAP TO SORT AGAIN\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let round: i32 = host::display::state_get(1);\n let shape: i32 = hash(round * 13) % 2;\n let mut timer: i32 = host::display::state_get(2) - 1;\n let mut limit: i32 = host::display::state_get(3);\n let mut done: i32 = 0;\n if timer <= 0 { done = 1; }\n if tap {\n let mut pick: i32 = 0;\n if host::display::pointer_x() >= w / 2 { pick = 1; }\n if pick == shape {\n host::display::state_set(4, score + 1);\n limit = limit - 3;\n if limit < 36 { limit = 36; }\n host::display::state_set(3, limit);\n host::display::state_set(1, round + 1);\n timer = limit;\n } else {\n done = 1;\n }\n }\n if done == 1 {\n host::display::state_set(5, 1);\n }\n host::display::state_set(2, timer);\n host::display::clear(0x0c0c14);\n host::display::fill_rect(0, 0, timer * w / limit, 10, 0x00ccff);\n if shape == 0 {\n host::display::fill_rect(w / 2 - 60, h / 2 - 80, 120, 120, 0xffaa00);\n } else {\n host::display::fill_triangle(w / 2 - 70, h / 2 + 40, w / 2 + 70, h / 2 + 40, w / 2, h / 2 - 80, 0x00cc88);\n }\n host::display::fill_rect(w / 2 - 1, h - 120, 2, 120, 0x303030);\n host::display::draw_string(60, h - 70, \"SQUARE\", 0xffaa00, 3);\n host::display::draw_string(w / 2 + 40, h - 70, \"TRIANGLE\", 0x00cc88, 3);\n host::display::draw_number(8, 24, score, 0xffffff, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"ui"
]
}