Skip to content

Play classic Nokia snake game by reinforcement learning with Keras

License

Notifications You must be signed in to change notification settings

wing3s/snake_game

Repository files navigation

Snake Game

Play classic Nokia snake game by reinforcement learning with Keras. This project is a great starting point to learn how reinforcement learning works and implementation of deep learning with Keras. Keras is a high level Python deep learning library based on Theano or TensorFlow. We use Q-learning to teach snake how to move. This Q-learning tutorial is an awesome material to get the idea how it works.

Installation

git clone [email protected]:wing3s/snake_game.git
cd snake_game
# Install app required packages
pip install -r requirements.txt

Note

If you have any issue with matplotlib package installation, please follow below steps.

MacOS with virtualenv (pyenv)
# Install a Python version
PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2 --enable-framework CC=clang" pyenv install <your_python_version>
pyenv virtualenv <your_python_version> <your_virtualenv_name>
# Install app required packages
git clone [email protected]:wing3s/snake_game.git
cd snake_game
# Install app required packages
pyenv activate <your_virtualenv_name>
pip install -r requirements.txt
# add missing file for matplotlib in Python virtualenv
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
Ubuntu with virtualenv (pyenv)
# Install freestyle, png packages
sudo apt-get install freetype* libpng*
# Install a Python version
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install <your_python_version>
pyenv virtualenv <your_python_version> <your_virtualenv_name>
# Install app required packages
git clone [email protected]:wing3s/snake_game.git
cd snake_game
# Install app required packages
pyenv activate <your_virtualenv_name>
pip install -r requirements.txt

Code Structure

Play the game

python terminal.py

Simply move the snake by arrow keys ←, → ↑ ↓.

  • 1: snake or wall
  • F: target fruit

Train the bot

python run_bot.py

Trained model is saved to /models with its json structure and weights by default.

Reference

This project is inspired by following resources.

About

Play classic Nokia snake game by reinforcement learning with Keras

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages