소스 검색

Unlock (#20)

* Obstructed maze environment

* Add unlock environment

* Fix env id
Lucas Willems 6 년 전
부모
커밋
2a3c7dc685
3개의 변경된 파일55개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      README.md
  2. 1 0
      gym_minigrid/envs/__init__.py
  3. 46 0
      gym_minigrid/envs/unlock.py

+ 8 - 0
README.md

@@ -251,6 +251,14 @@ 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.
 
+### Unlock environment
+
+Registed configurations:
+- `MiniGrid-Unlock-v0`
+
+The agent has to open a locked door. This environment can be solved without
+relying on language.
+
 ### Blocked unlock pickup environment
 
 Registed configurations:

+ 1 - 0
gym_minigrid/envs/__init__.py

@@ -7,6 +7,7 @@ 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.unlock import *
 from gym_minigrid.envs.blockedunlockpickup import *
 from gym_minigrid.envs.playground_v0 import *
 from gym_minigrid.envs.redbluedoors import *

+ 46 - 0
gym_minigrid/envs/unlock.py

@@ -0,0 +1,46 @@
+from gym_minigrid.minigrid import Ball
+from gym_minigrid.roomgrid import RoomGrid
+from gym_minigrid.register import register
+
+class Unlock(RoomGrid):
+    """
+    Unlock a door
+    """
+
+    def __init__(self, seed=None):
+        room_size = 6
+        super().__init__(
+            num_rows=1,
+            num_cols=2,
+            room_size=room_size,
+            max_steps=8*room_size**2,
+            seed=seed
+        )
+
+    def _gen_grid(self, width, height):
+        super()._gen_grid(width, height)
+
+        # Make sure the two rooms are directly connected by a locked door
+        door, _ = self.add_door(0, 0, 0, locked=True)
+        # Add a key to unlock the door
+        self.add_object(0, 0, 'key', door.color)
+
+        self.place_agent(0, 0)
+
+        self.door = door
+        self.mission = "open the door"
+
+    def step(self, action):
+        obs, reward, done, info = super().step(action)
+
+        if action == self.actions.toggle:
+            if self.door.is_open:
+                reward = self._reward()
+                done = True
+
+        return obs, reward, done, info
+
+register(
+    id='MiniGrid-Unlock-v0',
+    entry_point='gym_minigrid.envs:Unlock'
+)