in robosumo/envs/sumo.py [0:0]
def __init__(self, agent_names,
xml_path=None,
init_pos_noise=.1,
init_vel_noise=.1,
agent_kwargs=None,
frame_skip=5,
tatami_size=2.0,
timestep_limit=500,
**kwargs):
EzPickle.__init__(self)
self._tatami_size = tatami_size + 0.1
self._timestep_limit = timestep_limit
self._init_pos_noise = init_pos_noise
self._init_vel_noise = init_vel_noise
self._n_agents = len(agent_names)
self._mujoco_init = False
self._num_steps = None
self._spec = None
# Resolve agent scopes
agent_scopes = [
"%s%d" % (name, i)
for i, name in enumerate(agent_names)
]
# Consturct scene XML
scene_xml_path = os.path.join(os.path.dirname(__file__),
"assets", "tatami.xml")
agent_xml_paths = [_AGENTS[name] for name in agent_names]
scene = construct_scene(scene_xml_path, agent_xml_paths,
agent_scopes=agent_scopes,
tatami_size=tatami_size,
**kwargs)
# Init MuJoCo
if xml_path is None:
with tempfile.TemporaryDirectory() as tmpdir_name:
scene_filepath = os.path.join(tmpdir_name, "scene.xml")
scene.write(scene_filepath)
MujocoEnv.__init__(self, scene_filepath, frame_skip)
else:
with open(xml_path, 'w') as fp:
scene.write(fp.name)
MujocoEnv.__init__(self, fp.name, frame_skip)
self._mujoco_init = True
# Construct agents
agent_kwargs = agent_kwargs or {}
self.agents = [
agents.get(name, env=self, scope=agent_scopes[i], **agent_kwargs)
for i, name in enumerate(agent_names)
]
# Set opponents
for i, agent in enumerate(self.agents):
agent.set_opponents([
agent for j, agent in enumerate(self.agents) if j != i
])
# Setup agents
for i, agent in enumerate(self.agents):
agent.setup_spaces()
# Set observation and action spaces
self.observation_space = Tuple([
agent.observation_space for agent in self.agents
])
self.action_space = Tuple([
agent.action_space for agent in self.agents
])