Skip to content

search-based agents for solving the Frozen Lake environment from OpenAI Gymnasium

Notifications You must be signed in to change notification settings

serenaveraa/Frozen-Lake

Repository files navigation

❄️ Frozen Lake Search Agents

Welcome to the Frozen Lake Search Agents repository!
Here you'll find intelligent agents that solve the classic Frozen Lake maze problem using search algorithms.

🧊 The Problem

Imagine a frozen lake represented as a grid, where each cell can be:

  • S: Start position
  • G: Goal position
  • F: Frozen (safe to walk)
  • H: Hole (danger! falls in)

Your agent must find the safest path from S to G without falling into any holes.
At each step, the agent can move:

  • ⬅️ Left (0)
  • ⬇️ Down (1)
  • ➡️ Right (2)
  • ⬆️ Up (3)

🤖 The Agents

This repo includes two search-based agents:

  • UCSAgent: Uniform Cost Search agent (explores all paths with equal cost)
  • AStarAgent: A* agent (uses smart heuristics to find the shortest path faster)
    • Manhattan distance heuristic 🏙️
    • Euclidean distance heuristic 📏

🏁 How It Works

  • The environment is generated randomly for different grid sizes (4x4, 8x8, 16x16, 20x20).
  • Agents use the environment's model to plan their moves.
  • Performance (steps, reward, time) is compared for each agent and environment.

🚀 Getting Started

  1. Install dependencies with Poetry
    If you don't have Poetry, install it first:

    curl -sSL https://install.python-poetry.org | python3 -
    

    Then install all dependencies:

    poetry install
    
  2. Explore interactively
    Open frozen_lake.ipynb for step-by-step exploration and visualization.

📊 Results

After running, you'll see a comparison of UCS and A* agents on different maze sizes, showing:

  • Reward earned 🏆
  • Steps taken 👣
  • Time spent ⏱️

📝 Files

  • main.py — Runs the agent comparison
  • ucs_agent.py — Uniform Cost Search agent
  • a_star_agent.py — A* agent with heuristics
  • model.py — Maze model and graph builder
  • priority_queue.py — Priority queue for search
  • frozen_lake.ipynb — Interactive notebook

Enjoy solving the Frozen Lake challenge! ❄️🧠🚶‍♂️

About

search-based agents for solving the Frozen Lake environment from OpenAI Gymnasium

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published