CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Reinforcement Learning with Gymnasium in Python

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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!")
Modifier et exécuter le code