empty.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. self.mission = "get to the green goal square"
  22. return grid
  23. class EmptyEnv6x6(EmptyEnv):
  24. def __init__(self):
  25. super().__init__(size=6)
  26. class EmptyEnv16x16(EmptyEnv):
  27. def __init__(self):
  28. super().__init__(size=16)
  29. register(
  30. id='MiniGrid-Empty-6x6-v0',
  31. entry_point='gym_minigrid.envs:EmptyEnv6x6'
  32. )
  33. register(
  34. id='MiniGrid-Empty-8x8-v0',
  35. entry_point='gym_minigrid.envs:EmptyEnv'
  36. )
  37. register(
  38. id='MiniGrid-Empty-16x16-v0',
  39. entry_point='gym_minigrid.envs:EmptyEnv16x16'
  40. )