Skip to content
Snippets Groups Projects
Commit 5b64aba3 authored by maljx's avatar maljx
Browse files

fixes to linting errors

parent 854d7139
No related branches found
No related tags found
No related merge requests found
......@@ -284,8 +284,9 @@ class RailEnv:
# 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
# free, i.e., no agent is currently in that cell
if new_position[1] >= self.width or new_position[0] >= self.height or\
new_position[0] < 0 or new_position[1] < 0:
if new_position[1] >= self.width or\
new_position[0] >= self.height or\
new_position[0] < 0 or new_position[1] < 0:
new_cell_isValid = False
elif self.rail[new_position[0]][new_position[1]] > 0:
......
......@@ -245,7 +245,8 @@ class Grid4Transitions(Transitions):
Validity of the requested transition: 0/1 allowed/not allowed.
"""
return ((cell_transition >> ((4-1-orientation) * 4)) >> (4-1-direction)) & 1
return ((cell_transition >> ((4-1-orientation) * 4)) >>
(4-1-direction)) & 1
def set_transition(self, cell_transition, orientation, direction,
new_transition):
......@@ -275,12 +276,12 @@ class Grid4Transitions(Transitions):
"""
if new_transition:
cell_transition |= (1 << ((4-1-orientation) * 4 +
(4 - 1 - direction)))
cell_transition |= (1 << ((4-1-orientation) * 4 +
(4-1-direction)))
else:
cell_transition &= \
~(1 << ((4-1-orientation) * 4 +
(4 - 1 - direction)))
(4-1-direction)))
return cell_transition
......@@ -315,7 +316,7 @@ class Grid4Transitions(Transitions):
# Rotate the 4-bits blocks
value = ((value & (2**(rotation*4)-1)) <<
((4-rotation)*4)) | (value >> (rotation*4))
((4-rotation)*4)) | (value >> (rotation*4))
cell_transition = value
return cell_transition
......@@ -429,7 +430,7 @@ class Grid8Transitions(Transitions):
"""
return ((cell_transition >> ((8-1-orientation) * 8)) >>
(8-1-direction)) & 1
(8-1-direction)) & 1
def set_transition(self, cell_transition, orientation, direction,
new_transition):
......@@ -469,7 +470,7 @@ class Grid8Transitions(Transitions):
def rotate_transition(self, cell_transition, rotation=0):
"""
Clockwise-rotate a 64-bit transition bitmap by
Clockwise-rotate a 64-bit transition bitmap by
rotation={0, 45, 90, 135, 180, 225, 270, 315} degrees.
Parameters
......@@ -500,7 +501,7 @@ class Grid8Transitions(Transitions):
# Rotate the 8bits blocks
value = ((value & (2**(rotation*8)-1)) <<
((8-rotation)*8)) | (value >> (rotation*8))
((8-rotation)*8)) | (value >> (rotation*8))
cell_transition = value
......@@ -540,9 +541,9 @@ class RailEnvTransitions(Grid4Transitions):
int('1000000000100000', 2), # Case 1 - straight
int('1001001000100000', 2), # Case 2 - simple switch
int('1000010000100001', 2), # Case 3 - diamond drossing
int('1001011000100001', 2), # Case 4 - single slip switch
int('1100110000110011', 2), # Case 5 - double slip switch
int('0101001000000010', 2), # Case 6 - symmetrical switch
int('1001011000100001', 2), # Case 4 - single slip
int('1100110000110011', 2), # Case 5 - double slip
int('0101001000000010', 2), # Case 6 - symmetrical
int('0010000000000000', 2)] # Case 7 - dead end
def __init__(self):
......
......@@ -28,17 +28,21 @@ def test_rail_environment_single_agent():
transitions = Grid4Transitions([])
vertical_line = cells[1]
south_symmetrical_switch = cells[6]
north_symmetrical_switch = transitions.rotate_transition(south_symmetrical_switch, 180)
south_east_turn = int('0100000000000010', 2) # Simple turn not in the base transitions ?
north_symmetrical_switch = transitions.rotate_transition(
south_symmetrical_switch, 180)
# Simple turn not in the base transitions ?
south_east_turn = int('0100000000000010', 2)
south_west_turn = transitions.rotate_transition(south_east_turn, 90)
# print(bytes(south_west_turn))
north_east_turn = transitions.rotate_transition(south_east_turn, 270)
north_west_turn = transitions.rotate_transition(south_east_turn, 180)
rail_map = np.array([[south_east_turn, south_symmetrical_switch, south_west_turn],
[vertical_line, vertical_line, vertical_line],
[north_east_turn, north_symmetrical_switch, north_west_turn]],
dtype=np.uint16)
rail_map = np.array([[south_east_turn, south_symmetrical_switch,
south_west_turn],
[vertical_line, vertical_line, vertical_line],
[north_east_turn, north_symmetrical_switch,
north_west_turn]],
dtype=np.uint16)
rail_env = RailEnv(rail_map, number_of_agents=1)
for _ in range(200):
......@@ -47,7 +51,8 @@ def test_rail_environment_single_agent():
# We do not care about target for the moment
rail_env.agents_target[0] = [-1, -1]
# Check that trains are always initialized at a consistent position / direction.
# Check that trains are always initialized at a consistent position
# or direction.
# They should always be able to go somewhere.
assert(transitions.get_transitions(
rail_map[rail_env.agents_position[0]],
......@@ -68,8 +73,8 @@ def test_rail_environment_single_agent():
if prev_pos != pos:
valid_active_actions_done += 1
# After 6 movements on this railway network, the train should be back to its original
# position.
# After 6 movements on this railway network, the train should be back
# to its original position.
assert(initial_pos[0] == rail_env.agents_position[0][0])
# We check that the train always attains its target after some time
......@@ -84,9 +89,3 @@ def test_rail_environment_single_agent():
_, _, dones, _ = rail_env.step({0: action})
done = dones['__all__']
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