--- issue: 1 status: done tags: search --- # Nearest winnable planet, aimed ahead, without crossing the sun Issue #1's strategy, rebuilt from the starter: each planet sends just enough ships to take the nearest planet it can win (nearest in turns to arrive), aimed at where an orbiting target will be. The first try, `swarm` (cc591d1), scored 0.444 and lost every game to the starter. This route scores **1.0** locally: it wins all 36 check games against random, starter and swarm. ## What `main.py` does - **Predicts where every planet will be** for the next 160 turns. Orbiting planets turn at `angular_velocity` around (50, 50), comets follow their `paths`, and static planets stay put (`paths`). - **Flies fleets the way the engine does** (`fly`). It uses the same speed curve and the same swept fleet/planet test. It also checks for the sun and the edge, and returns which planet a fleet hits and on which turn. Every fleet in flight, mine or the enemy's, goes through it, so the bot knows what arrives where and when. - **Forecasts each planet's owner turn by turn** (`owners`), with production and the engine's combat: the largest force minus the second, then against the garrison. - **Sends only what its planets can spare.** A planet keeps the least it needs to hold against the fleets already coming at it. - **Picks the target.** For each target not already bound to be mine, the bot iterates *ships → speed → arrival turn → ships needed* (binary search on the forecast). It aims at the target's centre on the arrival turn. It skips targets it cannot afford, and neutrals whose production would not pay back their garrison before turn 500. Then it takes the candidates nearest-first. The first one whose simulated flight hits that target, with no sun or other planet in between, gets the fleet. - **Reinforces its own planets.** A planet of mine that is forecast to fall is a target like any other, so the nearest planet that can save it does. ## Results | | random | starter | swarm | score | |---|---|---|---|---| | baseline: starter (`routes/main.py`) | 1 | 0.5 | 1 | 0.833 | | `swarm` route (cc591d1, check job 25) | 0.833 | 0 | 0.5 | 0.444 | | this route, check seeds (6 maps × 2 seats) | 1 | 1 | 1 | **1.0** | | this route, seeds 1–10 × 2 seats (not in the check) | 20/20 | 20/20 | 20/20 | 1.0 | Most games end by elimination before turn 160. The slowest turn I measured is under 0.05 s, in field games and in mirror matches that run the full 500 turns with many fleets in flight; the limit is 1 s. What `swarm` misses (I did not measure which of these costs it most): 1. It sends every turn without counting the fleets already on the way, so its ships trickle out. 2. Its paths cross the sun. 3. Its guess for an enemy's garrison (`ships + 10·production`) has nothing to do with travel time. 4. It never keeps ships back to hold a planet. ## Reproduce ``` python3 routes/bo-claude/1-take-the-nearest-planet-that-can/main.py # self-check: combat, intercept, ok PYTHONHASHSEED=0 python3 -s referee/play.py check routes/bo-claude/1-take-the-nearest-planet-that-can ``` ## Next The field is beaten, so the next test is a harder opponent. Mirror matches vs this bot are close, often tied 1054 to 1054. To improve on it: when no single planet can win a target, gather ships from several planets (it now waits until one planet has enough). Weigh targets by production per ship and turn, not by distance alone. Strike the enemy before it attacks, when its fleets in flight leave a planet thin.