Hive game (wikipedia), backed by an AlphaZero (wikipedia) based AI, using GoMLX (an ML framework for Go) .
Hive is a small fun board game played with two people, where each one is trying to surround the other one's Queen Bee. For a quick match, with instructions and a tutorial, try a web version here (janpfeifer.github.io).
It is also a great platform to play around with game algorithms, like AlphaZero (wikipedia) and demo GoMLX, a machine learning framework for Go.
It comes with:
It is slower because of WebAssembly and using a pure Go backend for the machine learning, but it is enough to play at the medium level at no wait.
Tested on Linux and Windows, probably work in most platforms:
go install github/janpfeifer/hiveGo/cmd/hive@latest
- To play vs a default AI:
hive
- To watch AIs playing against each other:
hive -watch
- Hotseat mode:
hive -hotseat
- See
hive -help
for more options.
It uses the GoMLX Go backend by default, so nothing else is needed to install. If you want the "accelerated" version, based on OpenXLA, including GPU support, install the XLA libraries (see GoMLX Installation), and install hive command with:
go install -tags xla github/janpfeifer/hiveGo/cmd/hive@latest
Warning
🚧🛠 Currently broken 🚧🛠
Easy to build in XWindows -- well, more or less, depending on the dependencies working out fine. Probably one could compile it in windows as well ...
TODO: use Fyne to make it portable?
go run github/janpfeifer/hiveGo/cmd/gnome-hive
This is an experimental / educative project to learn the AlphaZero algorithm and RL in general.
It was originally a 2018 project using TensorFlow, refreshed in 2025 to use GoMLX, a feature-full ML framework for Go.
What is working right now:
- The command-line UI, see below.
- AIs, using a basic set of features for the board (lots that can be improved here) a. AlphaBeta-Pruning (code): using a straight forward FNN (Feedforward Neural Network) model. b. Alpha-Zero (code): using a tiny GNN (Graph Neural Network) model.
It already beats me every time, and when I pitched it against some commercially available Hive game, both AIs won every time.
Trainers: cmd/a0-trainer
and `cmd/ab-trainer
Allows playing games among AI's automatically.
- Play new games. Optionally save the games.
- Load and rescore old games.
- Compare AIs
- Train models while playing the game.
- Can train TF models.
- Can distill from previous models: very handy to quickly ramp up a new model to a moderate quality model.
- Two trainers: ab-trainer (for AlphaBeta Pruning) and a0-trainer (for the AlphaZero models).
During training with larger models you may want to use GoMLX with a GPU.
Warning
🚧🛠 Currently broken 🚧🛠
The GoMLX version doesn't yet implemented the convolutional model.
But also, the better idea would be to do a transformer based model.
The latest, more fancy model, uses the full board as input to the NN, and runs a bunch of layers of convolution on that, with residual connections.
The convolutions for hexagonal mappings require some extra care, since the neighbourhood kernel is different depending if one are on odd/even columns.
See experiments in this colab
- Thanks for Florence Poirel for the awesome drawings!
- The project started from earlier version in Python, but it was greatly improved since.
Background pictures:
- Winning pattern from pexels.com/light-creative-abstract-colorful-134