Browse Source

Added variants of empty env with random starting position.

Maxime Chevalier-Boisvert 6 years ago
parent
commit
ef3d3f039a
2 changed files with 50 additions and 6 deletions
  1. 7 1
      README.md
  2. 43 5
      gym_minigrid/envs/empty.py

+ 7 - 1
README.md

@@ -120,7 +120,10 @@ or to fine-tune difficulty.
 ### Empty environment
 ### Empty environment
 
 
 Registered configurations:
 Registered configurations:
+- `MiniGrid-Empty-5x5-v0`
+- `MiniGrid-Empty-Random-5x5-v0`
 - `MiniGrid-Empty-6x6-v0`
 - `MiniGrid-Empty-6x6-v0`
+- `MiniGrid-Empty-Random-6x6-v0`
 - `MiniGrid-Empty-8x8-v0`
 - `MiniGrid-Empty-8x8-v0`
 - `MiniGrid-Empty-16x16-v0`
 - `MiniGrid-Empty-16x16-v0`
 
 
@@ -132,7 +135,10 @@ This environment is an empty room, and the goal of the agent is to reach the
 green goal square, which provides a sparse reward. A small penalty is
 green goal square, which provides a sparse reward. A small penalty is
 subtracted for the number of steps to reach the goal. This environment is
 subtracted for the number of steps to reach the goal. This environment is
 useful, with small rooms, to validate that your RL algorithm works correctly,
 useful, with small rooms, to validate that your RL algorithm works correctly,
-and with large rooms to experiment with sparse rewards.
+and with large rooms to experiment with sparse rewards and exploration.
+The random variants of the environment have the agent starting at a random
+position for each episode, while the regular variants have the agent always
+starting in the corner opposite to the goal.
 
 
 ### Door & key environment
 ### Door & key environment
 
 

+ 43 - 5
gym_minigrid/envs/empty.py

@@ -6,7 +6,15 @@ class EmptyEnv(MiniGridEnv):
     Empty grid environment, no obstacles, sparse reward
     Empty grid environment, no obstacles, sparse reward
     """
     """
 
 
-    def __init__(self, size=8):
+    def __init__(
+        self,
+        size=8,
+        agent_start_pos=(1,1),
+        agent_start_dir=0,
+    ):
+        self.agent_start_pos = agent_start_pos
+        self.agent_start_dir = agent_start_dir
+
         super().__init__(
         super().__init__(
             grid_size=size,
             grid_size=size,
             max_steps=4*size*size,
             max_steps=4*size*size,
@@ -21,29 +29,59 @@ class EmptyEnv(MiniGridEnv):
         # Generate the surrounding walls
         # Generate the surrounding walls
         self.grid.wall_rect(0, 0, width, height)
         self.grid.wall_rect(0, 0, width, height)
 
 
-        # Place the agent in the top-left corner
-        self.start_pos = (1, 1)
-        self.start_dir = 0
-
         # Place a goal square in the bottom-right corner
         # Place a goal square in the bottom-right corner
         self.grid.set(width - 2, height - 2, Goal())
         self.grid.set(width - 2, height - 2, Goal())
 
 
+        # Place the agent
+        if self.agent_start_pos is not None:
+            self.start_pos = self.agent_start_pos
+            self.start_dir = self.agent_start_dir
+        else:
+            self.place_agent()
+
         self.mission = "get to the green goal square"
         self.mission = "get to the green goal square"
 
 
+class EmptyEnv5x5(EmptyEnv):
+    def __init__(self):
+        super().__init__(size=5)
+
+class EmptyRandomEnv5x5(EmptyEnv):
+    def __init__(self):
+        super().__init__(size=5, agent_start_pos=None)
+
 class EmptyEnv6x6(EmptyEnv):
 class EmptyEnv6x6(EmptyEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=6)
         super().__init__(size=6)
 
 
+class EmptyRandomEnv6x6(EmptyEnv):
+    def __init__(self):
+        super().__init__(size=6, agent_start_pos=None)
+
 class EmptyEnv16x16(EmptyEnv):
 class EmptyEnv16x16(EmptyEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=16)
         super().__init__(size=16)
 
 
 register(
 register(
+    id='MiniGrid-Empty-5x5-v0',
+    entry_point='gym_minigrid.envs:EmptyEnv5x5'
+)
+
+register(
+    id='MiniGrid-Empty-Random-5x5-v0',
+    entry_point='gym_minigrid.envs:EmptyRandomEnv5x5'
+)
+
+register(
     id='MiniGrid-Empty-6x6-v0',
     id='MiniGrid-Empty-6x6-v0',
     entry_point='gym_minigrid.envs:EmptyEnv6x6'
     entry_point='gym_minigrid.envs:EmptyEnv6x6'
 )
 )
 
 
 register(
 register(
+    id='MiniGrid-Empty-Random-6x6-v0',
+    entry_point='gym_minigrid.envs:EmptyRandomEnv6x6'
+)
+
+register(
     id='MiniGrid-Empty-8x8-v0',
     id='MiniGrid-Empty-8x8-v0',
     entry_point='gym_minigrid.envs:EmptyEnv'
     entry_point='gym_minigrid.envs:EmptyEnv'
 )
 )