Skip to content

Interactive AI simulator featuring Q-Learning reinforcement learning in real-time maze navigation. Watch autonomous agents evolve their strategies from random exploration to optimal pathfinding with visual Q-value heatmaps and performance analytics

Notifications You must be signed in to change notification settings

josefdc/agente-genesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Agent Genesis: Autonomous Evolution

Python Pygame NumPy License

Agent Genesis is an interactive artificial intelligence simulator that implements reinforcement learning (Q-Learning) in a maze navigation environment. Watch how an autonomous agent learns to navigate from a starting point to the goal, improving its strategy with each episode. image

๐ŸŽฏ Key Features

๐Ÿง  Reinforcement Learning

  • Q-Learning Algorithm: Complete implementation with Q-table
  • Exploration vs Exploitation: Adaptive epsilon-greedy strategy
  • Real-Time Visualization: Watch Q-values as the agent learns
  • Amnesia Mode: Agent resets its knowledge each session

๐ŸŽฎ Interactive Interface

  • Intuitive Controls: Pause, speed up, restart, and manual navigation
  • Customizable HUD: Draggable and minimizable information panel
  • Advanced Visualizations: Agent trail, color-coded Q-values
  • Notification System: Visual feedback through toast notifications

๐Ÿ“Š Analysis and Metrics

  • Real-Time Statistics: Episodes, steps, rewards, and FPS
  • Performance History: Average rewards and best episode
  • Status Indicators: Training/observation mode, simulation speed
  • Visual Effects: Celebration particles and screen effects

๐Ÿš€ Installation and Setup

System Requirements

  • Python 3.10 or higher
  • Pygame-compatible operating system (Windows, macOS, Linux)
  • Emoji font recommended for better visual experience

Quick Installation

# Clone the repository
git clone https://github.com/josefdc/agente-genesis.git
cd agente-genesis

# Install dependencies with uv (recommended)
uv sync

# Or with pip
pip install pygame-ce numpy

Execution

# Method 1: Direct launch script
python run.py

# Method 2: Main module
python -m src.main

# Method 3: With uv
uv run python run.py

๐ŸŽฎ User Controls

Simulation Controls

  • SPACE: Pause/Resume simulation
  • R: Reset agent to initial position
  • ESC: Return to main menu
  • H: Show/Hide help panel

Visualization Controls

  • G: Toggle environment grid
  • Q: Show/Hide color-coded Q-values
  • T: Toggle agent trail with fade

Speed Controls

  • +/=: Increase simulation speed
  • -: Decrease simulation speed
  • P: Pause simulation

Manual Navigation

  • Arrow Keys: Move agent manually

๐Ÿ—๏ธ Project Architecture

agente-genesis/
โ”œโ”€โ”€ src/                          # Main source code
โ”‚   โ”œโ”€โ”€ game.py                   # Main game controller
โ”‚   โ”œโ”€โ”€ agent.py                  # Q-Learning agent implementation
โ”‚   โ”œโ”€โ”€ environment.py            # Navigation environment and physics
โ”‚   โ”œโ”€โ”€ emoji_fallback.py         # Emoji compatibility system
โ”‚   โ”œโ”€โ”€ components/               # Reusable UI components
โ”‚   โ”‚   โ””โ”€โ”€ button.py             # Interactive buttons
โ”‚   โ””โ”€โ”€ scenes/                   # Game scenes
โ”‚       โ”œโ”€โ”€ base_scene.py         # Base class for scenes
โ”‚       โ”œโ”€โ”€ menu_scene.py         # Main menu
โ”‚       โ””โ”€โ”€ simulation_scene.py   # Main simulation scene
โ”œโ”€โ”€ levels/                       # Maze levels
โ”‚   โ”œโ”€โ”€ 01_basic.txt             # Basic level
โ”‚   โ””โ”€โ”€ 02_intermediate.txt      # Intermediate level
โ”œโ”€โ”€ config/                       # Game configuration
โ”‚   โ””โ”€โ”€ settings.json            # Visual and game settings
โ”œโ”€โ”€ assets/                       # Multimedia resources
โ”‚   โ”œโ”€โ”€ fonts/                   # Fonts
โ”‚   โ””โ”€โ”€ sounds/                  # Sound effects and music
โ”œโ”€โ”€ saved_models/                # Saved models (not used in amnesia mode)
โ”œโ”€โ”€ run.py                       # Launch script
โ””โ”€โ”€ pyproject.toml              # Python project configuration

