This project involves a Python-based AI to play the game of Snake. The AI uses reinforcement learning through the Deep Q Learning methodology, which incorporates a deep neural network to predict actions and maximize rewards.
Reinforcement learning (RL) is an area of machine learning focusing on software agents making decisions to maximize cumulative reward. For this project, the AI will be taught the rules of Snake and learn to play efficiently over time.
The following rules are used in the game:
- Rule details…
To set up the project environment, please ensure you have the following dependencies installed:
- Python 3.7
- Pygame
- PyTorch
- Matplotlib
- IPython
For other dependencies and specific versions, please refer to requirements.txt
.
- Create and activate a new Conda environment:
$ conda create -n pygame_env python=3.7
$ conda activate pygame_env
- Install Pygame, PyTorch and other packages:
$ pip install pygame torch torchvision torchaudio matplotlib ipython
Note: Visit PyTorch's official website to select the appropriate installation command for your system.
The AI will learn to play Snake over numerous iterations, progressively improving its strategy to maximize its score.
A custom implementation of the Snake game was developed using Pygame. The foundation of the game is as follows:
import pygame
# Initialize Pygame and create a window...
# Game loop...
# Render snake, handle movement, check for game over...
# Quit game...
Full implementation details are included within the project files.
Contributions to the project are welcome. Please read through the CONTRIBUTING.md file to understand the process for submitting pull requests.
- - Initial work
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to viewers and subscribers of the tutorial series that inspired this AI on YouTube.
- Link to the tutorial series: YouTube tutorial