Skip to content

Python library to train an AlphaZero Model to play chess

Notifications You must be signed in to change notification settings

munjeongho/pyairena

Repository files navigation

Pyairena

Pyairena is a Python library designed to train an AlphaZeroNetwork model. It also includes an SDK to connect your AI agent to the airena.bet game server.


Table of Contents

  1. Install
  2. Train Model
  3. Example Self-Playing Agent

Install

pip install -r requirements.txt

Train Model

Help Command

To see the available options and arguments for training, use the --help command:

python train.py --help

This will display details about the arguments, such as the number of epochs, filters, device selection, etc.

Training Data

The training data must be provided in Portable Game Notation (PGN) files. Each PGN file should contain one game.

Example PGN file:

[Event "Live Chess"]
[Date "2022.04.25"]
[White "Mykola-Bortnyk"]
[Black "Hikaru"]
[Result "0-1"]
[CurrentPosition "q4nk1/p2r2bp/1p1Np1p1/3b2Q1/3P4/P7/BP3PPP/3R2K1 w - -"]
[UTCDate "2022.04.25"]
[UTCTime "20:22:41"]


1. e4 { [%clk 0:03:00] } 1... c5 { [%clk 0:03:00] } 2. c3 { [%clk 0:02:59.6] } 2... d5 { [%clk 0:02:58.7] } 3. exd5 { [%clk 0:02:59.5] } 3... Qxd5 { [%clk 0:02:58.3] } 4. d4 { [%clk 0:02:59.3] } 4... Nf6 { [%clk 0:02:57.4] } 5. Nf3 { [%clk 0:02:58.8] } ....

Start Training

To start training, specify the path to your training data directory:

python train.py --ccrl_dir /path/to/training-data

You can also pass optional arguments to customize the training process. For example:

python train.py --ccrl_dir /path/to/training-data --num_epochs 50 --batch_size 128

Example Self-Playing Agent

To play games with your trained agent, connect it to the Airena websocket server. The server sends game events to your agent, and your agent must use the Airena REST API to send commands and make moves.

API Documentation

Keep in mind that the above example implementation uses the agent wallets private key to sign messages. Make sure to review the code before using it.

About

Python library to train an AlphaZero Model to play chess

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages