This repository contains a multi-agent reinforcement learning system in which Pac-Man and a Ghost train against each other using Deep Q-Networks (DQNs). The project supports full training (Phase 2) and evaluation of saved model checkpoints.
From the project root:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install "numpy<2"If you already have a venv, simply activate it:
source venv/bin/activatePyTorch builds included in this project require NumPy below version 2.
All training configuration is controlled through:
phase_2/config.py
This file defines:
- epsilon schedule
- reward shaping
- environment settings
- batch size
- update frequency
- target network update interval
Modify values in config.py before launching a new run.
Run:
python phase_2/train.pyEach training session creates an automatically numbered folder under:
phase_2/runs/run_XXX/
This folder includes:
- pacman_epXXXX.pt (model checkpoint)
- ghost_epXXXX.pt (model checkpoint)
- metrics CSV
- parameters CSV
Training prints progress to the console and logs data every episode.
(Adapted from EVAL_README.md)
This guide explains how to load .pt checkpoints and run evaluation episodes using phase_2/eval_agent.py. Evaluation is deterministic and supports optional visual rendering.
If not already done:
source venv/bin/activate
pip install pygame
pip install "numpy<2"Each run directory contains:
pacman_epXXXX.pt
ghost_epXXXX.pt
run_XXX_metrics.csv
run_XXX_parameters.csv
Use matching episode numbers for Pac-Man and Ghost.
python phase_2/eval_agent.py --pac phase_2/runs/<RUN_FOLDER>/pacman_epXXXX.pt --ghost phase_2/runs/<RUN_FOLDER>/ghost_epXXXX.pt --episodes 20python phase_2/eval_agent.py --pac phase_2/runs/<RUN_FOLDER>/pacman_epXXXX.pt --ghost phase_2/runs/<RUN_FOLDER>/ghost_epXXXX.pt --episodes 10 --render --cell 48This opens a Pygame window showing:
- Pac-Man
- Ghost
- Walls
- Pellets
- Movement step-by-step
Example:
=== Evaluation Results ===
{'caught': 13, 'cleared': 5, 'timeout': 2}
Interpretation:
- caught: Ghost catches Pac-Man
- cleared: Pac-Man collects all pellets
- timeout: Maximum steps reached
Fix:
pip install "numpy<2" --upgradepip install pygame- Use matching checkpoint episode numbers
- Ensure environment settings match those used during training
| Argument | Description |
|---|---|
| --episodes | Number of evaluation episodes (default 20) |
| --render | Enable visualization |
| --cell | Pixel size per grid cell |
| --pac | Path to Pac-Man checkpoint |
| --ghost | Path to Ghost checkpoint |
The repository supports:
- Full DQN-based training of Pac-Man and Ghost agents
- Automated run logging via per-run folders
- Reproducible hyperparameter snapshots
- Visual and non-visual evaluation tools
train.py handles full training.
eval_agent.py provides deterministic evaluation suitable for analysis and demonstration.