{
"id": "111",
"prompt": "Build a pong match against a computer opponent: my paddle on the left follows pointer_y, the CPU paddle on the right chases the ball at a capped speed so it can be beaten. First to 5 points wins, then a win/lose screen with both scores and a tap-to-rematch. Remember rustlite has no struct literals - keep the ball and scores in state slots.",
"solution_rl": "fn 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, w / 2);\n host::display::state_set(2, h / 2);\n host::display::state_set(3, 4);\n host::display::state_set(4, 3);\n host::display::state_set(9, h / 2 - 30);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(8) == 0;\n host::display::state_set(8, down);\n let phase: i32 = host::display::state_get(7);\n if phase == 1 {\n host::display::clear(0x101018);\n if host::display::state_get(5) >= 5 {\n host::display::draw_string(160, 190, \"YOU WIN\", 0x00ff88, 4);\n } else {\n host::display::draw_string(150, 190, \"CPU WINS\", 0xff4040, 4);\n }\n host::display::draw_number(200, 250, host::display::state_get(5), 0xffffff, 3);\n host::display::draw_number(280, 250, host::display::state_get(6), 0xff8800, 3);\n host::display::draw_string(150, 320, \"TAP TO REMATCH\", 0x808080, 2);\n if tap {\n host::display::state_set(5, 0);\n host::display::state_set(6, 0);\n host::display::state_set(7, 0);\n host::display::state_set(0, 0);\n }\n } else {\n let mut bx: i32 = host::display::state_get(1);\n let mut by: i32 = host::display::state_get(2);\n let mut vx: i32 = host::display::state_get(3);\n let mut vy: i32 = host::display::state_get(4);\n let mut py: i32 = host::display::pointer_y() - 30;\n if py < 0 { py = 0; }\n if py > h - 60 { py = h - 60; }\n let mut ay: i32 = host::display::state_get(9);\n let bc: i32 = by + 5;\n if bc > ay + 34 { ay = ay + 3; }\n if bc < ay + 26 { ay = ay - 3; }\n if ay < 0 { ay = 0; }\n if ay > h - 60 { ay = h - 60; }\n host::display::state_set(9, ay);\n bx = bx + vx;\n by = by + vy;\n if by < 0 { by = 0; vy = -vy; }\n if by > h - 10 { by = h - 10; vy = -vy; }\n if bx < 20 && bx > 6 && vx < 0 && by + 10 > py && by < py + 60 {\n bx = 20;\n vx = -vx;\n }\n if bx > w - 30 && bx < w - 16 && vx > 0 && by + 10 > ay && by < ay + 60 {\n bx = w - 30;\n vx = -vx;\n }\n if bx < -12 {\n host::display::state_set(6, host::display::state_get(6) + 1);\n bx = w / 2;\n by = h / 2;\n vx = 4;\n vy = 3;\n }\n if bx > w + 2 {\n host::display::state_set(5, host::display::state_get(5) + 1);\n bx = w / 2;\n by = h / 2;\n vx = -4;\n vy = 3;\n }\n host::display::state_set(1, bx);\n host::display::state_set(2, by);\n host::display::state_set(3, vx);\n host::display::state_set(4, vy);\n if host::display::state_get(5) >= 5 || host::display::state_get(6) >= 5 {\n host::display::state_set(7, 1);\n }\n host::display::clear(0x000000);\n let mut ny: i32 = 0;\n while ny < h {\n host::display::fill_rect(w / 2 - 1, ny, 2, 8, 0x303030);\n ny = ny + 16;\n }\n host::display::fill_rect(12, py, 8, 60, 0xffffff);\n host::display::fill_rect(w - 20, ay, 8, 60, 0xff8800);\n host::display::fill_rect(bx, by, 10, 10, 0x00ff88);\n host::display::draw_number(w / 2 - 60, 10, host::display::state_get(5), 0xffffff, 3);\n host::display::draw_number(w / 2 + 36, 10, host::display::state_get(6), 0xff8800, 3);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"pointer",
"no-struct-boundary"
]
}