This project implements a simple Pac-Man game where the AI agent learns to navigate using Q-Learning, a Reinforcement Learning (RL) algorithm. The agent improves its decision-making over time by interacting with the game environment and receiving rewards.
- AI-controlled Pac-Man using Q-Learning
- Customizable game environment
- Exploration vs. Exploitation balance for optimal learning
- Reward-based learning mechanism
- Randomized starting positions for better generalization
To run the project, ensure you have Python installed. Then, install the required dependencies:
pip install numpy pygameQ-Learning is a reinforcement learning algorithm that helps the AI learn the best actions to take in a given state. The core idea is:
-
Initialize a Q-table to store state-action values.
-
Choose an action based on an exploration-exploitation strategy.
-
Perform the action and receive a reward.
-
Update the Q-value using the Bellman equation:
Q(s, a) = (1 - α) * Q(s, a) + α * (reward + γ * max(Q(s', a')))where:
s= current statea= action takens'= new state after actionα= learning rateγ= discount factor
-
Repeat the process until the AI learns optimal actions.
- First, this Pac-Man version doesn't contain any ghosts (maybe in the future).
- Second, we train this model many times across 10 different maps. However, since there are 3^12 different states, there will be some states that the model hasn't encountered before, which might lead to incorrect actions. You can increase the model's performance by loading the Q-matrix and training it further (this is just one way to improve the model).