From a8d5dc4f7b364df30b7ce6d8df91272f919d5321 Mon Sep 17 00:00:00 2001 From: MLErik <baerenjesus@gmail.com> Date: Sat, 22 Jun 2019 09:22:09 -0500 Subject: [PATCH] fixed bug in step function. Now checking if cell is free before moving out of cell into the next one. --- flatland/envs/rail_env.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 05738ecc..fccf6b89 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -191,7 +191,8 @@ class RailEnv(Environment): # for i in range(len(self.agents_handles)): for iAgent in range(self.get_num_agents()): agent = self.agents[iAgent] - + if iAgent % 2 == 0: + agent.speed_data["speed"] = 1./3. if self.dones[iAgent]: # this agent has already completed... continue @@ -269,7 +270,7 @@ class RailEnv(Environment): agent.speed_data['position_fraction'] += agent.speed_data['speed'] if agent.speed_data['position_fraction'] >= 1.0: - agent.speed_data['position_fraction'] = 0.0 + # Perform stored action to transition to the next cell @@ -277,10 +278,15 @@ class RailEnv(Environment): # the cell cell_isFree, new_cell_isValid, new_direction, new_position, transition_isValid = \ self._check_action_on_agent(agent.speed_data['transition_action_on_cellexit'], agent) - agent.old_direction = agent.direction - agent.old_position = agent.position - agent.position = new_position - agent.direction = new_direction + + if all([new_cell_isValid, transition_isValid, cell_isFree]): + agent.old_direction = agent.direction + agent.old_position = agent.position + agent.position = new_position + agent.direction = new_direction + agent.speed_data['position_fraction'] = 0.0 + + if np.equal(agent.position, agent.target).all(): self.dones[iAgent] = True -- GitLab