NAME

Game::Backgammon::Dice - the rolls, as a pure function of the seed

SYNOPSIS

use Game::Backgammon::Dice qw(roll_for opening_for);

my ($a, $b) = roll_for($seed, 0);          # the same, always
my @dice    = Game::Backgammon::Dice::dice_for($seed, 3);   # four on doubles
my ($first, $dice, $used) = opening_for($seed);

DESCRIPTION

roll_for($seed, $n) is the $nth roll of the game whose seed is $seed, as two faces. It is a pure function, so the same inputs give the same roll on every machine and at any time.

Hashed per roll, not drawn from a stream

Both are reproducible. Only this one is unpredictable to somebody who learns the seed while the game is still going, which in a game decided by dice is the difference between a checkable record and a solved game. The same choice and the same reasoning are in P2PGames::Game::Ludo::Dice.

The opening roll

opening_for plays the real opening: one die each, higher starts and plays the pair, ties re-rolled. Each tie consumes a roll number so the log's numbering stays honest.

FUNCTIONS

roll_for($seed, $n)

The $nth roll, as two faces.

dice_for($seed, $n)

What that roll actually plays: two faces, or four of the same on doubles.

opening_for($seed)

($player, [$d1, $d2], $rolls_used): one die each, higher starts, ties re-rolled.

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.