Commit dceceb86 authored by Erik Nygren's avatar Erik Nygren
Browse files

added curves to rail_env.py step function

parent 0ad69215
...@@ -30,13 +30,13 @@ env = RailEnv(width=20, ...@@ -30,13 +30,13 @@ env = RailEnv(width=20,
rail_generator=complex_rail_generator(nr_start_goal=20, min_dist=10, max_dist=99999, seed=0), rail_generator=complex_rail_generator(nr_start_goal=20, min_dist=10, max_dist=99999, seed=0),
number_of_agents=5) number_of_agents=5)
"""
env = RailEnv(width=20, env = RailEnv(width=20,
height=20, height=20,
rail_generator=rail_from_list_of_saved_GridTransitionMap_generator( rail_generator=rail_from_list_of_saved_GridTransitionMap_generator(
['../env-data/tests/test_rail.npy']), ['../env-data/tests/train_simple.npy']),
number_of_agents=1) number_of_agents=1)
"""
env_renderer = RenderTool(env, gl="QT") env_renderer = RenderTool(env, gl="QT")
handle = env.get_agent_handles() handle = env.get_agent_handles()
......
...@@ -1053,6 +1053,21 @@ class RailEnv(Environment): ...@@ -1053,6 +1053,21 @@ class RailEnv(Environment):
direction = reverse_direction direction = reverse_direction
movement = reverse_direction movement = reverse_direction
is_deadend = True is_deadend = True
if nbits == 2:
# straigt or curve
valid_transition = self.rail.get_transition(
(pos[0], pos[1], direction),
movement)
reverse_direction = (direction + 2) % 4
curv_dir = (movement + 1) % 4
while not valid_transition:
if curv_dir != reverse_direction:
valid_transition = self.rail.get_transition(
(pos[0], pos[1], direction),
curv_dir)
curv_dir = (curv_dir+1) % 4
if valid_transition:
movement = curv_dir
new_position = self._new_position(pos, movement) new_position = self._new_position(pos, movement)
# Is it a legal move? 1) transition allows the movement in the # Is it a legal move? 1) transition allows the movement in the
# cell, 2) the new cell is not empty (case 0), 3) the cell is # cell, 2) the new cell is not empty (case 0), 3) the cell is
......
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