Skip to content

A Deep Learning UCI-Chess Variant Engine written in C++ & Python ๐Ÿฆ

License

Notifications You must be signed in to change notification settings

MyraBaba/CrazyAra

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

License: GPL v3 ย  Codacy Badge License: GPL v3

Contents

Description

CrazyAra is an open-source neural network chess variant engine, initially developed in pure python by Johannes Czech, Moritz Willig and Alena Beyer in 2018. It started as a semester project at the TU Darmstadt with the goal to train a neural network to play the chess variant crazyhouse via supervised learning on human data. The project was part of the course "Deep Learning: Architectures & Methods" held by Kristian Kersting, Johannes Fรผrnkranz et al. in summer 2018.

The development was continued and the engine ported to C++ by Johannes Czech. In the course of a master thesis supervised by Karl Stelzner and Kristian Kersting, the engine will learn crazyhouse in a reinforcement learning setting and learn to play other chess variants including classical chess.

The project is mainly inspired by the techniques described in the Alpha-(Go)-Zero papers by David Silver, Thomas Hubert, Julian Schrittwieser, Ioannis Antonoglou, Matthew Lai, Arthur Guez, Marc Lanctot, Laurent Sifre, Dharshan Kumaran, Thore Graepel, Timothy Lillicrap, Karen Simonyan, Demis Hassabis.

The training scripts, preprocessing and neural network definition source files are written in python and located at DeepCrazyhouse/src. There are two version of the search engine available: The initial version is written in python and located at DeepCrazyhouse/src/domain/agent. The newer version is written in C++ and located at engine/src.

CrazyAra is an UCI chess engine and requires a GUI (e.g. Cute Chess, XBoard, WinBoard) for convinient usage.

Links

Download

Binaries

We provide binary releases for the following plattforms:

Operating System Backend Compatible with
Linux CUDA 10.0, cuDNN v7.5.1.10, openBlas NVIDIA GPUs and CPU
Linux Intel MKL Intel CPUs
Windows CUDA 10.1, cuDNN v7.5.1.10, openBlas NVIDIA GPUs and CPU
Windows Intel MKL Intel CPUs

For Intel MKL the network inference is optimized when defining the following environment variable:

MXNET_SUBGRAPH_BACKEND=MKLDNN

Models

The following models are available for download:

The extracted model should be placed in the same directory as the engine executable. The directory can be changed by adjusting the UCI-parameter Model_Directory. Each model is compatible with all executables.

More information about the different models can be found in the wiki.

Variants

The current list of available chess variants include:

Documentation

For more details about the initial python version visit the wiki pages:

Compilation

Please follow these steps to build CrazyAra from source:

Linux

  1. Clone the CrazyAra repository:

    git clone https://github.com/QueensGambit/CrazyAra.git --recursive
  2. Download and install the Blaze library of version >=3.6 or current master:

    tar -xvzf blaze-3.6.tar.gz
    cd blaze-3.6
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/
    sudo make install

    Detailed build instruction can be found here:

  3. Build the MXNet C++ package. Building with OpenCV is not required:

    Install the prerequesites (e.g. for IntelMKL):

    sudo apt-get update
    sudo apt-get install -y build-essential git
    sudo apt-get install -y libopenblas-dev liblapack-dev
    sudo apt-get install -y graphviz
    git clone https://github.com/apache/incubator-mxnet --recursive

    IntelMKL: make -j $(nproc) USE_CPP_PACKAGE=1 USE_OPENCV=0 USE_MKL=1

    CUDA / cuDNN: make -j $(nproc) USE_CPP_PACKAGE=1 USE_OPENCV=0 USE_MKL=0 USE_CUDA=1 USE_CUDNN=1

    You might have to reduce the number of jobs to run in paralell e.g. -j 4 if you run out of memory (RAM) during building. Building the MXNet-C++ examples is not required.

    Detailed build instruction can be found here:

  4. Build the CrazyAra binary

    export MXNET_PATH=<path_to_mxnet>/incubator-mxnet/
    cd engine
    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Release ..
    make

Windows

Instructions can be found in the wiki.

Rating

The playing strength of CrazyAra has been evaluated over the course of development.

Playing strength of CrazyAra 0.3.1

CrazyAra 0.3.1 played multiple world champion Justin Tan (LM JannLee) at 18:00 GMT on 21st December in five official matches and won 4-1. You can find a detailed report about the past event published by okei here:

CrazyAra 0.3.1 was also put to the test against known crazyhouse engines:

Playing strength of CrazyAra 0.5.0

Matuiss2 generated 25 games (Intel i5 8600k, 5GHz) between CrazyAra 0.3.1 and CrazyAra 0.5.0:

