About zxGammon
zxGammon is backgammon for the 48K ZX Spectrum. You play against Gnubby, a little gnu with a neural-network player for a brain: money games, or matches to 1, 3, 5 or 7 points, with the doubling cube and the Crawford rule. It runs on a real Spectrum, in any Spectrum emulator, and on this site's front page.
How Gnubby plays
All of Gnubby's play is in Z80 code with no multiplication or division: 22 KB of code and data for the engine, the networks' weights among them, and the whole game about 31 KB.
- Every legal move is generated, each resulting position once, and a fast linear filter scores them all.
- The best twelve are scored by a neural network with 48 hidden units (or, once the game is a race, a smaller race network), which keeps two.
- Each of those two is tried against all 21 of the opponent's rolls, the opponent's reply chosen by the filter and a small network and the position after it scored by the large one; the better wins.
- For the cube, Gnubby weighs his equity against thresholds for doubling, for being too good to double, and for taking. When it is close he looks a move deeper, which can take him a few seconds more.
The networks keep the sums of their first layer and add only the inputs a move changes. On a 3.5 MHz Spectrum a move takes Gnubby about seven seconds on average.
GNU Backgammon
zxGammon's play is derived from GNU Backgammon, the free backgammon program of the GNU Project, and owes it everything about how well Gnubby plays:
- Its neural networks are derived from GNU Backgammon's: they score positions as GNU Backgammon does, and the contact network takes GNU Backgammon's own input features of a position, computed here in integer arithmetic.
- Its doubling cube follows GNU Backgammon: in a match its thresholds come from GNU Backgammon's match equity table at the score and cube, and in money play from GNU Backgammon's own cube decisions.
GNU Backgammon is free software, licensed under the GNU General Public License, and so is zxGammon.
Licence
zxGammon, Copyright © 2026 Paul Hankin.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
That covers the whole of this site: the game and its source, the networks' weights, its pictures, and the pages and Spectrum emulator here (js/z80.js, js/spectrum.js, js/main.js). The source is on the Source pages, ready to build with the open-source assembler sjasmplus.
While you look at the site's other pages, your game is kept where it was, in your browser tab's own storage, and goes when you close the tab or press Restart. Nothing is sent anywhere: the site has no server code, and the one cookie it sets only records that you have seen the notice on your first visit.
ZX Spectrum is a trademark of its owners; zxGammon is not connected with them. The emulator here needs no Spectrum ROM: zxGammon reads the keyboard and draws the screen itself.