"""Editable starter bot: mine, return, deposit and launch a small fleet. Run: ./start.sh play --bots bots/mein_bot.py collector --turns 240 This intentionally simple bot does not coordinate several ships perfectly. """ from kobaltmeer.sdk import BaseBot, Observation, Orders class Bot(BaseBot): name = "Mein erster Bot" def __init__(self, seed=0): super().__init__(seed) self.returning = set() def decide(self, observation: Observation, player: int) -> Orders: orders = Orders() harbor = observation.players[player].yard fleet = observation.fleet(player) occupied = {ship.pos for ship in fleet} reserved = set() for ship in sorted(fleet, key=lambda item: -item.cargo): occupied.discard(ship.pos) if ship.pos == harbor: self.returning.discard(ship.id) distance = observation.distance(ship.pos, harbor) if (ship.cargo >= 560 or (ship.cargo > 0 and observation.rules.turns - observation.turn <= distance * 2 + 5)): self.returning.add(ship.id) resource = int(observation.resource[ship.y, ship.x]) if ship.id in self.returning: action = observation.toward(ship.pos, harbor) elif resource >= 60: action = "O" else: # Prefer resource-rich neighboring cells. choices = [] for candidate in ("N", "E", "S", "W"): x, y = observation.destination(ship.pos, candidate) choices.append((int(observation.resource[y, x]) + self.rng.random(), candidate)) action = max(choices)[1] fuel = observation.move_cost(ship) if ship.cargo < fuel: action = "O" destination = observation.destination(ship.pos, action) if destination in occupied or destination in reserved: action = "O" reserved.add(observation.destination(ship.pos, action)) orders.ships[ship.id] = action orders.explain(ship.id, target=harbor if ship.id in self.returning else observation.destination(ship.pos, action), reason="Fracht zum Hafen bringen." if ship.id in self.returning else "Sammeln oder ein reiches Nachbarfeld suchen.", path=[ship.pos, observation.destination(ship.pos, action)]) orders.spawn = (len(fleet) < 5 and observation.turn < observation.rules.turns // 2 and observation.players[player].bank >= observation.rules.ship_cost and harbor not in reserved) return orders