{
"id": "118",
"prompt": "A little maze escape: encode an 8x8 maze as an array of row bitmasks (test a wall with (row >> x) % 2), draw the wall cells, and move my yellow runner one cell per tap toward the pointer (dominant axis wins, walls block). Reaching the green exit shows an ESCAPED screen with the step count and offers a restart. Track position and steps in state slots.",
"solution_rl": "fn wall(rows_y: i32, x: i32) -> i32 {\n (rows_y >> x) % 2\n}\n\nfn frame(t: i32) {\n let w: i32 = host::display::width();\n let cs: i32 = w / 8;\n let rows = [255, 145, 215, 129, 189, 133, 145, 255];\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, 1);\n host::display::state_set(3, 0);\n host::display::state_set(4, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(5) == 0;\n host::display::state_set(5, down);\n let mut px: i32 = host::display::state_get(1);\n let mut py: i32 = host::display::state_get(2);\n if host::display::state_get(4) == 1 {\n host::display::clear(0x041804);\n host::display::draw_string(160, 180, \"ESCAPED\", 0x00ff88, 4);\n host::display::draw_string(150, 250, \"STEPS\", 0x808080, 2);\n host::display::draw_number(260, 244, host::display::state_get(3), 0xffffff, 3);\n host::display::draw_string(140, 320, \"TAP TO RE-ENTER\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n if tap {\n let mut dx: i32 = host::display::pointer_x() - (px * cs + cs / 2);\n let mut dy: i32 = host::display::pointer_y() - (py * cs + cs / 2);\n let mut ax: i32 = dx;\n if ax < 0 { ax = -ax; }\n let mut ay: i32 = dy;\n if ay < 0 { ay = -ay; }\n let mut nx: i32 = px;\n let mut ny: i32 = py;\n if ax > ay {\n if dx > 0 { nx = px + 1; } else { nx = px - 1; }\n } else {\n if dy > 0 { ny = py + 1; } else { ny = py - 1; }\n }\n if wall(rows[ny], nx) == 0 {\n px = nx;\n py = ny;\n host::display::state_set(1, px);\n host::display::state_set(2, py);\n host::display::state_set(3, host::display::state_get(3) + 1);\n }\n if px == 6 && py == 6 {\n host::display::state_set(4, 1);\n }\n }\n host::display::clear(0x101418);\n let mut y: i32 = 0;\n while y < 8 {\n let mut x: i32 = 0;\n while x < 8 {\n if wall(rows[y], x) == 1 {\n host::display::fill_rect(x * cs, y * cs, cs, cs, 0x304050);\n }\n x = x + 1;\n }\n y = y + 1;\n }\n host::display::fill_rect(6 * cs + 8, 6 * cs + 8, cs - 16, cs - 16, 0x00aa44);\n host::display::fill_rect(px * cs + 12, py * cs + 12, cs - 24, cs - 24, 0xffdd00);\n host::display::draw_number(8, 4, host::display::state_get(3), 0xffffff, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"arrays",
"loops",
"state"
]
}