gnubg_web is a port of GNU Backgammon to the web, with nearly all the features of the original.
A Javascript GUI replaces the GTK-based GUI in the original.
gnubg_web is built using Emscripten, which compiles the gnubg C source code and the glib libraries used by it, into Javascript and Webassembly. Webassembly is supported by the latest modern browsers.
Instructions for building and testing:
-
Install Emscripten. Then activate the PATH and other environment variables by running
source /path/to/emscripten/emsdk_env.sh. For more information on this step, see the Emscripten documentation. The latest version of Emscripten which has been tested to successfully buildgnubg_webis 2.0.23. -
Execute
./build.shfrom within the gnubg_web directory. -
This will generate several files within a
builddirectory. To test the build locally, start a webserver inside thebuilddirectory. If you have Python 3 installed, a simple way is to runpython -m http.server 8000from within thebuilddirectory. (For Python 2, usepython -m SimpleHTTPServer 8000.) Then go tohttp://localhost:8000/gnubg_web.htmlfrom your browser. Note that opening thegnubg_web.htmlfile directly from your browser probably won't work, because of CORS restrictions for local files on the latest browsers. If you really cannot get anything else to work, you can look up how to disable such restrictions in your browser, but this is not recommended.
The gnubg subdirectory contains the original source code for GNU Backgammon version 1.05.000, with the following changes:
-
Some source files are not needed in the web version, and have been moved to a
removed_filessubdirectory withingnubg, which doesn't get compiled when buildinggnubg_web. This includes the GTK-related files (since the GTK GUI has been replaced by a Javascript GUI),openurl(for opening files within a browser) andexternal(for connecting to an external player). -
A few modifications to the original source have been made, primarily to interact with the Javascript GUI properly. These changes are marked with
#ifdef WEBor#ifndef WEBblocks. -
The
packaged_filessubdirectory consists of several data files needed. These are the neural network weightsgnubg.wd, the one-sided bearoff databasegnubg_os0.bd, all the match equity tables in themetsubdirectory, and some startup settings in.gnubg/gnubgrcneeded by the web version. Note that due to its size, the two-sided bearoff databasegnubg_ts0.bdis currently not packaged. However, it is included in thegnubgsubdirectory. If you wish to package it, you can copy this file to thepackaged_filessubdirectory before building. -
Sounds have been disabled. Although it probably wouldn't be difficult to get them working using Javascript, it didn't seem worth the increased binary size (which increases the download time when serving the binary over the web).
GNU Backgammon uses the glib libraries extensively. Because Emscripten needs to build everything from scratch, a copy of the glib 2.62.0 source code is included in the subdirectory glib/glib-2.62.0, configured to work with Emscripten. Many of glib's necessary configuration parameters (#defines) have been consolidated into config.h within gnubg.
Not all of glib is needed for compiling gnubg_web, so some of the *.c source files have been renamed as *.c_do_not_compile. If you make some changes that need one of the files, you should rename them back to *.c. However, note that some of the source files -- particularly anything related to Windows, such as gwin32 -- will not work in the Emscripten environment.