{
"id": "247",
"prompt": "A pursuit-curve chase: the rabbit runs laps on a circle of radius 140 (position straight from a 32-entry sine table, cos is the +8 offset), while the fox - stored in state slots in 1/8-px fixed point - always heads directly at the rabbit at constant speed. Normalize the chase direction with manhattan length instead of sqrt: step = delta * 5 / (|dx|+|dy|+1). When the fox gets within 20px it scores a catch, teleports back to the corner, and a CAUGHT counter increments. Dot the circular track so the geometry of the spiral intercept is visible.",
"solution_rl": "fn iabs(v: i32) -> i32 {\n if v < 0 { -v } else { v }\n}\n\nfn frame(t: i32) {\n let tab = [0, 25, 49, 71, 90, 106, 117, 124, 127, 124, 117, 106, 90, 71, 49, 25, 0, -25, -49, -71, -90, -106, -117, -124, -127, -124, -117, -106, -90, -71, -49, -25];\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let cx: i32 = w / 2;\n let cy: i32 = h / 2;\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, 60 * 8);\n host::display::state_set(2, 60 * 8);\n }\n let idx: i32 = (t / 6) & 31;\n let rx: i32 = cx + tab[idx] * 140 / 127;\n let ry: i32 = cy + tab[(idx + 8) & 31] * 140 / 127;\n let mut fx: i32 = host::display::state_get(1);\n let mut fy: i32 = host::display::state_get(2);\n let dx: i32 = rx * 8 - fx;\n let dy: i32 = ry * 8 - fy;\n let len: i32 = (iabs(dx) + iabs(dy)) / 8 + 1;\n fx = fx + dx * 5 / len;\n fy = fy + dy * 5 / len;\n let mut caught: i32 = host::display::state_get(3);\n let ex: i32 = rx - fx / 8;\n let ey: i32 = ry - fy / 8;\n if ex * ex + ey * ey < 400 {\n caught = caught + 1;\n fx = 60 * 8;\n fy = 60 * 8;\n }\n host::display::state_set(1, fx);\n host::display::state_set(2, fy);\n host::display::state_set(3, caught);\n host::display::clear(0x0e0e12);\n let mut i: i32 = 0;\n while i < 16 {\n let a: i32 = i * 2;\n host::display::fill_rect(cx + tab[a] * 140 / 127 - 1, cy + tab[(a + 8) & 31] * 140 / 127 - 1, 2, 2, 0x303840);\n i = i + 1;\n }\n host::display::draw_line(fx / 8, fy / 8, rx, ry, 0x303030);\n host::display::fill_rect(rx - 5, ry - 5, 10, 10, 0xf0f0f0);\n host::display::fill_rect(fx / 8 - 6, fy / 8 - 6, 12, 12, 0xe06020);\n host::display::draw_string(8, 8, \"CAUGHT\", 0x808080, 1);\n host::display::draw_number(70, 8, caught, 0xffffff, 1);\n host::display::present();\n}\n",
"tags": [
"simulation",
"pursuit",
"sine-table",
"state"
]
}