Sign in

For bot developers

BGAP, version 1

BGAP (BG Arena Protocol) is how the bgbotarena referee talks to backgammon engines. An engine is a program that reads commands on standard input and writes replies on standard output, one per line (\n; a trailing \r is tolerated). Engines that don't speak BGAP natively are wrapped in a small adapter.

The referee owns the game. It rolls the dice, generates the legal moves, validates every reply and applies it. Engines are stateless per decision: every request carries the complete position, so an engine never needs to track a game and can be restarted at any time.

Below, > is the referee to the engine and < the engine to the referee.

Session

> bgap 1
< id name gnubg                 (optional, shown on the site)
< id version 1.07.001           (optional)
< option name plies type combo default 2 var 0 var 1 var 2 var 3 var 4   (optional, see below)
< bgapok
> setoption plies 2             (zero or more: setoption NAME VALUE)
> isready
< readyok
  ... decisions ...
> quit

Describing the engine

Between bgap 1 and bgapok, an engine describes itself: which settings rooms may choose and how they read, in its own words. The arena reads this when it registers the engine; nothing about an engine's settings is kept by hand. Every line is optional; an engine that sends none is offered with its defaults only.

< id name gnubg
< id version 1.08.003
< option name plies type combo default 2 var 0 var 1 var 2 var 3 var 4
< option name plies label Search
< option name plies search
< option name plies var 0 label 0-ply
< option name plies var 1 label 1-ply
  ...
< option name prune type check default true
< option name prune label Pruning networks
< option name prune tag off no pruning
< option name noise type combo default 0 var 0 var 0.015 var 0.04
< option name noise var 0.015 label 0.015 (gnubg's Advanced level)
< option name noise var 0.015 tag noise 0.015
< option name threads type spin default 1 min 1 max 64
< option name beavers type check default false
< bgapok

Decisions

Each decision is a position line followed by a go line:

> position XGID=-b----E-C---eE---c-e----B-:0:0:1:52:0:0:0:7:10
> go move
< move 13/11 13/8
RequestMeaningReply
go movePlay the dice shown in the position.move notation
go cubeYou are on roll, before rolling. Do you double?double or nodouble
go takeThe opponent has doubled you.take or pass (drop is accepted), or beaver where allowed

Before replying, an engine may write any number of lines starting with info (e.g. info equity +0.123). The referee ignores them for now.

The referee doesn't ask when the answer is forced:

Beavers

Some money rooms play beavers: a player who is doubled may answer beaver, taking the double and redoubling at once while keeping the cube. A double from 1 to 2 that is beavered leaves the cube at 4, owned by the beaverer, and the doubler plays on (there are no raccoons). Beavers are allowed on any double, within the room's cube limit.

The beaver flag (bit 2 of the XGID's cj field) is set in every position of such a room, so an engine can allow for being beavered when it doubles. In a go take it is cleared when a beaver would pass the cube limit. A beaver reply to a position without the flag is illegal, and is reported against the engine like any illegal reply. An engine that plays beavers declares it with the beavers option; one without it can still play in such rooms, and is shown there as not playing beavers.

Time limit

Each decision must be answered within the room's limit (60 seconds; 10 minutes for slow settings, 30 for eXtreme Gammon's). Exceeding it, crashing, or replying with something illegal ends the match as an error, reported against that engine. The limit only catches engines that hang: it is never sent to the engine, and an engine should search as its settings say, not budget its time against it.

Positions (XGID)

XGID=<board>:<cube>:<cubepos>:<turn>:<dice>:<score1>:<score2>:<cj>:<len>:<maxcube>

The deciding player is always X: the bottom player, uppercase letters, moving from point 24 towards point 1. The turn field is therefore always 1, also for go take, where X is the player answering the double.

FieldMeaning
board26 characters. Index 0 is O's bar, 1 to 24 are points 1 to 24 from X's side, 25 is X's bar. A to O are 1 to 15 X checkers, a to o O checkers, - empty.
cubelog2 of the cube value (0 = 1, 1 = 2, ...). For go take, the value before the double.
cubepos0 centred, 1 X owns the cube, -1 O owns it.
turn1 (X decides).
dicego move: the two dice, e.g. 52. go cube: 00. go take: D.
score1, score2The match score of X and of O; 0 in money play.
cjMatch play: 1 in the Crawford game. Money play: 1 Jacoby, 2 beavers allowed (Beavers), 3 both.
lenMatch length; 0 is a money game.
maxcubelog2 of the cube limit; 0 (a limit of 1) when the room plays without the cube.

The starting position, X to play 5-2 in a 7-point match at 0-0:

XGID=-b----E-C---eE---c-e----B-:0:0:1:52:0:0:0:7:10

Move notation

Moves are written from the mover's (X's) side: points 1 to 24, bar (or 25) and off (or 0). The referee accepts any unambiguous standard form:

FormExample
one step per die24/18 13/11, 25/22 6/5, 3/0 2/0
chains24/18/13, 13/5
repetition8/5(2) 6/5(2)
hit marks13/7*, 24/23*/18

The reply is matched against the legal plays by the position it leads to. Hit marks (*) are optional, and only needed to tell apart two plays that move the same checkers but hit differently, such as 24/23*/18 and 24/18.

Our test suite checks an engine's image against this page, the way we check it before any room can use it.

Questions, or a case this page doesn't settle: bots@bgbotarena.net.