Skip to content

shlok12343/Q_learning_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏰 Escape the Castle: An RL Adventure

Welcome to Escape the Castle! This project features an AI agent, trained from scratch using Q-learning, that has one goal: navigate a dangerous, guard-filled castle and escape to freedom.

The Challenge

Our hero starts in a random location within a 7x7 castle grid. The exit is always at the far corner (6,6). But it's not that simple! The castle is a dynamic environment, patrolled by four unique guards, each with their own strengths and weaknesses. The agent must learn to deal with them, avoid hidden traps, and use healing fountains wisely to survive.

The catch? The agent has partial observability, meaning it can only see its immediate 3x3 surroundings. It must make life-or-death decisions based on limited information, just like a real adventurer!

The Agent: A Brain Built with Q-Learning

This agent's intelligence isn't hard-coded. It's built on the principles of Temporal Difference learning, specifically Q-learning. Through thousands of simulated runs, it learns the optimal strategy for any situation—when to fight, when to hide, when to heal, and when to just wait for a guard to pass. It learns from its mistakes, associating rewards and penalties with its actions until it masters the art of escape.

How to Run the Agent

Want to see it in action?

1. Train the Agent

First, you need to let the agent learn. Run the following command to start the training process. This will generate a Q_table.pickle file containing the agent's "brain."

python3 Q_learning.py train

(Note: Training can take a long time! The more episodes, the smarter the agent gets.)

2. Watch the Agent Play

Once training is complete, run the agent in evaluation mode with a GUI to see what it has learned.

python3 Q_learning.py gui

This project was built with Python, PyGame, NumPy, and Matplotlib. Dive into Q_learning.py to see how the magic happens!

About

Reinforcement learning to play the famous "Escape the Castle" game. The game is set on a 7x7 grid(3X3 is observable), where the player’s goal is to navigate from a random starting position to the bottom-right corner (grid position (6,6)). The envi- ronment is populated with four guards, one trap state, and one heal state

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages