To beatRandom agent 0
Join
cef7bd7
36 lines · 1.7 KB Raw Permalink History
1"""A bot's own process, in the ARC-AGI-3-Agents interface: agent.py defines a class Agent with
2choose_action(frames, latest_frame) -> GameAction (or (GameAction, {"x": .., "y": ..}) for ACTION6) and, if it likes,
3is_done(frames, latest_frame). It plays one game through the official toolkit, online mode, against the referee's
4local server, and stops at the action limit.
5 python3 referee/agent_child.py <agent.py> <server url> <game> <max actions>
6"""
7import os, sys
8
9sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit'))
10import random # noqa: E402
11from host import load # noqa: E402
12from arc_agi import Arcade, OperationMode # noqa: E402
13from arcengine import GameAction, GameState # noqa: E402
14
15random.seed(0)
16bot, url, game, most = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
17agent = load(bot, 'Agent')()
18arc = Arcade(arc_api_key='local', arc_base_url=url, operation_mode=OperationMode.ONLINE, environments_dir=os.path.join(os.getcwd(), 'none'))
19env = arc.make(game)
20fd = env.reset()
21frames = [fd]
22for _ 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)