empty.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from gym_minigrid.minigrid import Goal, Grid, MiniGridEnv, MissionSpace
  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. mission_space = MissionSpace(
  10. mission_func=lambda: "get to the green goal square"
  11. )
  12. super().__init__(
  13. mission_space=mission_space,
  14. grid_size=size,
  15. max_steps=4 * size * size,
  16. # Set this to True for maximum speed
  17. see_through_walls=True,
  18. **kwargs
  19. )
  20. def _gen_grid(self, width, height):
  21. # Create an empty grid
  22. self.grid = Grid(width, height)
  23. # Generate the surrounding walls
  24. self.grid.wall_rect(0, 0, width, height)
  25. # Place a goal square in the bottom-right corner
  26. self.put_obj(Goal(), width - 2, height - 2)
  27. # Place the agent
  28. if self.agent_start_pos is not None:
  29. self.agent_pos = self.agent_start_pos
  30. self.agent_dir = self.agent_start_dir
  31. else:
  32. self.place_agent()
  33. self.mission = "get to the green goal square"