浏览代码

Fixed issue causing dynamic obstacles env to crash

Maxime Chevalier-Boisvert 6 年之前
父节点
当前提交
ba8b8e2316
共有 3 个文件被更改,包括 6 次插入11 次删除
  1. 2 1
      README.md
  2. 二进制
      figures/dynamic_obstacles.gif
  3. 4 10
      gym_minigrid/envs/dynamicobstacles.py

+ 2 - 1
README.md

@@ -141,6 +141,7 @@ position for each episode, while the regular variants have the agent always
 starting in the corner opposite to the goal.
 
 ### Dynamic obstacles environment
+
 Registered configurations:
 - `MiniGrid-Dynamic-Obstacles-5x5-v0`
 - `MiniGrid-Dynamic-Obstacles-Random-5x5-v0`
@@ -150,7 +151,7 @@ Registered configurations:
 - `MiniGrid-Dynamic-Obstacles-16x16-v0`
 
 <p align="center">
-<img src="https://media.giphy.com/media/NUvVVRNTW4cG0NoQBr/giphy.gif">
+<img src="/figures/dynamic_obstacles.gif">
 </p>
 
 This environment is an empty room with moving obstacles. The goal of the agent is to reach the green goal square without colliding with any obstacle. A large penalty is subtracted if the agent collides with an obstacle and the episode finishes. This environment is useful to test Dynamic Obstacle Avoidance for mobile robots with Reinforcement Learning in Partial Observability.

二进制
figures/dynamic_obstacles.gif


+ 4 - 10
gym_minigrid/envs/dynamicobstacles.py

@@ -2,10 +2,9 @@ from gym_minigrid.minigrid import *
 from gym_minigrid.register import register
 from operator import add
 
-
 class DynamicObstaclesEnv(MiniGridEnv):
     """
-    Empty grid environment with moving obstacles
+    Single-room square grid environment with moving obstacles
     """
 
     def __init__(
@@ -68,39 +67,34 @@ class DynamicObstaclesEnv(MiniGridEnv):
             for i_obst in range(len(self.obstacles)):
                 old_pos = self.obstacles[i_obst].cur_pos
                 top = tuple(map(add, old_pos, (-1, -1)))
+                self.grid.set(*old_pos, None)
                 self.place_obj(self.obstacles[i_obst], top=top, size=(3,3), max_tries=100)
-                self.grid.set(old_pos[0], old_pos[1], None)
                 if np.array_equal(self.obstacles[i_obst].cur_pos, self.agent_pos):
                     reward = -1
                     done = True
-        return obs, reward, done, info
 
+        return obs, reward, done, info
 
 class DynamicObstaclesEnv5x5(DynamicObstaclesEnv):
     def __init__(self):
         super().__init__(size=5, n_obstacles=2)
 
-
 class DynamicObstaclesRandomEnv5x5(DynamicObstaclesEnv):
     def __init__(self):
         super().__init__(size=5, agent_start_pos=None, n_obstacles=2)
 
-
 class DynamicObstaclesEnv6x6(DynamicObstaclesEnv):
     def __init__(self):
         super().__init__(size=6, n_obstacles=3)
 
-
 class DynamicObstaclesRandomEnv6x6(DynamicObstaclesEnv):
     def __init__(self):
         super().__init__(size=6, agent_start_pos=None, n_obstacles=3)
 
-
 class DynamicObstaclesEnv16x16(DynamicObstaclesEnv):
     def __init__(self):
         super().__init__(size=16, n_obstacles=8)
 
-
 register(
     id='MiniGrid-Dynamic-Obstacles-5x5-v0',
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv5x5'
@@ -129,4 +123,4 @@ register(
 register(
     id='MiniGrid-Dynamic-Obstacles-16x16-v0',
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv16x16'
-)
+)