This is a Reinforcement Learning Snake Game with an NCurses UI for selecting to either:
- Play snake yourself.
- Watch an RL bot play.
- Train a new RL bot to play, which you can then watch.
The game code for this repo was inspired by CppND-Capstone-Snake-Game.
- cmake >= 3.13
- All OSes: click here for installation instructions
- make >= 4.1 (Linux, Mac)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- SDL2 >= 2.0
- All installation instructions can be found here
- Note that for Linux, an
apt
orapt-get
installation is preferred to building from source.
- NCurses >= 6.1
- gcc/g++ >= 9.3
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - install Xcode command line tools
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install libncurses5-dev libncursesw5-dev
sudo apt install -y gcc-9 g++-9
export CC=gcc-9
export CXX=g++-9
- Clone this repo.
- Make a build directory in the top level directory:
mkdir build && cd build
- Compile:
cmake .. && cmake --build .
- Run it:
./RLSnakeGame
.
All .h
files are in include
, core .cpp
files are in src
, and tests files in tests
. The tests are a good place
to see how the entities work in isolation. To build the tests, you need CMake>=3.14
and to set
option -DBUILD_TESTS=YES
.
The following files implement a template based API for tabular Reinforcement Learning. Only the Q-Learning algorithm has been implemented but the API supports SARSA and Expected SARSA.
include/state_action_map.h
include/action_valuer.h
include/policy.h
include/agent.h
include/learner.h
include/environment.h
include/simulator.h
include/controller.h
include/key_board_controller.h
src/keyboard_controller.h
include/food.h
src/food.cpp
include/snake.h
src/snake.cpp
include/game.h
src/game.cpp
include/renderer.h
src/renderer.cpp
include/menu.h
src/menu.cpp
include/game_menu_factory.h
src/game_menu_factory.cpp
include/gui.h
src/gui.cpp
include/io.h
src/io.cpp
include/mail_utils.h
src/mail_utils.cpp
include/trainer.h
src/trainer.cpp
src/main.cpp
The rest of the code are either factories for assembling the entities or wiring the snake game with the RL algorithms and the gui.
- Loops, Functions, I/O: All
- Object Oriented Programming: All
- Memory Management:
- The project makes use of references in function declarations.
- The project uses move semantics to move data, instead of copying it, where possible.
- The project uses smart pointers instead of raw pointers.
- Concurrency: None