{
"id": "282",
"prompt": "A tap-race tug of war for two browsers: every edge-detected tap fires host::mp::send(1) - a discrete EVENT, not shared state - and bumps my counter; each frame drain the receive queue with event_count()/event_next() to grow the opponent's tally. The rope knot slides by the tap difference and clamps near the edges. Using the event queue instead of slots is the point: taps are discrete, and a coalesced slot would eat them.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n host::display::clear(0x0e0e14);\n if host::display::state_get(0) == 0 {\n host::mp::auto(6);\n host::display::state_set(0, 1);\n }\n if host::mp::connected() == 0 {\n host::display::draw_string(120, 230, \"FINDING AN OPPONENT\", 0x8899aa, 2);\n } else {\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(1);\n host::display::state_set(1, down);\n if down == 1 && prev == 0 {\n host::mp::send(1);\n host::display::state_set(2, host::display::state_get(2) + 1);\n }\n let mut evs: i32 = host::mp::event_count();\n while evs > 0 {\n let v: i32 = host::mp::event_next();\n if v == 1 {\n host::display::state_set(3, host::display::state_get(3) + 1);\n }\n evs = evs - 1;\n }\n let mine: i32 = host::display::state_get(2);\n let theirs: i32 = host::display::state_get(3);\n let mut knot: i32 = w / 2 + (mine - theirs) * 6;\n if knot < 40 {\n knot = 40;\n }\n if knot > w - 40 {\n knot = w - 40;\n }\n host::display::fill_rect(0, 240, w, 8, 0x554433);\n host::display::fill_rect(knot - 10, 220, 20, 48, 0xffffff);\n host::display::draw_string(30, 60, \"YOU\", 0xffcc33, 2);\n host::display::draw_number(30, 100, mine, 0xffcc33, 4);\n host::display::draw_string(400, 60, \"THEM\", 0x33ff88, 2);\n host::display::draw_number(400, 100, theirs, 0x33ff88, 4);\n host::display::draw_string(120, 420, \"TAP FAST TO PULL THE KNOT\", 0x8899aa, 1);\n }\n host::display::present();\n}\n",
"tags": [
"mp",
"events",
"game"
]
}