You are implementing an autopilot strategy for a simple side-scrolling jump game.
A character moves forward automatically. On each game tick, your strategy must decide whether the character should jump.
Game rules:
-
If the character touches the ground, it loses.
-
If the character goes above the top boundary, it loses.
-
The map contains coins. When the character collides with a coin, the coin is collected and the score increases.
-
Every jump costs one coin.
-
If the strategy attempts to jump when the character has no coins left, the jump cannot happen; the character will continue falling and may lose.
There are therefore three main failure modes:
-
Hitting the top boundary.
-
Hitting the ground.
-
Running out of coins when a jump is needed.
Implement a strategy function that, given the current game state, returns whether the character should jump on this tick. The strategy should keep the character alive as long as possible while collecting coins and avoiding unnecessary jumps.
Your implementation should reason about the current vertical position, vertical velocity, remaining coins, nearby collectible coins, and the risk of hitting the top or bottom boundary.