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
- The engine must answer
bgap 1withbgapokwithin the start-up time limit (120 seconds, so that engines have time to load their weights). idlines may also be sent betweenisreadyandreadyok, for example a version the engine only learns while loading.optionandidlines describe the engine and its settings (see Describing the engine). A room's settings are applied withsetoptionbeforeisready.- After
quitthe engine should exit promptly. It is killed after 100 ms.
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
- Settings. An option is first defined UCI-style (
option name NAME type ...); names are one word. Rooms are offered itscomboandcheckoptions, as a choice of thevarvalues or a tick box.spin,stringandbuttonoptions, and any markedhidden, are the engine's own business (paths, caches) and keep their defaults, exceptthreads: an engine that has it is set to the number of CPU cores the room gives each bot (both bots get the same). A room always sets every offered option explicitly. - Beavers.
option name beavers type checksays the engine plays beavers. It isn't offered to rooms: it is set to the room's rule,trueorfalse, beforeisready. - Wording, each on its own line after the definition, the text running to the end of the line:
labelnames the setting in the room form,helpsays in one sentence what it does,var VALUE labelis how a choice reads, andvar VALUE taga short form shown in a bot's name when the choice isn't the default (noise 0.015). A check option hastag onandtag offinstead. - Level.
option name NAME searchmarks the combo that sets the engine's level (its search depth, or whatever it calls its strength): a bot is named by its engine and that choice's label, “gnubg 2-ply”. Labels are shown as the engine gives them, with no meaning read into them, so use the names your engine's own users know:2-ply,Roller++orstrong. - Formats.
id maxmatch N: the longest match it plays,0for money games only,1for money games and 1-point matches. Without it, any. - Slow choices.
option name NAME var VALUE slowis a hint that a choice can take minutes a decision. The arena times every choice itself on its own hardware when it registers the engine, and uses that instead: a slow choice gets a longer decision limit, and one that doesn't answer within two minutes isn't offered.
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
| Request | Meaning | Reply |
|---|---|---|
go move | Play the dice shown in the position. | move notation |
go cube | You are on roll, before rolling. Do you double? | double or nodouble |
go take | The 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:
go moveisn't sent if there is no legal move or only one legal play.go cubeisn't sent when the player may not double: in the Crawford game, with the cube owned by the opponent or at its limit, in cubeless play, or in a match the player already wins with the current cube value.
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.
| Field | Meaning |
|---|---|
| board | 26 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. |
| cube | log2 of the cube value (0 = 1, 1 = 2, ...). For go take, the value before the double. |
| cubepos | 0 centred, 1 X owns the cube, -1 O owns it. |
| turn | 1 (X decides). |
| dice | go move: the two dice, e.g. 52. go cube: 00. go take: D. |
| score1, score2 | The match score of X and of O; 0 in money play. |
| cj | Match play: 1 in the Crawford game. Money play: 1 Jacoby, 2 beavers allowed (Beavers), 3 both. |
| len | Match length; 0 is a money game. |
| maxcube | log2 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:
| Form | Example |
|---|---|
| one step per die | 24/18 13/11, 25/22 6/5, 3/0 2/0 |
| chains | 24/18/13, 13/5 |
| repetition | 8/5(2) 6/5(2) |
| hit marks | 13/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.