empty.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from gym_minigrid.minigrid import *
  2. from gym_minigrid.register import register
  3. class EmptyEnv(MiniGridEnv):
  4. """
  5. Empty grid environment, no obstacles, sparse reward
  6. """
  7. def __init__(self, size=8):
  8. super().__init__(
  9. grid_size=size,
  10. max_steps=4*size*size,
  11. # Set this to True for maximum speed
  12. see_through_walls=True
  13. )
  14. def _gen_grid(self, width, height):
  15. # Create an empty grid
  16. self.grid = Grid(width, height)
  17. # Generate the surrounding walls
  18. self.grid.wall_rect(0, 0, width, height)
  19. # Place the agent in the top-left corner
  20. self.start_pos = (1, 1)
  21. self.start_dir = 0
  22. # Place a goal square in the bottom-right corner
  23. self.grid.set(width - 2, height - 2, Goal())
  24. self.mission = "get to the green goal square"
  25. class EmptyEnv6x6(EmptyEnv):
  26. def __init__(self):
  27. super().__init__(size=6)
  28. class EmptyEnv16x16(EmptyEnv):
  29. def __init__(self):
  30. super().__init__(size=16)
  31. register(
  32. id='MiniGrid-Empty-6x6-v0',
  33. entry_point='gym_minigrid.envs:EmptyEnv6x6'
  34. )
  35. register(
  36. id='MiniGrid-Empty-8x8-v0',
  37. entry_point='gym_minigrid.envs:EmptyEnv'
  38. )
  39. register(
  40. id='MiniGrid-Empty-16x16-v0',
  41. entry_point='gym_minigrid.envs:EmptyEnv16x16'
  42. )