NAME

Game::Backgammon::Notation - standard notation, parsed and printed

SYNOPSIS

use Game::Backgammon::Notation qw(parse_turn print_turn);

my $turn = parse_turn('8/5 6/5', player => 'white') or die $@;
print_turn($turn);                 # '8/5 6/5'
parse_turn('bar/20 13/11*', player => 'black');
parse_turn('13/7/5', player => 'white');    # one checker, two hops

DESCRIPTION

Both directions of the notation a backgammon player writes. 8/5(2) is two checkers making the same move; 13/7/5 is one checker making two, and expands to 13/7 7/5.

It does not know the rules

The parser produces the moves the line says and nothing more: not whether they are legal, not which dice they needed, not whether the hits are real. That belongs to the rules, and a parser that half-knew them would be a second place for them to be wrong. The die on a parsed move is undef where the position decides it, which is entering from the bar and bearing off.

A line that is not notation returns undef with the reason in $@. It came from a player; refusing it is an ordinary answer, not an exception.

FUNCTIONS

parse_turn($line, player => $who, dice => \@dice)

A Game::Backgammon::Turn, or undef with the reason in $@.

The turn as a line of notation.