empty.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. self.grid = Grid(width, height)
  12. # Generate the surrounding walls
  13. self.grid.horzWall(0, 0)
  14. self.grid.horzWall(0, height-1)
  15. self.grid.vertWall(0, 0)
  16. self.grid.vertWall(width-1, 0)
  17. # Place a goal square in the bottom-right corner
  18. self.grid.set(width - 2, height - 2, Goal())
  19. self.mission = "get to the green goal square"
  20. class EmptyEnv6x6(EmptyEnv):
  21. def __init__(self):
  22. super().__init__(size=6)
  23. class EmptyEnv16x16(EmptyEnv):
  24. def __init__(self):
  25. super().__init__(size=16)
  26. register(
  27. id='MiniGrid-Empty-6x6-v0',
  28. entry_point='gym_minigrid.envs:EmptyEnv6x6'
  29. )
  30. register(
  31. id='MiniGrid-Empty-8x8-v0',
  32. entry_point='gym_minigrid.envs:EmptyEnv'
  33. )
  34. register(
  35. id='MiniGrid-Empty-16x16-v0',
  36. entry_point='gym_minigrid.envs:EmptyEnv16x16'
  37. )