Search code examples
openai-gym

How to generate a random frozen lake map in OpenAI?


They recently added the capability of generating a random frozen map. But there is no accompanying documentation of how to use it. I want to use it in an ongoing project.


Solution

  • One option is to use the function generate_random_map() from the frozen_lake module and use the map returned by the function as an argument to the desc parameter when creating the environment:

    import gym
    from gym.envs.toy_text.frozen_lake import generate_random_map
    
    random_map = generate_random_map(size=20, p=0.8)
    
    env = gym.make("FrozenLake-v0", desc=random_map)
    env.reset()
    env.render()
    

    the generate_random_map() function takes two parameters:

    • size: is the size of the sides of the grid
    • p: is the probability of a frozen tile.

    Another option is to create a subclass of the FrozenLake environment that takes the size and p parameters directly and register it as a new environment. You can find an example of this approach on the following repository:

    https://github.com/rodmsmendes/gym-toy-text-ext