[TimeControl "40/300"]
Score of CrazyAra 0.5.0 vs CrazyAra 0.3.1: 22 - 3 - 0 [0.88]
Elo difference: 346 +/- NaN

25 of 25 games finished.

Playing strength of CrazyAra 0.6.0

CrazyAra 0.6.0 is the first C++ release and has been evaluated in our paper (section 11 Experimental Evaluation).

Libraries

These libraries are used in the python version:

  • python-chess: A pure Python chess library
  • MXNet: A flexible and efficient library for deep learning
  • numpy: The fundamental package for scientific computing with Python
  • Zarr: An implementation of chunked, compressed, N-dimensional arrays

The following libraries are used to run the C++ version of CrazyAra:

  • Multi Variant Stockfish: Stockfish fork specialized to play chess and some chess variants
    • Used for move generation and board representation as a replacement for python-chess.
  • MXNet C++ Package: A flexible and efficient library for deep learning
    • Used as the deep learning backend for loading and inference of the trained neural network
  • Blaze: An open-source, high-performance C++ math library for dense and sparse arithmetic
    • Used for arithmetic, numerical vector operation within the MCTS search as a replacement for NumPy
  • Catch2: A multi-paradigm test framework for C++

When CrazyAra is also built with reinforcement learning functionality the following libraries are used:

  • z5: Lighweight C++ and Python interface for datasets in zarr and N5 format
    • Used for exporting generated self-play data in C++ in the Zarr data format
  • xtensor: C++ tensors with broadcasting and lazy computing
    • Used as the internal matrix format within z5

Players

CrazyAra's knowledge in the game of crazhyouse for supervised neural networks is based on human played games of the lichess.org database.

The most active players which influenced the play-style of CrazyAra the most are:

  1. mathace
  2. ciw
  3. retardedplatypus123
  4. xuanet
  5. dovijanic
  6. KyleLegion
  7. LM JannLee
  8. crosky
  9. mariorton
  10. IM opperwezen

Please have a look at Supervised training or our paper for more detailed information.

Related

Similar open source neural network chess projects are listed below:

chess-alpha-zero

In CrazyAra v.0.1.0 the Monte-Carlo-Tree-Search (MCTS) was imported and adapted from the following project:

For CrazyAra v.0.2.0 the MCTS was rewritten from scratch adding new functionality:

  • Reusing the old search tree for future positions
  • Node and child-nodes structure using numpy-arrays
  • Always using mate-in-one connection if possible in the current search tree

SixtyFour crazyhouse engine

Leela-Chess-Zero chess engine

Allie(Stein) chess engine

Scorpio chess engine

Research

The following is a collection of useful research links

AlphaGo Zero paper: https://arxiv.org/pdf/1712.01815.pdf

Journal Nature: https://storage.googleapis.com/deepmind-media/alphago/AlphaGoNaturePaper.pdf

CrazyAra paper: https://arxiv.org/abs/1908.06660

SixtyFour engine paper: https://arxiv.org/abs/1908.09296v1

Hyper-Parameter Sweep on AlphaZero General: https://arxiv.org/abs/1903.08129

DeepMind Blogpost: https://deepmind.com/blog/alphago-zero-learning-scratch/

How AlphaGo Zero works - Google DeepMind https://www.youtube.com/watch?v=MgowR4pq3e8

Deep Mind's AlphaGo Zero - EXPLAINED https://www.youtube.com/watch?v=NJBLx29JuHs

A Simple Alpha(Go) Zero Tutorial https://web.stanford.edu/~surag/posts/alphazero.html

AlphaGo Zero - How and Why it Works: http://tim.hibal.org/blog/alpha-zero-how-and-why-it-works/

Simple Chess AI implementation https://github.com/mnahinkhan/Chess/blob/master/Chess/chess.py

Licence

CrazyAra is free software, and distributed under the terms of the GNU General Public License version 3 (GPL v3). The source-code including all project files is licensed under the GPLv3-License if not stated otherwise.

For details about the GPL v3 license, refer to the file LICENSE.

Publication

  • J. Czech, M. Willig, A. Beyer, K. Kersting and J. Fรผrnkranz: Learning to play the Chess Variant Crazyhouse above World Champion Level with Deep Neural Networks and Human Data, preprint
@article{czech2019learning,
  title={Learning to play the Chess Variant Crazyhouse above World Champion Level with Deep Neural Networks and Human Data},
  author={Czech, Johannes and Willig, Moritz and Beyer, Alena and Kersting, Kristian and F{\"u}rnkranz, Johannes},
  journal={arXiv preprint arXiv:1908.06660},
  year={2019}
}

About

A Deep Learning UCI-Chess Variant Engine written in C++ & Python ๐Ÿฆ

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jupyter Notebook 68.2%
  • Python 31.8%