Commit a8d5dc4f authored by Erik Nygren's avatar Erik Nygren 🚅
Browse files

fixed bug in step function. Now checking if cell is free before moving out of...

fixed bug in step function. Now checking if cell is free before moving out of cell into the next one.
parent dbb8e4c9
Pipeline #1201 failed with stages
in 5 minutes and 52 seconds
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment