-
Notifications
You must be signed in to change notification settings - Fork 61
Description
It seems that negative or out of edge position will result index error in _is_valid() method, because of the passable check.
I think it should be changed to
def _is_valid(self, position):
nonnegative = position[0] >= 0 and position[1] >= 0
within_edge = position[0] < self.maze.size[0] and position[1] < self.maze.size[1]
if (nonnegative and within_edge):
passable = not self.maze.to_impassable()[position[0]][position[1]]
else:
passable = False
return nonnegative and within_edge and passable
IndexError Traceback (most recent call last)
in
35 action = agent.act(state, epsilon)
36
---> 37 _, reward, done, _ = env.step(action)
38 next_state = env.unwrapped.maze.objects.agent.positions[0]
39
//anaconda3/lib/python3.7/site-packages/gym/wrappers/time_limit.py in step(self, action)
14 def step(self, action):
15 assert self._elapsed_steps is not None, "Cannot call env.step() before calling reset()"
---> 16 observation, reward, done, info = self.env.step(action)
17 self._elapsed_steps += 1
18 if self._elapsed_steps >= self._max_episode_steps:
in step(self, action)
21 current_position = self.maze.objects.agent.positions[0]
22 new_position = [current_position[0] + motion[0], current_position[1] + motion[1]]
---> 23 valid = self._is_valid(new_position)
24 if valid:
25 self.maze.objects.agent.positions = [new_position]
in _is_valid(self, position)
44 nonnegative = position[0] >= 0 and position[1] >= 0
45 within_edge = position[0] < self.maze.size[0] and position[1] < self.maze.size[1]
---> 46 passable = not self.maze.to_impassable()[position[0]][position[1]]
47 return nonnegative and within_edge and passable
48
IndexError: index 6 is out of bounds for axis 0 with size 6