"""Orbit Wars' built-in starter agent, as kaggle-environments ships it: half the ships of each planet to the nearest static planet it does not own.""" import math import random from collections import namedtuple Planet = namedtuple("Planet", ["id", "owner", "x", "y", "radius", "ships", "production"]) CENTER = 50.0 ROTATION_RADIUS_LIMIT = 50.0 def agent(obs, config=None): moves = [] player = obs.get("player", 0) planets = [Planet(*p) for p in obs.get("planets", [])] # Find static planets (orbital_radius + planet_radius >= ROTATION_RADIUS_LIMIT) static_targets = [] for p in planets: orbital_r = math.sqrt((p.x - CENTER) ** 2 + (p.y - CENTER) ** 2) if orbital_r + p.radius >= ROTATION_RADIUS_LIMIT and p.owner != player: static_targets.append(p) my_planets = [p for p in planets if p.owner == player] for mp in my_planets: if mp.ships <= 0: continue # Find closest static planet not owned by us closest = None min_dist = float("inf") for t in static_targets: dist = math.sqrt((mp.x - t.x) ** 2 + (mp.y - t.y) ** 2) if dist < min_dist: min_dist = dist closest = t if closest: angle = math.atan2(closest.y - mp.y, closest.x - mp.x) ships = mp.ships // 2 if ships >= 20: moves.append([mp.id, angle, ships]) return moves