This project implements a reinforcement learning agent that learns to play Super Mario Bros using Deep Q-Learning (DQN). The agent uses a Convolutional Neural Network (CNN) to process game states and make decisions.
- Deep Q-Learning implementation for game control
- CNN-based state processing
- Custom reward system for optimal gameplay
- Automatic model saving and loading
- GPU acceleration support with CUDA 12.4
- Anti-freezing mechanism to prevent agent from getting stuck
- Python 3.8+
- PyTorch with CUDA 12.4 support
- Gym Super Mario Bros
- NES-Py
- NumPy
- Pillow
- NVIDIA GPU with CUDA 12.4 support
- Clone this repository
- Create environment
conda create -n mario-rl python=3.8
conda activate mario-rl- Install PyTorch with CUDA 12.4 support:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124- Install the remaining required packages:
pip install -r requirements.txtRun the training script:
python mario_main.pyThe agent will:
- Train for 100 episodes
- Save the model after training
- Display training statistics
- Render the game during training
The CNN model consists of:
- 3 convolutional layers
- 2 fully connected layers
- ReLU activation functions
- Output layer for action selection
- Learning rate: 0.0001
- Batch size: 128
- Gamma (discount factor): 0.99
- Epsilon (exploration rate): 1.0 with decay
- Freeze time limit: 60 frames
- NVIDIA GPU with CUDA 12.4 support
- Minimum 8GB RAM
- CUDA Toolkit 12.4 installed
This project is open source and available under the MIT License.
AnssiO