empty.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from gym_minigrid.minigrid import Goal, Grid, MiniGridEnv
  2. class EmptyEnv(MiniGridEnv):
  3. """
  4. Empty grid environment, no obstacles, sparse reward
  5. """
  6. def __init__(self, size=8, agent_start_pos=(1, 1), agent_start_dir=0, **kwargs):
  7. self.agent_start_pos = agent_start_pos
  8. self.agent_start_dir = agent_start_dir
  9. super().__init__(
  10. grid_size=size,
  11. max_steps=4 * size * size,
  12. # Set this to True for maximum speed
  13. see_through_walls=True,
  14. **kwargs
  15. )
  16. def _gen_grid(self, width, height):
  17. # Create an empty grid
  18. self.grid = Grid(width, height)
  19. # Generate the surrounding walls
  20. self.grid.wall_rect(0, 0, width, height)
  21. # Place a goal square in the bottom-right corner
  22. self.put_obj(Goal(), width - 2, height - 2)
  23. # Place the agent
  24. if self.agent_start_pos is not None:
  25. self.agent_pos = self.agent_start_pos
  26. self.agent_dir = self.agent_start_dir
  27. else:
  28. self.place_agent()
  29. self.mission = "get to the green goal square"