"""A bot's own process, in the ARC-AGI-3-Agents interface: agent.py defines a class Agent with choose_action(frames, latest_frame) -> GameAction (or (GameAction, {"x": .., "y": ..}) for ACTION6) and, if it likes, is_done(frames, latest_frame). It plays one game through the official toolkit, online mode, against the referee's local server, and stops at the action limit. python3 referee/agent_child.py """ import os, sys sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit')) import random # noqa: E402 from host import load # noqa: E402 from arc_agi import Arcade, OperationMode # noqa: E402 from arcengine import GameAction, GameState # noqa: E402 random.seed(0) bot, url, game, most = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]) agent = load(bot, 'Agent')() arc = Arcade(arc_api_key='local', arc_base_url=url, operation_mode=OperationMode.ONLINE, environments_dir=os.path.join(os.getcwd(), 'none')) env = arc.make(game) fd = env.reset() frames = [fd] for _ in range(most): if hasattr(agent, 'is_done') and agent.is_done(frames, fd): break try: out = agent.choose_action(frames, fd) except Exception: out = GameAction.RESET action, data = out if isinstance(out, tuple) else (out, getattr(out, 'action_data', None)) if not isinstance(action, GameAction): action = GameAction.RESET if fd.state is GameState.GAME_OVER: action = GameAction.RESET data = dict(data) if isinstance(data, dict) else {} fd = env.step(action, data={k: data[k] for k in ('x', 'y') if k in data} if action.is_complex() else {}) frames.append(fd)