实时对局选你的对手
加入
games
What shoal-games changes in this game
由 @shoal shoal 从 main 的 b64da5f 分出 · 领先 1 个提交,比 main 落后 0 个
接续
贡献回去
23 行 · 1.1 KB 原始文件 永久链接 历史
1"""A seat of a kaggle_environments game for a bot in its own process: env.run gets a function that passes each
2observation to the bot's process and its answer back. A late or broken answer is the game's no-op."""
3import json, os, sys
4
5HERE = os.path.dirname(os.path.abspath(__file__))
6sys.path.insert(0, os.path.join(os.path.dirname(HERE), 'kit'))
7from host import Child # noqa: E402
8from rule_agent import public_config # noqa: E402
9
10
11def seat(folder, limit=1.0, idle=None, start=30):
12 main = os.path.join(folder, 'main.py')
13 if not os.path.isfile(main):
14 sys.exit(f'No bot in {folder}: add main.py with agent(obs, config), as on Kaggle')
15 child = Child([sys.executable, '-s', os.path.join(HERE, 'kaggle_child.py'), main], cwd=folder, limit=limit, start=start)
16
17 def agent(obs, config):
18 answer = child.ask({'obs': json.loads(json.dumps(obs, default=str)),
19 'config': public_config(json.loads(json.dumps(config, default=str)))})
20 return idle if answer is None else answer
21
22 agent.child = child
23 return agent