Skip to main content

Glinski hexagonal chess engine with AlphaZero-style training

Project description

Hexchess Zero

Hexagonal chess engine (Glinski variant) in Rust with AlphaZero-style self-play training.

Install

Prebuilt packages are published to PyPI and npm under the name hexchess-zero:

pip install hexchess-zero       # Python (imports as `hexchess`)
npm install hexchess-zero       # JavaScript / WASM

Python wheels are available for Linux, macOS, and Windows (3.9–3.13); the npm package bundles the WASM binary. See docs/content/docs/usage/ for API documentation, or the published docs site for interactive examples.

Structure

  • engine/ — Rust engine: board representation (91-cell hex grid, axial coordinates), move generation, MCTS search, minimax search, and neural network inference
  • training/ — Async distributed AlphaZero loop: self-play workers, continuous trainer, Elo rating service, dashboard
  • bindings/wasm/ — WASM bindings for browser play (uses tract for inference)
  • bindings/python/ — PyO3 bindings for the training pipeline (uses ONNX Runtime)
  • docs/ — Documentation site with interactive playground (Fumadocs)
  • k8s/ — Kubernetes manifests for the production training cluster

Quick Start

# Run engine tests
make test

# One-time setup: uv sync + build Python bindings
make setup

# Start training (run in separate terminals — or `make docker-up`)
make worker      # self-play worker (run N of these)
make trainer     # continuous trainer (run 1)
make elo         # Elo rating service (scale via replicas)
make dashboard   # status dashboard

# Quick CLI status
make status

# Run documentation site (includes interactive playground)
make docs-dev

Training Pipeline

The pipeline has three asynchronous components that coordinate purely through S3 (DigitalOcean Spaces / Cloudflare R2 / any S3-compatible store). Workers can run anywhere with credentials.

  1. Workers generate self-play games using MCTS + the latest model and flush .npz batches to S3.
  2. Trainer maintains a sliding-window replay buffer over recent self-play data, trains the network, exports ONNX, and promotes a new model version every cycle.
  3. Elo service plays continuous matches between model versions and baselines, persisting per-game results to S3 and rating models with OpenSkill (Weng-Lin / Plackett-Luce).

On first run (no model exists), the trainer bootstraps by training on minimax-supervised imitation data before switching to self-play.

Configuration

All parameters live in training/config.py. Key dials:

MCTS & Self-Play

Parameter Default Description
num_simulations 500 MCTS simulations per move. Higher = stronger play but slower data generation.
temperature_threshold 60 Move number after which temperature drops to temperature_low.
temperature_high 1.0 Temperature for early-game moves (before threshold). Higher = more diverse openings.
temperature_low 0.35 Late-game temperature. Lc0-style floor — anything near zero produced one-hot policy targets in 65–70% of positions, killing gradient signal.
dirichlet_alpha 0.3 Dirichlet noise concentration at the MCTS root.
dirichlet_epsilon 0.25 Mixing weight for Dirichlet noise.
worker_batch_size 5 Games per .npz flush.

Training

Parameter Default Description
batch_size 256 Training batch size.
learning_rate 0.001 Adam learning rate.
l2_regularization 1e-4 Weight decay.
replay_buffer_size 1,000,000 Max positions in the sliding window. The trainer streams uniformly from the most recent .npz files up to this limit.
steps_per_cycle 1,000 Training steps before promoting a new model version.
reload_interval 1,000 Re-scan S3 every N steps within a cycle to pick up fresh worker output.
max_train_steps_per_new_data 4.0 KataGo-style token bucket: target training passes per new data point. Throttles the trainer when workers fall behind.
min_positions_to_start 1,000,000 Bootstrap gate: self-play training won't start until this many positions exist.

Bootstrap (Imitation)

These only apply to the initial bootstrap phase when no model exists yet:

Parameter Default Description
imitation_depth 5 Minimax search depth for generating imitation targets.
imitation_exploration_plies 30 Plies that use softmax sampling (rather than greedy) for opening diversity.
imitation_temperature 200.0 Softmax temperature for converting centipawn scores to policy targets.
imitation_wdl_lambda 0.5 Blend between sigmoid(eval) and final game outcome for the WDL value target.
bootstrap_steps 50,000 Training steps for imitation bootstrap.
bootstrap_learning_rate 0.003 Higher LR for the clean supervised signal (3× self-play LR).

Network Architecture

Parameter Default Description
num_residual_blocks 10 Depth of the residual tower.
num_filters 192 Width of convolutional layers.
se_channels 48 Squeeze-and-excitation bottleneck width.
global_pool_channels 32 KataGo-style global pooling width.
global_pool_blocks (3, 6) Which residual blocks get global pooling.
policy_channels / value_channels 8 / 32 Conv channels in the policy and value heads.
board_channels 19 Input tensor channels (piece planes + metadata). Must match serialization.rs.
board_height / board_width 11 Hex grid embedded in 11×11 rectangle. Fixed by the coordinate system.

