@@ -13,14 +13,13 @@ class MultiAgentEnv(gym.Env):
1313 }
1414
1515 def __init__ (self , world , reset_callback = None , reward_callback = None ,
16- observation_callback = None , arglist = None , info_callback = None ,
16+ observation_callback = None , info_callback = None ,
1717 shared_viewer = True ):
1818
1919 self .world = world
2020 self .agents = self .world .policy_agents
21- self .arglist = arglist
2221 # set required vectorized gym env property
23- self .n = len (world .policy_agents )
22+ self .n = len (world .policy_agents )
2423 # scenario callbacks
2524 self .reset_callback = reset_callback
2625 self .reward_callback = reward_callback
@@ -65,27 +64,25 @@ def __init__(self, world, reset_callback=None, reward_callback=None,
6564 self .action_space .append (act_space )
6665 else :
6766 self .action_space .append (total_action_space [0 ])
68- # observation space
67+ # observation space
6968 obs_dim = len (observation_callback (agent , self .world ))
7069 self .observation_space .append (spaces .Box (low = - np .inf , high = + np .inf , shape = (obs_dim ),))
7170 agent .action .c = np .zeros (self .world .dim_c )
7271
73-
72+
7473 # rendering
7574 self .shared_viewer = shared_viewer
7675 if self .shared_viewer :
7776 self .viewers = [None ]
7877 else :
79- self .viewers = [None ] * self .n
78+ self .viewers = [None ] * self .n
8079 self ._reset_render ()
8180
8281 def _step (self , action_n ):
8382 obs_n = []
8483 reward_n = []
8584 done_n = []
8685 info_n = {'n' : []}
87- if self .arglist and self .arglist .render_each_step :
88- self ._reset_render ()
8986 self .agents = self .world .policy_agents
9087 # set action for each agent
9188 for i , agent in enumerate (self .agents ):
@@ -149,7 +146,7 @@ def _set_action(self, action, agent, action_space, time=None):
149146 for s in size :
150147 act .append (action [index :(index + s )])
151148 index += s
152- action = act
149+ action = act
153150 else :
154151 action = [action ]
155152
@@ -187,7 +184,7 @@ def _set_action(self, action, agent, action_space, time=None):
187184 assert len (action ) == 0
188185
189186 # reset rendering assets
190- def _reset_render (self ):
187+ def _reset_render (self ):
191188 self .render_geoms = None
192189 self .render_geoms_xform = None
193190
@@ -261,7 +258,7 @@ def _render(self, mode='human', close=True):
261258 else :
262259 pos = self .agents [i ].state .p_pos
263260 self .viewers [i ].set_bounds (pos [0 ]- cam_range ,pos [0 ]+ cam_range ,pos [1 ]- cam_range ,pos [1 ]+ cam_range )
264- # update geometry positions
261+ # update geometry positions
265262 for e , entity in enumerate (self .world .entities ):
266263 self .render_geoms_xform [e ].set_translation (* entity .state .p_pos )
267264 # render to display or array
@@ -297,13 +294,13 @@ def _get_receptor_activations(self, entity_root, state_root, other_x_pos):
297294 activations .append (tf .reduce_sum (tf .square (dx_pos ), 1 , keep_dims = True ))
298295 activations = tf .concat (1 , activations )
299296 #return tf.nn.softmax(-1e+1 * activations)
300- return tf .exp (- activations / 1.0 ** 2 )
297+ return tf .exp (- activations / 1.0 ** 2 )
301298
302299# vectorized wrapper for a batch of multi-agent environments
303300# assumes all environments have the same observation and action space
304301class BatchMultiAgentEnv (gym .Env ):
305302 metadata = {
306- 'runtime.vectorized' : True ,
303+ 'runtime.vectorized' : True ,
307304 'render.modes' : ['human' , 'rgb_array' ]
308305 }
309306
@@ -320,7 +317,7 @@ def action_space(self):
320317
321318 @property
322319 def observation_space (self ):
323- return self .env_batch [0 ].observation_space
320+ return self .env_batch [0 ].observation_space
324321
325322 def _step (self , action_n , time ):
326323 obs_n = []
@@ -348,4 +345,4 @@ def _render(self, mode='human', close=True):
348345 results_n = []
349346 for env in self .env_batch :
350347 results_n += env .render (mode , close )
351- return results_n
348+ return results_n
0 commit comments