NAME
Game::Backgammon::Board - the position, and the only thing that knows which way round it is
SYNOPSIS
my $b = Game::Backgammon::Board->new; # the opening position
$b->mine_on('white', 6); # 5
$b->is_blocked('white', 1); # 1: black has two there
$b->pip_count('white'); # 167
$b->all_home('black'); # 0
DESCRIPTION
Twenty-four points as one signed array: +n is n white checkers, -n is n black. A point holds one colour or nothing, which the sign says exactly, and which makes a point holding both colours unrepresentable rather than merely untested.
Numbering, and why only this class knows it
Points are numbered 1 to 24 from each player's own side, so your 1 point is your opponent's 24. The array is stored from white's, and index_for converts. Nothing outside this class indexes the array: the direction is where the bugs in a backgammon engine live, so exactly one piece of code knows about it and a test greps the tree to keep it that way.
Methods
point_for($player, $n) returns ($mine, $theirs), both positive, so a rule reads the way it is spoken. mine_on, theirs_on, is_blot and is_blocked are the shorthands the rules actually use.
pip_count counts a checker on the bar as 25. all_home is false while anything is on the bar, which is what stops a player bearing off after being hit.
consistent returns a list of complaints, empty when the position is sound.
METHODS
opening
The starting position, as the signed array.
clone
An independent copy. The rules walk a tree of positions, so nothing shares.
other
The other player's name.
index_for($player, $n)
That player's point $n as an index. The only place direction is known.
point_for($player, $n)
($mine, $theirs), both positive.
mine_on($player, $n), theirs_on($player, $n)
One half of point_for each.
is_blot($player, $n)
Exactly one of theirs: the thing you can hit.
is_blocked($player, $n)
Two or more of theirs: you may not land there.
bar($player), off($player)
That side's count on the bar and in the tray.
bar_counts, off_counts, points
The raw attributes. Prefer the readers above.
set_point($player, $n, $count), add($player, $n, $delta)
to_bar($player, $delta), to_off($player, $delta)
occupied($player)
[ [ point, count ], ... ], highest point first.
checkers_on_points($player)
pip_count($player)
The sum of distances home; a checker on the bar counts 25.
all_home($player)
True when every checker is in the home board, which bearing off needs. False while anything is on the bar.
highest_occupied($player)
The highest point still occupied, or 0.
consistent
A list of complaints, empty when the position is sound.
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.