Teaching a reinforcement learning agent to play the classical game of snake.
This project contains 2 implementations of machine learning agents for playing snake, one created using Convolutional Neural Networks (CNN) and one using a densly connected network.
For running this project you'll need a modern Python version (>=3.9) as well as the following packages:
These are specified in the requirements.txt
file and can be easily installed using pip with the following command:
pip install -r requirements.txt
For training the densly connected model simply run:
python src/nn_model.py
This should start running the training for a new model with the default configuration (found in src/nn_model.py
)
For training the CNN model, you can run the following command:
python src/train_cnn.py
If you want to configure some variables, like if weights should be loaded before running, if graphics should be used, and how many epochs it should be trained on, run the following command to get a description on how to set these:
python src/train_cnn.py --help
If you want to play the game yourself, simply run:
python src/play.py
To play the game using a trained densly connected network run:
python src/play.py -m nn -w <PATH TO WEIGHTS>
To play the game using a trained CNN run:
python src/play.py -m cnn -w <PATH TO WEIGHTS>