diff --git a/examples/play_model.py b/examples/play_model.py index 08dadeb1d3d1e64b012c00e99594bcefd2905d1c..5e2d898db02969138bfa2112055f531967320306 100644 --- a/examples/play_model.py +++ b/examples/play_model.py @@ -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) diff --git a/flatland/envs/agent_utils.py b/flatland/envs/agent_utils.py index db7f9ae05483f4b4879e24f93716a384690f6432..a4dc6962ebd69b38008c684e8015fc2c3e1b5d43 100644 --- a/flatland/envs/agent_utils.py +++ b/flatland/envs/agent_utils.py @@ -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): diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 89feaab01e6512226d2037185850c211e2d9c274..a23b6ac71651e8e424bb90a23cbcfd472ce89a12 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -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 diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 294251e4c1f9e138cdd3174e642eab6bd9c1f8c3..84718813faf284fe90455aa02d6d1039a29d11f7 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -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. diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 03c1c63dfc60b4fe1a867d0cfb83d54fe9dbf30e..a8f9f1cbc5158275ae45539d41a1607b775b22ef 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -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()