Source
zxGammon is written in Z80 assembly. Everything needed to build it is here: the program's source, and the files it includes — the neural networks' weights, the pictures and the tables — as they are.
Building
With the open-source assembler sjasmplus (1.20 or later), in a folder holding all of these files:
sjasmplus zxgammon.asm
That writes zxgammon.sna, a snapshot to open in an emulator, and
zxgammon.tap, a tape to load with LOAD "". Your tape will be
identical, byte for byte, to the zxgammon.tap you can
download from the front page.
The program loads at $5E00 as one block and starts there: the game
and its pictures, then above $8000 (clear of the memory the screen
slows) the engine that chooses Gnubby's moves, its code and its network's tables,
and the match equity table. The engine works in the top 8 pages of memory and
the bytes below them, with the stack below that, and the game's own memory is
at $5B00, where BASIC was. Interrupts stay off: the keyboard is read
directly, and the engine reads its weights off the stack pointer.
The program
| File | What it is | Bytes |
|---|---|---|
| game.asm | The game: its memory map, what Gnubby says, its pictures; includes the rest, the engine among it. | 8423 |
| play.asm | The title and menu, games and matches, the player's and Gnubby's turns, the doubling cube, the scores. | 44135 |
| screen.asm | The board, checkers, dice, cube, Gnubby, the scores and what he says, drawn only where they change. | 27205 |
| input.asm | The keyboard, the beeper and the dice. | 4252 |
| log.asm | The game as it is played, a record at a time in memory, for whatever reads it from outside (this site catches each and writes the games out as a match file). | 3611 |
| n2ram.asm | The engine's work area. | 6758 |
| n2gen.asm | The legal moves from a position, each position once, with the network's and the filter's sums kept as each checker moves. | 9983 |
| encode.asm | Positions turned about, totals, and other helpers. | 1408 |
| n2net.asm | The neural network, in integers and without multiplication (products from a table of quarter squares): its first layer kept by adding and taking away a row as each checker moves, then products of its units in pairs and the head for the kind of position (contact, crashed or race), to the chances of each result and an equity. | 18504 |
| n2choose.asm | Choosing a move: every legal play scored by the network (the filter's best 99 if there are more), then the best few, while time allows, each tried against all 21 of the opponent's rolls. | 19389 |
| n2cube.asm | For the cube: Gnubby's chances (of winning, and of gammons won and lost) and equity, by the network and a move deeper. | 6895 |
| n2data.asm | The network's weights and the filter's, and the tables they use, as bytes (weights stored plus 128). | 115992 |
| zxgammon.asm | The file to assemble: places the program and the loading screen in memory, and writes the snapshot and the tape (with its BASIC loader). | 1638 |
Included files
Binary files, read in whole by incbin.
| File | What it is | Bytes |
|---|---|---|
| checker | A checker, 16 by 16; then the disc that its counts are cut out of. | 64 |
| cube | The doubling cube's faces: 64 (at 1), 2, 4, ... 64, 128. | 256 |
| dice | The six faces of a die, 16 by 16. | 192 |
| font | The characters, 32 to 95, 8 by 8. | 512 |
| mascot | Gnubby, 32 by 32: calm, happy, sad and thinking. | 512 |
| met16 | GNU Backgammon's match equity table to 7-away, for the cube and for what gammons are worth at a match score. | 112 |
| triangle | A point, 80 lines from its base. | 160 |
| loading.scr | The loading screen, as the Spectrum's screen memory. | 6912 |
Licence
zxGammon 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. It 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.
The emulator on the front page is part of this site's source too: js/z80.js, js/spectrum.js and js/main.js.