{
"id": "283",
"prompt": "Shared territory grid: an 8x8 board where every connected peer claims the cell under its pointer by publishing the packed cell index PLUS ONE (so 0 can mean nowhere-yet) into its shared slot 0. Each frame draw every peer's claimed cell in a per-peer color from a palette array with the peer number stamped on it. Auto-join a fixed room, clamp the pointer-to-cell math to the board, and show peer_count().",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x0c1016);\n if host::display::state_get(0) == 0 {\n host::mp::auto(4);\n host::display::state_set(0, 1);\n }\n let palette = [0xffcc33, 0x33ff88, 0x66aaff, 0xff6688, 0xcc99ff, 0xffaa55, 0x55dddd, 0xdddddd];\n let cell: i32 = 48;\n let ox: i32 = 64;\n let oy: i32 = 64;\n let mut gy: i32 = 0;\n while gy < 8 {\n let mut gx: i32 = 0;\n while gx < 8 {\n host::display::fill_rect(ox + gx * cell + 1, oy + gy * cell + 1, cell - 2, cell - 2, 0x1a2028);\n gx = gx + 1;\n }\n gy = gy + 1;\n }\n if host::mp::connected() == 0 {\n host::display::draw_string(150, 20, \"CONNECTING...\", 0x8899aa, 2);\n } else {\n let me: i32 = host::mp::self_index();\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let mut cx: i32 = (px - ox) / cell;\n let mut cy: i32 = (py - oy) / cell;\n if cx < 0 {\n cx = 0;\n }\n if cx > 7 {\n cx = 7;\n }\n if cy < 0 {\n cy = 0;\n }\n if cy > 7 {\n cy = 7;\n }\n host::mp::set(0, cy * 8 + cx + 1);\n let n: i32 = host::mp::peer_count();\n let mut i: i32 = 0;\n while i < n {\n let packed: i32 = host::mp::get(i, 0);\n if packed > 0 {\n let pc: i32 = packed - 1;\n let hx: i32 = ox + (pc % 8) * cell;\n let hy: i32 = oy + (pc / 8) * cell;\n host::display::fill_rect(hx + 4, hy + 4, cell - 8, cell - 8, palette[i]);\n host::display::draw_number(hx + cell / 2 - 3, hy + cell / 2 - 4, i, 0x000000, 1);\n }\n i = i + 1;\n }\n host::display::draw_string(64, 20, \"STAND ON A CELL TO CLAIM IT\", 0x8899aa, 1);\n host::display::draw_string(64, 480, \"PEERS\", 0x8899aa, 1);\n host::display::draw_number(112, 478, n, 0xffffff, 1);\n }\n host::display::present();\n}\n",
"tags": [
"mp",
"multiplayer",
"grid"
]
}