| @@ -0,0 +1,42 @@ |
| 1 | +"""The starter bot: Orbit Wars' own starter agent from kaggle-environments. Copy it into routes/<your route>/main.py and |
| 2 | +make it better; on Kaggle the same file would be your submission.""" |
| 3 | +import math |
| 4 | +import random |
| 5 | +from collections import namedtuple |
| 6 | + |
| 7 | +Planet = namedtuple("Planet", ["id", "owner", "x", "y", "radius", "ships", "production"]) |
| 8 | +CENTER = 50.0 |
| 9 | +ROTATION_RADIUS_LIMIT = 50.0 |
| 10 | + |
| 11 | +def agent(obs, config=None): |
| 12 | + moves = [] |
| 13 | + player = obs.get("player", 0) |
| 14 | + planets = [Planet(*p) for p in obs.get("planets", [])] |
| 15 | + |
| 16 | + |
| 17 | + static_targets = [] |
| 18 | + for p in planets: |
| 19 | + orbital_r = math.sqrt((p.x - CENTER) ** 2 + (p.y - CENTER) ** 2) |
| 20 | + if orbital_r + p.radius >= ROTATION_RADIUS_LIMIT and p.owner != player: |
| 21 | + static_targets.append(p) |
| 22 | + |
| 23 | + my_planets = [p for p in planets if p.owner == player] |
| 24 | + for mp in my_planets: |
| 25 | + if mp.ships <= 0: |
| 26 | + continue |
| 27 | + |
| 28 | + closest = None |
| 29 | + min_dist = float("inf") |
| 30 | + for t in static_targets: |
| 31 | + dist = math.sqrt((mp.x - t.x) ** 2 + (mp.y - t.y) ** 2) |
| 32 | + if dist < min_dist: |
| 33 | + min_dist = dist |
| 34 | + closest = t |
| 35 | + |
| 36 | + if closest: |
| 37 | + angle = math.atan2(closest.y - mp.y, closest.x - mp.x) |
| 38 | + ships = mp.ships // 2 |
| 39 | + if ships >= 20: |
| 40 | + moves.append([mp.id, angle, ships]) |
| 41 | + |
| 42 | + return moves |