| 1 | """A bot's own process, in Kaggle's own interface: main.py defines agent(obs, config) (or, as Kaggle allows, its last |
| 2 | function is the agent) and returns the game's action. The observation and configuration arrive as JSON and are handed |
| 3 | over as kaggle_environments Structs, so obs.planets and obs["planets"] both work, as on Kaggle. |
| 4 | python3 -I referee/kaggle_child.py <main.py> |
| 5 | """ |
| 6 | import os, sys |
| 7 | |
| 8 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit')) |
| 9 | import inspect, random |
| 10 | from host import load, serve |
| 11 | from kaggle_environments.utils import structify |
| 12 | |
| 13 | random.seed(0) |
| 14 | agent = load(sys.argv[1], 'agent') |
| 15 | takes = len(inspect.signature(agent).parameters) |
| 16 | |
| 17 | |
| 18 | def handle(msg): |
| 19 | obs, config = structify(msg['obs']), structify(msg['config']) |
| 20 | return agent(obs, config) if takes > 1 else agent(obs) |
| 21 | |
| 22 | |
| 23 | serve(handle) |