| 1 | """A bot's own process, in the ARC-AGI-3-Agents interface: agent.py defines a class Agent with |
| 2 | choose_action(frames, latest_frame) -> GameAction (or (GameAction, {"x": .., "y": ..}) for ACTION6) and, if it likes, |
| 3 | is_done(frames, latest_frame). It plays one game through the official toolkit, online mode, against the referee's |
| 4 | local server, and stops at the action limit. |
| 5 | python3 referee/agent_child.py <agent.py> <server url> <game> <max actions> |
| 6 | """ |
| 7 | import os, sys |
| 8 | |
| 9 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit')) |
| 10 | import random |
| 11 | from host import load |
| 12 | from arc_agi import Arcade, OperationMode |
| 13 | from arcengine import GameAction, GameState |
| 14 | |
| 15 | random.seed(0) |
| 16 | bot, url, game, most = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]) |
| 17 | agent = load(bot, 'Agent')() |
| 18 | arc = Arcade(arc_api_key='local', arc_base_url=url, operation_mode=OperationMode.ONLINE, environments_dir=os.path.join(os.getcwd(), 'none')) |
| 19 | env = arc.make(game) |
| 20 | fd = env.reset() |
| 21 | frames = [fd] |
| 22 | for _ in range(most): |
| 23 | if hasattr(agent, 'is_done') and agent.is_done(frames, fd): |
| 24 | break |
| 25 | try: |
| 26 | out = agent.choose_action(frames, fd) |
| 27 | except Exception: |
| 28 | out = GameAction.RESET |
| 29 | action, data = out if isinstance(out, tuple) else (out, getattr(out, 'action_data', None)) |
| 30 | if not isinstance(action, GameAction): |
| 31 | action = GameAction.RESET |
| 32 | if fd.state is GameState.GAME_OVER: |
| 33 | action = GameAction.RESET |
| 34 | data = dict(data) if isinstance(data, dict) else {} |
| 35 | fd = env.step(action, data={k: data[k] for k in ('x', 'y') if k in data} if action.is_complex() else {}) |
| 36 | frames.append(fd) |