Browse Source

Added BlockedUnlockPickup environment

Maxime Chevalier-Boisvert 6 years ago
parent
commit
475adf182c
3 changed files with 64 additions and 0 deletions
  1. 11 0
      README.md
  2. 1 0
      gym_minigrid/envs/__init__.py
  3. 52 0
      gym_minigrid/envs/blockedunlockpickup.py

+ 11 - 0
README.md

@@ -251,3 +251,14 @@ The agent has to pick up an object which is behind a locked door. The key is
 hidden in another room, and the agent has to explore the environment to find
 it. The mission string does not give the agent any clues as to where the
 key is placed. This environment can be solved without relying on language.
+
+### Blocked unlock pickup environment
+
+Registed configurations:
+- `MiniGrid-BlockedUnlockPickup-v0`
+
+The agent has to pick up a box which is placed in another room, behind a
+locked door. The door is also blocked by a ball which the agent has to move
+before it can unlock the door. Hence, the agent has to learn to move the ball,
+pick up the key, open the door and pick up the object in the other room.
+This environment can be solved without relying on language.

+ 1 - 0
gym_minigrid/envs/__init__.py

@@ -7,5 +7,6 @@ from gym_minigrid.envs.gotodoor import *
 from gym_minigrid.envs.putnear import *
 from gym_minigrid.envs.lockedroom import *
 from gym_minigrid.envs.keycorridor import *
+from gym_minigrid.envs.blockedunlockpickup import *
 from gym_minigrid.envs.playground_v0 import *
 from gym_minigrid.envs.redbluedoors import *

+ 52 - 0
gym_minigrid/envs/blockedunlockpickup.py

@@ -0,0 +1,52 @@
+from gym_minigrid.minigrid import Ball
+from gym_minigrid.roomgrid import RoomGrid
+from gym_minigrid.register import register
+
+class BlockedUnlockPickup(RoomGrid):
+    """
+    Unlock a door blocked by a ball, then pick up a box
+    in another room
+    """
+
+    def __init__(self, seed=None):
+        room_size = 6
+        super().__init__(
+            num_rows=1,
+            num_cols=2,
+            room_size=room_size,
+            max_steps=16*room_size**2,
+            seed=seed
+        )
+
+    def _gen_grid(self, width, height):
+        super()._gen_grid(width, height)
+
+        # Add a box to the room on the right
+        obj, _ = self.add_object(1, 0, kind="box")
+        # Make sure the two rooms are directly connected by a locked door
+        door, pos = self.add_door(0, 0, 0, locked=True)
+        # Block the door with a ball
+        color = self._rand_color()
+        self.grid.set(pos[0]-1, pos[1], Ball(color))
+        # Add a key to unlock the door
+        self.add_object(0, 0, 'key', door.color)
+
+        self.place_agent(0, 0)
+
+        self.obj = obj
+        self.mission = "pick up the %s %s" % (obj.color, obj.type)
+
+    def step(self, action):
+        obs, reward, done, info = super().step(action)
+
+        if action == self.actions.pickup:
+            if self.carrying and self.carrying == self.obj:
+                reward = self._reward()
+                done = True
+
+        return obs, reward, done, info
+
+register(
+    id='MiniGrid-BlockedUnlockPickup-v0',
+    entry_point='gym_minigrid.envs:BlockedUnlockPickup'
+)