Get startedGet started for free

Interacting with the Frozen Lake environment

Now you'll navigate the Frozen Lake environment, a grid-based world where actions move an agent in specific directions. Your task is to carefully look at the environment, and manually define a list of actions that will navigate the agent from the start (top left) to the goal (bottom right) without falling into any holes. In the Frozen Lake environment, actions are typically represented as:

  • 0: left
  • 1: down
  • 2: right
  • 3: up

After running your code, be sure to navigate through your plots to see the path taken by using the 'Previous Plot' and 'Next Plot' buttons. This will help you understand the sequence of actions and their outcomes.

gym and plt have been imported along with the render() function and the env variable.

This exercise is part of the course

Reinforcement Learning with Gymnasium in Python

View Course

Exercise instructions

  • Observe the agent's position on the right and define a list of actions to navigate the agent across the lake to the goal.
  • Execute each action in the list through the for loop.
  • Render the environment after each action to observe the agent's path.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define the sequence of actions
actions = [____]

for action in actions:
  # Execute each action
  state, reward, terminated, _, _ = ____
  # Render the environment
  ____
  if terminated:
  	print("You reached the goal!")
Edit and Run Code