Skip to content
Snippets Groups Projects
Commit 14c04600 authored by hagrid67's avatar hagrid67
Browse files

changed renderer to use agent.old_position instead of actions,

also implies that agents are drawn in their old locations, ie from previous timestep
parent 8fefaeef
No related branches found
No related tags found
No related merge requests found
......@@ -277,4 +277,4 @@ def main_old(render=True, delay=0.0):
if __name__ == "__main__":
main(render=True, delay=0.5)
main(render=True, delay=0)
......@@ -66,14 +66,18 @@ class EnvAgent(EnvAgentStatic):
"""
handle = attrib(default=None)
old_direction = attrib(default=None)
old_position = attrib(default=None)
def __init__(self, position, direction, target, handle, old_direction):
def __init__(self, position, direction, target, handle, old_direction, old_position):
super(EnvAgent, self).__init__(position, direction, target)
self.handle = handle
self.old_direction = old_direction
self.old_position = old_position
def to_list(self):
return [self.position, self.direction, self.target, self.handle, self.old_direction]
return [
self.position, self.direction, self.target, self.handle,
self.old_direction, self.old_position]
@classmethod
def from_static(cls, oStatic):
......
......@@ -263,8 +263,9 @@ class RailEnv(Environment):
# performed
# self.agents_position[i] = new_position
# self.agents_direction[i] = new_direction
agent.position = new_position
agent.old_direction = agent.direction
agent.old_position = agent.position
agent.position = new_position
agent.direction = new_direction
else:
# the action was not valid, add penalty
......
......@@ -325,7 +325,7 @@ class PILSVG(PILGL):
rgbaZug3[xy_color_mask, 0:3] = tnNewColor
self.dPilZug[(iDirIn2, iDirOut2, iColor)] = Image.fromarray(rgbaZug3)
def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut, color=None):
def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut):
delta_dir = (iDirOut - iDirIn) % 4
iColor = iAgent % self.nAgentColors
# when flipping direction at a dead end, use the "iDirOut" direction.
......
......@@ -757,35 +757,20 @@ class RenderTool(object):
binTrans = env.rail.grid[r, c]
self.gl.setRailAt(r, c, binTrans)
cmap = self.gl.get_cmap('hsv',
lut=max(len(self.env.agents), len(self.env.agents_static) + 1))
for iAgent, agent in enumerate(self.env.agents):
if agent is None:
continue
oColor = self.gl.adaptColor(cmap(iAgent))
new_direction = agent.direction
action_isValid = False
if iAgent in action_dict:
iAction = action_dict[iAgent]
new_direction, action_isValid = self.env.check_action(agent, iAction)
# ** TODO ***
# why should we only update if the action is valid ?
if True:
if action_isValid:
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor)
else:
# pass
print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction)
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction)
if agent.old_position is not None:
position = agent.old_position
direction = agent.direction
old_direction = agent.old_direction
else:
print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction)
self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction, color=oColor)
# self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction)
position = agent.position
direction = agent.direction
old_direction = agent.direction
self.gl.setAgentAt(iAgent, *position, old_direction, direction)
if show:
self.gl.show()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment