Implementation of Q-learning with the game of snake.
I have a detailed write up about the algorithm here:
https://towardsdatascience.com/teaching-a-computer-how-to-play-snake-with-q-learning-93d0a316ddc0
Code is written in python 3.
The only extra dependecies are:
- Pygame
pip3 install pygame
- Depending on the Python version, may need to install dataclasses
pip3 install dataclasses
- First Initialize the Q Table. This will create a text file qvalues.json that is in json format.
python3 InitializeQvalues.py
- Run snake.py.
In snake.py there is a constant FRAMESPEED that is set to 50000 to speed up training and play more games faster. Set this to a smaller number (20-30) to better watch the snake's movements.
python3 snake.py