소스 검색

Made it so agent can see what it is carrying in observations

This helps performance on the DoorKey-6x6 task. The agent can
use the fact that it is carrying a key to inform its policy.
Maxime Chevalier-Boisvert 7 년 전
부모
커밋
25cc3b5253
2개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      basicrl/envs.py
  2. 10 0
      gym_minigrid/minigrid.py

+ 1 - 1
basicrl/envs.py

@@ -35,7 +35,7 @@ def make_env(env_id, seed, rank, log_dir):
         if len(obs_shape) == 3 and obs_shape[2] == 3:
             env = WrapPyTorch(env)
 
-        env = StateBonus(env)
+        #env = StateBonus(env)
 
         return env
 

+ 10 - 0
gym_minigrid/minigrid.py

@@ -707,6 +707,16 @@ class MiniGridEnv(gym.Env):
         for i in range(self.agentDir + 1):
             grid = grid.rotateLeft()
 
+        # Make it so the agent sees what it's carrying
+        # We do this by placing the carried object at the agent's position
+        # in the agent's partially observable view
+        agentPos = grid.width // 2, grid.height - 1
+        if self.carrying:
+            grid.set(*agentPos, self.carrying)
+        else:
+            grid.set(*agentPos, None)
+
+        # Encode the partially observable view into a numpy array
         obs = grid.encode()
 
         return obs