44import numpy as np
55import tensorflow as tf
66
7- # TODO: make description of class?
8-
97# environment for all agents in the multiagent world
10- # TODO: currently code assumes that no agents will be created/destroyed at runtime!
8+ # currently code assumes that no agents will be created/destroyed at runtime!
119class MultiAgentEnv (gym .Env ):
1210 metadata = {
1311 'render.modes' : ['human' , 'rgb_array' ]
@@ -94,6 +92,7 @@ def _step(self, action_n):
9492 obs_n .append (self ._get_obs (agent ))
9593 reward_n .append (self ._get_reward (agent ))
9694 done_n .append (False )
95+
9796 info_n ['n' ].append (self ._get_info (agent ))
9897
9998 # all agents get total reward in cooperative case
@@ -146,13 +145,12 @@ def _set_action(self, action, agent, action_space, time=None):
146145 act .append (action [index :(index + s )])
147146 index += s
148147 action = act
149- # else:
150- # action = [action] # TODO: why is this necessary??
148+ else :
149+ action = [action ] # TODO: why is this necessary??
151150
152151 if agent .movable :
153152 # physical action
154153 if self .discrete_action_input :
155- print (action )
156154 agent .action .u = np .zeros (self .world .dim_p )
157155 # process discrete action
158156 if action [0 ] == 1 : agent .action .u [0 ] = - 1.0
@@ -190,7 +188,6 @@ def _reset_render(self):
190188
191189 # render environment
192190 def _render (self , mode = 'human' , close = True ):
193- # TODO: render text in viewer instead
194191 if mode == 'human' :
195192 alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
196193 message = ''
@@ -231,10 +228,7 @@ def _render(self, mode='human', close=True):
231228 for entity in self .world .entities :
232229 geom = rendering .make_circle (entity .size )
233230 xform = rendering .Transform ()
234- if 'forest' in entity .name :
235- print (entity .color )
236- geom .set_color (* entity .color , alpha = 0.5 )
237- elif 'agent' in entity .name :
231+ if 'agent' in entity .name :
238232 geom .set_color (* entity .color , alpha = 0.5 )
239233 else :
240234 geom .set_color (* entity .color )
@@ -252,7 +246,7 @@ def _render(self, mode='human', close=True):
252246 for i in range (len (self .viewers )):
253247 from multiagent import rendering
254248 # update bounds to center around agent
255- cam_range = 1.2
249+ cam_range = 1
256250 if self .shared_viewer :
257251 pos = np .zeros (self .world .dim_p )
258252 else :
0 commit comments