Awesome Open Source
Awesome Open Source

Alpha Zero General (any game, any framework!)

A simplified, highly flexible, commented and (hopefully) easy to understand implementation of self-play based reinforcement learning based on the AlphaGo Zero paper (Silver et al). It is designed to be easy to adopt for any two-player turn-based adversarial game and any deep learning framework of your choice. A sample implementation has been provided for the game of Othello in PyTorch, Keras, TensorFlow and Chainer. An accompanying tutorial can be found here. We also have implementations for GoBang and TicTacToe.

To use a game of your choice, subclass the classes in and and implement their functions. Example implementations for Othello can be found in othello/ and othello/{pytorch,keras,tensorflow,chainer}/ contains the core training loop and performs the Monte Carlo Tree Search. The parameters for the self-play can be specified in Additional neural network parameters are in othello/{pytorch,keras,tensorflow,chainer}/ (cuda flag, batch size, epochs, learning rate etc.).

To start training a model for Othello:


Choose your framework and game in

Docker Installation

For easy environment setup, we can use nvidia-docker. Once you have nvidia-docker set up, we can then simply run:


to set up a (default: pyTorch) Jupyter docker container. We can now open a new terminal and enter:

docker exec -ti pytorch_notebook python


We trained a PyTorch model for 6x6 Othello (~80 iterations, 100 episodes per iteration and 25 MCTS simulations per turn). This took about 3 days on an NVIDIA Tesla K80. The pretrained model (PyTorch) can be found in pretrained_models/othello/pytorch/. You can play a game against it using Below is the performance of the model against a random and a greedy baseline with the number of iterations. alt tag

A concise description of our algorithm can be found here.


While the current code is fairly functional, we could benefit from the following contributions:

  • Game logic files for more games that follow the specifications in, along with their neural networks
  • Neural networks in other frameworks
  • Pre-trained models for different game configurations
  • An asynchronous version of the code- parallel processes for self-play, neural net training and model comparison.
  • Asynchronous MCTS as described in the paper

Contributors and Credits

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
jupyter-notebook (6,019
deep-learning (3,851
pytorch (2,276
tensorflow (2,131
keras (755
reinforcement-learning (543
chainer (51

Find Open Source By Browsing 7,000 Topics Across 59 Categories