empty.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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__(gridSize=size, maxSteps=3*size)
  9. def _genGrid(self, width, height):
  10. # Create an empty grid
  11. grid = Grid(width, height)
  12. # Place walls around the edges
  13. for i in range(0, width):
  14. grid.set(i, 0, Wall())
  15. grid.set(i, height - 1, Wall())
  16. for j in range(0, height):
  17. grid.set(0, j, Wall())
  18. grid.set(height - 1, j, Wall())
  19. # Place a goal in the bottom-right corner
  20. grid.set(width - 2, height - 2, Goal())
  21. return grid
  22. class EmptyEnv6x6(EmptyEnv):
  23. def __init__(self):
  24. super().__init__(size=6)
  25. class EmptyEnv16x16(EmptyEnv):
  26. def __init__(self):
  27. super().__init__(size=16)
  28. register(
  29. id='MiniGrid-Empty-6x6-v0',
  30. entry_point='gym_minigrid.envs:EmptyEnv6x6'
  31. )
  32. register(
  33. id='MiniGrid-Empty-8x8-v0',
  34. entry_point='gym_minigrid.envs:EmptyEnv'
  35. )
  36. register(
  37. id='MiniGrid-Empty-16x16-v0',
  38. entry_point='gym_minigrid.envs:EmptyEnv16x16'
  39. )