Browse Source

Draw boxes

Maxime Chevalier-Boisvert 5 years ago
parent
commit
220af251f5
4 changed files with 24 additions and 29 deletions
  1. 2 2
      README.md
  2. 1 1
      benchmark.py
  3. 8 20
      gym_minigrid/minigrid.py
  4. 13 6
      manual_control.py

+ 2 - 2
README.md

@@ -70,10 +70,10 @@ There is a UI application which allows you to manually control the agent with th
 ./manual_control.py
 ```
 
-The environment being run can be selected with the `--env-name` option, eg:
+The environment being run can be selected with the `--env_name` option, eg:
 
 ```
-./manual_control.py --env-name MiniGrid-Empty-8x8-v0
+./manual_control.py --env_name MiniGrid-Empty-8x8-v0
 ```
 
 ## Reinforcement Learning

+ 1 - 1
benchmark.py

@@ -10,7 +10,7 @@ parser.add_argument(
     "--env-name",
     dest="env_name",
     help="gym environment to load",
-    default='MiniGrid-DoorKey-8x8-v0'
+    default='MiniGrid-LavaGapS7-v0'
 )
 parser.add_argument("--num_frames", default=2000)
 args = parser.parse_args()

+ 8 - 20
gym_minigrid/minigrid.py

@@ -339,27 +339,15 @@ class Box(WorldObj):
     def can_pickup(self):
         return True
 
-    def render(self, r):
+    def render(self, img):
         c = COLORS[self.color]
-        r.setLineColor(c[0], c[1], c[2])
-        r.setColor(0, 0, 0)
-        r.setLineWidth(2)
-
-        r.drawPolygon([
-            (4            , TILE_PIXELS-4),
-            (TILE_PIXELS-4, TILE_PIXELS-4),
-            (TILE_PIXELS-4,             4),
-            (4            ,             4)
-        ])
 
-        r.drawLine(
-            4,
-            TILE_PIXELS / 2,
-            TILE_PIXELS - 4,
-            TILE_PIXELS / 2
-        )
+        # Outline
+        fill_coords(img, point_in_rect(0.12, 0.88, 0.12, 0.88), c)
+        fill_coords(img, point_in_rect(0.18, 0.82, 0.18, 0.82), (0,0,0))
 
-        r.setLineWidth(1)
+        # Vertical slit
+        fill_coords(img, point_in_rect(0.48, 0.52, 0.16, 0.84), c)
 
     def toggle(self, env, pos):
         # Replace the box by its contents
@@ -540,8 +528,8 @@ class Grid:
             highlight_mask = np.zeros(shape=(self.width, self.height), dtype=np.bool)
 
         # Compute the total grid size
-        width_px = self.width * TILE_PIXELS
-        height_px = self.height * TILE_PIXELS
+        width_px = self.width * tile_size
+        height_px = self.height * tile_size
 
         img = np.zeros(shape=(height_px, width_px, 3), dtype=np.uint8)
 

+ 13 - 6
manual_control.py

@@ -14,7 +14,7 @@ def reset():
         print('Mission: %s' % env.mission)
         plt.xlabel(env.mission)
 
-    img = env.render('rgb_array')
+    img = env.render('rgb_array', tile_size=args.tile_size)
     imshow_obj.set_data(img)
     fig.canvas.draw()
 
@@ -26,7 +26,7 @@ def step(action):
         print('done!')
         reset()
 
-    img = env.render('rgb_array')
+    img = env.render('rgb_array', tile_size=args.tile_size)
     imshow_obj.set_data(img)
     fig.canvas.draw()
 
@@ -68,13 +68,18 @@ def key_handler(event):
 
 parser = argparse.ArgumentParser()
 parser.add_argument(
-    "-e",
-    "--env-name",
-    dest="env_name",
+    "--env_name",
     help="gym environment to load",
     #default='MiniGrid-MultiRoom-N6-v0'
     default='MiniGrid-KeyCorridorS3R3-v0'
 )
+parser.add_argument(
+    "--tile_size",
+    type=int,
+    help="size at which to render tiles",
+    default=32
+)
+
 args = parser.parse_args()
 
 env = gym.make(args.env_name)
@@ -91,8 +96,10 @@ fig.canvas.set_window_title('gym_minigrid - ' + args.env_name)
 ax.set_xticks([], [])
 ax.set_yticks([], [])
 
+print(args.tile_size)
+
 # Show the first image of the environment
-img = env.render('rgb_array')
+img = env.render('rgb_array', tile_size=args.tile_size)
 imshow_obj = ax.imshow(img, interpolation='bilinear')
 
 reset()