Skip to main content

Python framework for building AI bots for Hexagonal Connect-6

Project description

hexbot

A Python framework for building AI bots for Hexagonal Tic-Tac-Toe (Connect-6 on an infinite hex grid). Fast C game engine, multiple neural network architectures, AlphaZero training pipeline, and a live training dashboard.

Home of the Orca bot. pip install -e .

Installation

git clone https://github.com/Saiki77/hexbot-building-framework.git
cd hexbot-building-framework
pip install -e .               # core (game engine + torch)
pip install -e '.[dashboard]'  # + dashboard UI
pip install -e '.[all]'        # everything

The C engine auto-compiles on first import (cc/gcc/clang required).

Quick Start

from hexbot import HexGame, Bot, Arena

game = HexGame()
game.place(0, 0)         # P0: 1 stone first turn
game.place(1, 0)         # P1: first of 2
game.place(1, -1)        # P1: second stone

# Any function is a bot
def my_bot(game):
    return game.legal_moves()[0]

result = Arena(my_bot, Bot.heuristic(), num_games=20).play()

Orca Bot

Pre-trained AlphaZero-style bot. The included checkpoint is early-stage (65 iterations) - gets significantly stronger with more training.

from hexbot import Bot
orca = Bot.orca()
move = orca.best_move(game)

Train

# From game collections (fast bootstrap)
python -m orca.scrape --games 5000 --output games.jsonl
python -m orca.sft --data games.jsonl --then-selfplay 50

# Pure self-play
python -m orca.train --iterations 100

# With web dashboard
python train_dashboard.py

Network Architectures

Config Params Description
fast 656K Quick experiments
standard 3.9M Default Orca (128 filters, 12 ResBlocks)
hex-masked 3.9M Hex-neighbor masked CNN (recommended for hex)
large 14.5M Maximum strength (256 filters)
orca-transformer 4.4M CNN + transformer attention
hex-gnn 432K Graph neural network on hex topology
multiscale 1.1M Local CNN + global attention two-tower
python -m orca.train --config hex-gnn --iterations 50

Features

Feature Description
SFT Pipeline Train from game collections (JSONL/CSV/text), chain with self-play
Endgame Solver Deep alpha-beta with transposition cache, integrates with MCTS
Opening Book Trie-based lookup from winning games, blends with MCTS policy
6 Architectures CNN, transformer, GNN, multiscale, hybrid, fast
Mixed Precision FP16 on CUDA for 2x training speed
Distributed Multi-GPU (DDP) and multi-machine (Ray)
Skill Curriculum 6-level auto-progression: basics through endgame
Ensemble Average N checkpoints with uncertainty estimation
Model Zoo Share and download community models
Leaderboard Rate bots against references, compare head-to-head
Plugin System Register custom bots and network architectures
Dashboard REST + WebSocket API, live game replay, charts
30+ API Functions NN eval, MCTS search, threats, solver, augmentation

Bot Approaches

# Approach Complexity
1 Hand-tuned evaluation Low
2 Evolutionary weights Low
3 Minimax with alpha-beta Medium
4 Monte Carlo playouts Medium
5 Neural network (AlphaZero) High
6 Hybrid strategies High

Architecture

hexbot.py              Framework API (Bot, Arena, 30+ analysis functions)
hexgame.py             Game engine (wraps C engine via ctypes)
engine.c               2,300 lines optimized C (bitboard win detection)
bot.py                 Neural networks, MCTS, training pipeline
dashboard.py           Dashboard API (REST + WebSocket)
train_dashboard.py     Training dashboard with web UI
pyproject.toml         pip install config
orca/
  __init__.py          Orca bot loader
  config.py            All tunable parameters
  train.py             Training pipeline (CLI + library)
  sft.py               Supervised fine-tuning from games
  scrape.py            Game downloader
  solver.py            Endgame solver
  openings.py          Opening book
  curriculum.py        Skill-based curriculum
  ensemble.py          Multi-checkpoint ensemble
  distributed.py       Multi-GPU / Ray training
  zoo.py               Model zoo
  leaderboard.py       Bot rating system
  transformer_net.py   Transformer architecture
  hex_gnn.py           Graph neural network
  multiscale_net.py    Multi-scale architecture
  checkpoint.pt        Pre-trained weights
docs/                  Detailed documentation
examples/              Example bot scripts

Device Support

Priority Device Platform
1 CUDA NVIDIA GPU (Linux/Windows)
2 MPS Apple Silicon (macOS)
3 CPU Any platform

Documentation

Guide Description
Getting Started Game API, coordinates, turn structure
Bot Approaches 6 approaches with full code
API Reference All function signatures
Training Guide Self-play, SFT, curriculum, distributed
Configuration Every tunable parameter
Dashboard REST API, WebSocket
Train Dashboard Web UI for training
SFT Guide Train from game collections
Advanced Solver, opening book, ensemble, MCTS tricks
Orca Bot Architectures, loading, training

Contributing

Built for the Hexagonal Tic-Tac-Toe community. Contributions welcome.

License

MIT

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

hexbot-4.0.0.tar.gz (179.0 kB view details)

Uploaded Source

Built Distribution

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

hexbot-4.0.0-py3-none-any.whl (124.4 kB view details)

Uploaded Python 3

File details

Details for the file hexbot-4.0.0.tar.gz.

File metadata

  • Download URL: hexbot-4.0.0.tar.gz
  • Upload date:
  • Size: 179.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hexbot-4.0.0.tar.gz
Algorithm Hash digest
SHA256 98da1c0568c7e9a7894c0fa3e51958c4db075a0a4bb9ac7ab45f9a972b8d407d
MD5 a3e365b16e5400ad1abb3372c4f18711
BLAKE2b-256 1c547e617a4cdb1da521d291856b0abc158714857dbc01cb00bf6e7c4fa63589

See more details on using hashes here.

File details

Details for the file hexbot-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: hexbot-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 124.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hexbot-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 471518280158d8c6f015070cddca61d70046aea4f1ea1665f78e8bfd91fa04b2
MD5 2623eb351fa6dd308d95da344c752e01
BLAKE2b-256 003bf98b169c69bf5fb31c07e872c4e85bb61e2376cb11f46a80a9de5b1f53a5

See more details on using hashes here.

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