Howdy, world! – bgammon.org – Free On-line Backgammon
A technical overview of the software program powering bgammon.org
On this put up I share my expertise with creating the bgammon.org server and consumer utilizing
free and open source
instruments. This contains Linux, the Go
programming language and the VSCodium IDE.
Whereas a lot of free and open supply backgammon software program exists, all the
servers that had been out there in late 2023 had been proprietary.
I’ve loved taking part in chess on Lichess for a number of
years, and have at all times admired their mannequin: free and open supply, no advertisements, no
paid advantages and no registration requirement. They are saying immitation is the
sincerest type of flattery.
I created Boxcars, a graphical
consumer for enjoying backgammon on-line, initially for the FIBS
backgammon server in late 2021. The mission was basically feature-complete
however by no means discovered a consumer base. Quick-forward two years to late 2023, and an thought
for a mission that has been brewing at the back of my head for a while begins
to look not simply potential, however vital: to make it potential to play backgammon
on-line utilizing free software.
I created bgammon, the server
part of bgammon.org, and tailored Boxcars to connect with this new server
as a substitute. Utilizing the perception I gained as a FIBS consumer writer of issues that work
properly and issues that had been (in my expertise) obscure or
implement, I wrote the specification for a protocol
that’s impressed by FIBS whereas additionally being distinct in methods similar to using a
commonplace knowledge interchange format (JSON)
for messages despatched by the server.
In the remainder of this weblog put up, I’ll describe the extra technical elements of
the creation of the bgammon.org server and consumer.
Server
Link to heading
The server was created with effectivity in thoughts from the start. There are some
low-hanging optimization fruits but to be picked, however I’ve executed my greatest to
select a knowledge format and scheme which is environment friendly in its use of processor and
reminiscence sources. That is partly executed simply pretty much as good software program design follow, however
additionally it is vital to make video games and community site visitors environment friendly as a result of
bgammon.org doesn’t have any ads or sponsorships. The infrastructure
for the server must be lightweight to maintain the price to the writer as little
as potential.
Due to this fact, the state of the board is saved as an array of integers, the place the
worth of every cell specifies what number of checkers are on a board house. Constructive
integers symbolize participant 1 (black) and damaging integers symbolize participant 2
(white). This array is referenced and copied and mutated many occasions because the server
evaluates all the potential strikes a participant could make to find out which authorized
strikes can be found. In backgammon, if you can also make a transfer that means that you can
then make a second transfer, however you would as a substitute make a transfer the place you might be solely
in a position to make one transfer after which finish your flip, you might be requred to make a transfer
that means that you can then make a subsequent transfer.
In contrast to chess, the place areas have the identical identify no matter whether or not it’s from
white or black’s perspective of the board, backgammon areas are numbered from
the angle of every participant. This implies when black strikes 24/22, if white
had been to maneuver in the wrong way from black’s 22 to 24, white would
understand the transfer as 3/1. To simplify dealing with this, the server solely shops the
board state from the angle of participant 1, and flips the state despatched to
participant 2 and strikes obtained from participant 2. Thus, the board is represented to
participant 2 appropriately with out requiring duplication of logic in every single place the
server analyzes the board state.
Consumer instructions include a single line of plain textual content, the place the command is the
first phrase of the road, and the command parameters make up the remainder of the road.
For example, to attach, a consumer may ship loginjson boxcars rocket9 s3cr3t
to log in utilizing a consumer named boxcars.
Server messages are despatched to shoppers in JSON format. This makes it straightforward for
shoppers to parse and validate knowledge despatched by the server. Whereas it’s a format
designed for use by computer systems, JSON remains to be very human-readable and it’s
not troublesome to learn and perceive a log of bgammon.org community site visitors.
Consumer
Link to heading
The official consumer makes use of extra libraries than every other mission I’ve
created. On the time of scripting this weblog put up, it makes use of 12 libraries straight,
a number of of which I authored to assist facilitate creating Boxcars, and 41
extra libraries not directly.
Ebitengine – Sport engine
Link to heading
Ebitengine is an unbelievable recreation engine. It’s straightforward
to make use of and perceive, the API design is straightforward, and it compiles to an incredible
variety of platforms.
This contains WebAssembly and
Android, which may be very interesting to any developer who needs to focus on a number of
platforms from a single code base.
messeji – Textual content show and enter
Link to heading
messeji is a library for drawing
textual content on the display screen in addition to dealing with textual consumer enter. It options an
environment friendly phrase wrapping implementation that permits very giant textual content buffer sizes
even when operating in a single-threaded context.
kibodo – On-screen keyboard
Link to heading
kibodo is a library that permits
functions operating on touch-enabled gadgets to just accept keyboard enter. This
library is critical as a result of toggling the system on-screen keyboard shouldn’t be
supported by Ebitengine.
etk – GUI instrument equipment
Link to heading
etk is a library that simplifies the
creation of graphical consumer interfaces. It offers a widget framework that makes
focus and consumer enter propagation far simpler to handle in comparison with implementing
customized logic in every single place it’s wanted within the utility. etk offers a number of
widgets out of the field, but in addition makes it potential to create customized widgets
that combine seamlessly with the official widgets. The Grid widget, for
occasion, permits the creation of versatile display screen layouts that perform throughout
desktop and cell platforms.
tabula – Backgammon AI
Link to heading
tabula is a library that analyzes
backgammon positions and makes an attempt to find out the perfect transfer. It accomplishes
this by performing a sequence of weighted calculations which I describe intimately
on this page.
Generally it wins, however it solely appears one
step forward within the recreation, whereas extra highly effective backgammon engines will often
look many extra steps forward. tabula doesn’t do that as a result of that takes a protracted
time. Whereas I do my greatest to make tabula as difficult as potential, it’s
inside the constraint of taking just a few seconds at most to find out the
greatest transfer on a low-powered Android cellphone.