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 and starts there: the game, then from
$8000 the engine that chooses Gnubby's moves. It uses
$D700–$F3FF to work in, the cube's table for matches
is at $F400, and the stack is at the top of memory. 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 and tables; includes the rest. | 7834 |
| play.asm | The title and menu, games and matches, the player's and Gnubby's turns, the doubling cube, the scores. | 28458 |
| screen.asm | The board, checkers, dice, cube, Gnubby, the scores and what he says, drawn only where they change. | 24612 |
| input.asm | The keyboard, the beeper and the dice. | 4248 |
| 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 |
| ram.asm | The engine's work area. | 5035 |
| gen.asm | The legal moves from a position, each position once. | 11130 |
| encode.asm | Positions turned about, totals, and other helpers. | 1408 |
| features.asm | GNU Backgammon's 25 contact features of a position, in integer arithmetic. | 24866 |
| net.asm | The neural networks, computed without multiplication: only the inputs that change are added. | 11729 |
| choose.asm | Choosing a move: the filter, the contact (or race) net, and a look a ply ahead over the opponent's 21 rolls; and the same look ahead for the cube. | 12777 |
| data.asm | The networks' layouts, small tables, and the weights' files. | 1330 |
| zxgammon.asm | The file to assemble: places the program, the loading screen and the cube's table in memory, and writes the snapshot and the tape (with its BASIC loader). | 1942 |
Included files
Binary files, read in whole by incbin.
| File | What it is | Bytes |
|---|---|---|
| checker | A checker, 16 by 16; then with each count from 1 to 15 cut out of it. | 512 |
| contact.b1 | The hidden units' biases, 16 bits each. | 96 |
| contact.b2 | The output's bias, 24 bits. | 3 |
| contact.h | The net's hidden units. | 1 |
| contact.w1 | The net's first layer: a row of weights (one a hidden unit) for each input, stored plus 128. | 12912 |
| contact.w2 | The output's weights, one a hidden unit. | 48 |
| 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 |
| filter.b1 | The move filter's bias. | 2 |
| filter.w1 | The move filter's weights, one a board input, stored plus 128. | 202 |
| font | The characters, 32 to 95, 8 by 8. | 512 |
| mascot | Gnubby, 32 by 32: calm, happy, sad and thinking. | 512 |
| moneyrec | The cube's thresholds in money play. | 10 |
| ptnum | The points' numbers, 1 to 24, in small digits. | 384 |
| race.b1 | The hidden units' biases, 16 bits each. | 16 |
| race.b2 | The output's bias, 24 bits. | 3 |
| race.h | The net's hidden units. | 1 |
| race.w1 | The net's first layer: a row of weights (one a hidden unit) for each input, stored plus 128. | 1752 |
| race.w2 | The output's weights, one a hidden unit. | 8 |
| reply.b1 | The hidden units' biases, 16 bits each. | 16 |
| reply.b2 | The output's bias, 24 bits. | 3 |
| reply.h | The net's hidden units. | 1 |
| reply.w1 | The net's first layer: a row of weights (one a hidden unit) for each input, stored plus 128. | 1752 |
| reply.w2 | The output's weights, one a hidden unit. | 8 |
| sig | The sigmoid, as a table (its upper half). | 129 |
| triangle | A point, 80 lines from its base. | 160 |
| loading.scr | The loading screen, as the Spectrum's screen memory. | 6912 |
| mettab.bin | The cube's thresholds in a match, by the score and the cube, from GNU Backgammon's match equity table. | 1260 |
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.