Rodrigo Perez-Vicente 2 лет назад
Родитель
Сommit
1d4b596c34
2 измененных файлов с 6 добавлено и 5 удалено
  1. 4 3
      gym_minigrid/minigrid.py
  2. 2 2
      gym_minigrid/window.py

+ 4 - 3
gym_minigrid/minigrid.py

@@ -18,6 +18,7 @@ from gym_minigrid.rendering import (
     point_in_triangle,
     point_in_triangle,
     rotate_fn,
     rotate_fn,
 )
 )
+from gym_minigrid.window import Window
 
 
 TILE_PIXELS = 32
 TILE_PIXELS = 32
 
 
@@ -710,6 +711,8 @@ class MiniGridEnv(gym.Env):
         # Range of possible rewards
         # Range of possible rewards
         self.reward_range = (0, 1)
         self.reward_range = (0, 1)
 
 
+        self.window: Window = None
+
         # Environment configuration
         # Environment configuration
         self.width = width
         self.width = width
         self.height = height
         self.height = height
@@ -1248,9 +1251,7 @@ class MiniGridEnv(gym.Env):
             return
             return
 
 
         if mode == "human" and not self.window:
         if mode == "human" and not self.window:
-            import gym_minigrid.window
-
-            self.window = gym_minigrid.window.Window("gym_minigrid")
+            self.window = Window("gym_minigrid")
             self.window.show(block=False)
             self.window.show(block=False)
 
 
         # Compute which cells are visible to the agent
         # Compute which cells are visible to the agent

+ 2 - 2
gym_minigrid/window.py

@@ -42,9 +42,9 @@ class Window:
 
 
         # If no image has been shown yet,
         # If no image has been shown yet,
         # show the first image of the environment
         # show the first image of the environment
-        if self.imshow_obj is None:
+        if self.no_image_shown:
             self.imshow_obj = self.ax.imshow(img, interpolation="bilinear")
             self.imshow_obj = self.ax.imshow(img, interpolation="bilinear")
-
+            self.no_image_shown = False
         # Update the image data
         # Update the image data
         self.imshow_obj.set_data(img)
         self.imshow_obj.set_data(img)