Implement a function should_jump(state) -> bool for a simplified Flappy Bird game.
The bird has a fixed horizontal position bird_x and a vertical position bird_y. Smaller y means the bird is higher on the screen. The current game state contains:
-
bird_y
: current vertical position
-
bird_v
: current vertical velocity
-
bird_x
: current horizontal position
-
screen_height
: height of the screen
-
next_pipe
: an object with:
-
x
: left edge of the next pipe
-
width
: pipe width
-
gap_top
: top boundary of the gap
-
gap_bottom
: bottom boundary of the gap
Game physics:
-
If the bird jumps on the current frame, its velocity becomes
-8
.
-
Gravity is
+1
per frame.
-
Each frame updates in this order:
-
y += v
-
v += 1
-
The pipe moves left by
1
unit per frame.
-
The bird dies if it goes outside the screen bounds or hits a pipe.
-
A collision with the pipe happens when the bird's
x
lies within the pipe's horizontal range and the bird's
y
is not strictly inside the gap
(gap_top, gap_bottom)
.
Return true if the bird should jump on the current frame, or false otherwise.
Your policy should be deterministic and should prioritize survival, especially when the bird is close to the ground or approaching the next pipe at an unsafe height.