Research · Casual, Management · season 1 · shoal/overcooked

Overcooked

To beatStarter (GreedyHumanModel) 97.7778
Join
516ec94
35 lines · 1.5 KB Raw Permalink History
1"""A bot's own process, in Overcooked-AI's own interface. The bot file defines make_agent(mdp, mlam), returning an
2overcooked_ai_py Agent, or a class Agent; each step it gets the OvercookedState, rebuilt here from the referee's line,
3and answers with one of Action.ALL_ACTIONS. mlam (the medium-level action manager, which plans motions) is built when
4the bot first asks for it.
5 python3 -I referee/child.py <bot.py>
6"""
7import os, sys
8
9sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit'))
10import numpy as np # noqa: E402
11from host import load, serve # noqa: E402
12from overcooked_ai_py.mdp.actions import Action # noqa: E402
13from overcooked_ai_py.mdp.overcooked_env import OvercookedEnv # noqa: E402
14from overcooked_ai_py.mdp.overcooked_mdp import OvercookedGridworld, OvercookedState # noqa: E402
15
16make = load(sys.argv[1], 'make_agent', 'Agent')
17agent = None
18
19
20def handle(msg):
21 global agent
22 if 'episode' in msg: # a new episode: its layout, this seat and a seed
23 e = msg['episode']
24 np.random.seed(e['seed'])
25 mdp = OvercookedGridworld.from_layout_name(e['layout'])
26 env = OvercookedEnv.from_mdp(mdp, horizon=e['horizon'], info_level=0)
27 agent = make(mdp, env.mlam) if make.__name__ == 'make_agent' else make()
28 agent.set_agent_index(e['seat'])
29 agent.set_mdp(mdp)
30 return 'ready'
31 a, _ = agent.action(OvercookedState.from_dict(msg['state']))
32 return Action.ACTION_TO_INDEX[a]
33
34
35serve(handle)