Key Dynamics

Worker throughput vs training speed. Workers produce positions at a rate determined by num_simulations and CPU count. The trainer consumes them at a rate determined by steps_per_cycle, batch_size, and GPU speed. The token bucket (max_train_steps_per_new_data) keeps them in lockstep — if the trainer outpaces data production, it sleeps instead of overfitting on stale data.

Buffer size vs cycle length. With a 1M-position buffer and 1,000 steps per cycle at batch size 256, each cycle trains on ~256k samples — about 25% of the buffer. Positions near the edge of the window get fewer passes than recent ones because they age out sooner.

Model version turnover. Every steps_per_cycle steps, the trainer exports a new ONNX version and atomically promotes it via models/latest.meta.json. Workers poll for new versions after each batch of games.

S3 Layout

models/
  latest.onnx              # current model for inference
  latest.meta.json         # {"version": N, "timestamp": "..."} — atomic promotion marker
  checkpoint.pt            # PyTorch training checkpoint
  versions/{N}.onnx        # immutable version snapshots

data/
  selfplay/v{N}/{ts}_{rand}_n{count}.npz   # self-play batches (position count in filename)
  imitation/{ts}_{rand}_n{count}.npz       # bootstrap minimax batches

state/
  elo.json                 # Elo projection (rebuilt from elo_games/)
  elo_games/{ts}_{rand}.json  # one immutable object per played game (race-free writes)

heartbeats/
  {hostname}.json          # worker liveness + stats for the dashboard

Position counts are encoded in each .npz filename so the trainer can compute buffer size from an S3 LIST without opening any files.

S3 credentials live in .env (gitignored): BUCKET_NAME, ACCESS_KEY, SECRET_KEY, ENDPOINT.

Documentation

Full docs (engine internals, training details, bindings reference, deployment, interactive playground) live in docs/ and are published from the Fumadocs site. Run make docs-dev to view locally.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hexchess_zero-0.0.2.tar.gz (98.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hexchess_zero-0.0.2-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (9.7 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

hexchess_zero-0.0.2-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (9.7 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

hexchess_zero-0.0.2-cp39-abi3-win_amd64.whl (6.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_aarch64.whl (9.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

hexchess_zero-0.0.2-cp39-abi3-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file hexchess_zero-0.0.2.tar.gz.

File metadata

  • Download URL: hexchess_zero-0.0.2.tar.gz
  • Upload date:
  • Size: 98.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hexchess_zero-0.0.2.tar.gz
Algorithm Hash digest
SHA256 51aa51fe3b2ff9fd4d8b5c3ce5e5f27f0d07f7ff60e479b13676e92430cd0591
MD5 e38f401be43fea11b235b3ce02ea6e2e
BLAKE2b-256 77f13313053af975317ccc6585e1fc32da84a8ed6be52e1894f43a83011b8580

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2.tar.gz:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 67bc3ba561cbef2395b2a542b71c13bf46b2a865aa25c88e00d6b748d9c4afa7
MD5 e82b4cf3b2753d4db37c0a55be361ad3
BLAKE2b-256 e0f2634fe165a53a269ec1c981c6f2804bb1157a6681082d2781b172319d3f85

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9cfe40859ccdc2f53b22c292cd1d29be292de830fdd8f7cec24f92c548ebdd40
MD5 62fbca5cf4b03ca9bea76feccb60a0e7
BLAKE2b-256 d558964e5e552f41ef5c62a4a8d5b599255b98cf38562df421a39e57d5f6afaf

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d68a1f72c9b1cd2a2a2a03129dcc7e4623496af79e1726f953179a16882eb5d1
MD5 515001f55003598d738fcf00fdd3fd05
BLAKE2b-256 ffe8349b9166bb5e74f4ad7a7c4fc8eb63bebf0e8db45a74ab3dd481952928b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-cp39-abi3-win_amd64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bfdb40b754a1b5080bf022d90c2c42542ef120dda819508af2c8d2caccea2a4f
MD5 a90cf119cd41bc9d8773caa11d20a9f6
BLAKE2b-256 4d7cc903d1ace01e19806678f3fd82dc3e842c866f83f72dd7bf913a0cdb17b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d1be23f2d46fef78587f6af4b435c6d559637304e4e2d665c48751b323d49fbc
MD5 780326d274a413efcd4b5b9c8f0cd424
BLAKE2b-256 14829a68a040ae2d410348797aae761c7d8275fd64881d0ece5597beb152cff9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hexchess_zero-0.0.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hexchess_zero-0.0.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00151e70ef2a32abc8ce65c275f55b7ecb46ffbaa4cb33e7784fc1172e78d755
MD5 e4eeafda77c1cada9fe9cd60cce0ba20
BLAKE2b-256 53ebba186e9139bf96c41f3e66e2dafc11afc036f41550e9719a81fb7e93a5e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for hexchess_zero-0.0.2-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on k15z/hexchess-zero

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page