How to create FrozenLake random maps

Besides providing our custom map using the desc parameter, it’s also possible to create random maps for the Frozen Lake environment, as shown in the code below:

import gym

env = gym.make("FrozenLake-v0", desc=None, map_name=None)

By setting both the parameters desc and map_name to None, the environment will be created using a random 8×8 map. However, it’s not possible to create a random map of custom size using only the make method. But we can work around this limitation by importing the generate_random_map() function from the frozen_lake module and passing its output to the desc parameter:

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)

The generate_random_map() function provides us much more flexibility. The function receives two parameters: size and p. The parameter size expects an integer representing the side of the grid, resulting in a size x size map, whereas the p parameter is the probability of occurring a frozen tile, and is used to set the proportion between frozen tiles and holes.


The FrozenLake environment provided with the Gym library has limited options of maps, but we can work around these limitations by combining the generate_random_map() function and the desc parameter. The use of random maps it’s interesting to test how well our algorithm can generalize.



Introduction to the Frozen Lake game:

Using the Frozen Lake environment:

Installing OpenAI Gym:

OpenAI Gym project homepage:

2 thoughts on “How to create FrozenLake random maps

  1. I use this method, however, I always get zeros for my q table as well as the final score for Q leaning and SARSA RL algorithum. I could not figure out the reason, could you please let me know if there is any solution for this? Thanks!!!


Leave a Reply to Rodolfo Mendes Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s