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