๐Ÿ”ฌ Q-Learning Algorithm

The agent uses a classic Q-Learning implementation with the following characteristics:

Learning Parameters

  • Learning Rate (ฮฑ): 0.1
  • Discount Factor (ฮณ): 0.99
  • Initial Epsilon: 1.0 (full exploration)
  • Minimum Epsilon: 0.05
  • Epsilon Decay: 0.9995

State and Action Space

  • States: Position (x, y) in the maze grid
  • Actions: 4 cardinal directions (up, down, left, right)
  • Rewards:
    • +100 for reaching the goal
    • -10 for wall collision
    • Small penalty for each step

Exploration Strategy

The agent uses an epsilon-greedy strategy:

  • With probability epsilon: Exploration (random action)
  • With probability 1-epsilon: Exploitation (best known action)

๐ŸŽจ Customization

Visual Configuration

The config/settings.json file allows customization of:

  • Screen resolution and FPS
  • Complete color scheme
  • Animation speeds
  • UI settings

Level Creation

Levels are defined in simple text format:

  • #: Walls
  • .: Free spaces
  • S: Agent starting position
  • G: Goal to reach

Custom level example:

##########
#S.......#
#.#####.##
#.....#.G#
##########

๐Ÿ› ๏ธ Development and Contributions

Main Class Structure

Agent (src/agent.py)

  • Implements the Q-Learning algorithm
  • Handles epsilon-greedy decision making
  • Updates Q-table based on experiences

Environment (src/environment.py)

  • Manages maze logic
  • Calculates rewards and state transitions
  • Renders environment with Q-value visualization

SimulationScene (src/scenes/simulation_scene.py)

  • Orchestrates the complete simulation
  • Handles user input and visualization
  • Implements interactive HUD and notification system

Contributing to the Project

  1. Fork the repository
  2. Create a branch for your feature: git checkout -b feature/new-feature
  3. Commit your changes: git commit -m 'Add new feature'
  4. Push to the branch: git push origin feature/new-feature
  5. Open a Pull Request

๐Ÿ“ˆ Usage Examples

Observing Learning

  1. Run the simulator
  2. Select a level
  3. Watch how the agent initially explores randomly
  4. Notice how it gradually improves its navigation strategy
  5. Enable Q-value visualization to see the agent's "mental map"

Experimenting with Parameters

Modify parameters in src/agent.py to experiment:

  • Increase learning rate for faster convergence
  • Adjust epsilon to change exploration/exploitation balance
  • Modify rewards for different behaviors

๐Ÿ› Troubleshooting

Common Issues

Game won't start

  • Verify Pygame-CE is installed: pip install pygame-ce
  • Confirm you have Python 3.10 or higher

Performance issues

  • Reduce resolution in config/settings.json
  • Decrease simulation speed with the - key

Emojis not displaying correctly

  • The game includes automatic ASCII fallbacks
  • For better experience, install an emoji font like Noto Color Emoji

๐Ÿ“ License

This project is under the MIT License. See the LICENSE file for more details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Jose Felipe Duarte (@josefdc)

  • Software developer specialized in AI and interactive visualization
  • Passionate about machine learning and educational interfaces

๐Ÿ™ Acknowledgments

  • Pygame community for the excellent game development library
  • Reinforcement Learning researchers for the theoretical foundations
  • Open Source community for inspiration and tools

Like the project? โญ Give it a star on GitHub and share it with other AI enthusiasts!

Have suggestions? ๐Ÿ’ก Open an issue or contribute directly to the code.

"Artificial intelligence is not about replacing human intelligence, but amplifying it." - Agent Genesis

About

Interactive AI simulator featuring Q-Learning reinforcement learning in real-time maze navigation. Watch autonomous agents evolve their strategies from random exploration to optimal pathfinding with visual Q-value heatmaps and performance analytics

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages