NAME

Game::Backgammon - backgammon as a reusable engine

SYNOPSIS

use Game::Backgammon;

my $game = Game::Backgammon->new(seed => $bytes);
$game->turn;                       # who the opening roll sent first
$game->dice;                       # [5, 2], from the seed

for my $turn (@{ $game->legal_turns }) { print $turn->notation, "\n" }
$game->play('8/3 6/4') or die $@;

$game->status;                     # 'active' or 'finished'
$game->result->margin;             # 'single', 'gammon', 'backgammon'

DESCRIPTION

Pure rules: no input, no output, no clock, and no randomness beyond the seed. A game is its seed plus the turn chosen at each roll, and "replay" rebuilds it from exactly that.

It is the engine behind the backgammon at https://peer2peergames.com.

A turn is the unit

Two dice mean up to two checkers move and doubles mean four, and the rules binding which combinations are legal are properties of the whole set. So legal_turns offers whole turns and play takes one. See Game::Backgammon::Rules.

The dice are checkable but not predictable

Roll n is SHA-256($seed . "roll:$n:..."), so a finished game can be replayed and verified from its seed, while somebody who learns the seed mid-game learns nothing about what is coming. See Game::Backgammon::Dice.

No doubling cube, and no draws

There is no cube: it is not a wager, but it reads like one, and leaving it out costs the game little. Backgammon cannot be drawn, so a result always has a winner.

METHODS

new(seed => $bytes)

The opening roll decides who starts and gives them their dice.

status, result, turn, board, history, to_log

seed

The 32 bytes every roll is derived from.

rolls

How many rolls the game has consumed: the dice index replay needs.

pending

The dice rolled and not yet played.

other

The other player's name.

finish(winner => ..., reason => ...)

A finish imposed from outside: a resignation, a timeout, an abandoned game. A resignation concedes a single.

replay(seed => ..., turns => [ '8/5 6/5', ... ])

SEE ALSO

Game::Backgammon::Board, Game::Backgammon::Rules, Game::Backgammon::Dice, Game::Backgammon::Result.

AUTHOR

LNATION, <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under the Artistic License 2.0.