NAME

Game::Merrills::Board - the 24 points, the men on them and the men still in hand

VERSION

Version 0.03

SYNOPSIS

use Game::Merrills::Board;
use Game::Merrills::Points;

my $board = Game::Merrills::Board->new;

my $d2 = Game::Merrills::Points::point('d2');
$board->set($d2, 'white');
$board->side_at($d2);          # 'white'
$board->count('white');        # 1
$board->in_hand('white');      # 9, the board does not move men for you
$board->in_mill($d2);          # 0

DESCRIPTION

A board is what a photograph of the table would show: which points hold a white man, which a black one, and how many men each side has yet to place.

It knows nothing of turns or of what is legal. Setting a point does not take a man from a hand, and nothing stops a man being set where the rules would never allow it. The board refuses only what could not be a position at all: a cell that is not a man or empty, a hand that is not a count, and a side with more than nine men between its hand and the board.

Sides are the strings white and black. Points are the numbers of Game::Merrills::Points. A side that is neither, or a point that is not one, is a programming mistake and dies.

PROPERTIES

cells

Read and write arrayref of 24 values, one a point in point order, each EMPTY, WHITE or BLACK. Defaults to an empty board.

my $board = Game::Merrills::Board->new(cells => \@cells);

hand

Read and write hashref of the men each side has not yet placed, keyed white and black. Defaults to nine each.

my $board = Game::Merrills::Board->new(hand => { white => 0, black => 0 });

METHODS

opening

The cells of an empty board, a fresh arrayref each time. Callable as a function.

my $cells = Game::Merrills::Board->opening;

at

The value on a point: EMPTY, WHITE or BLACK.

$board->at($point);

side_at

The side whose man is on a point, or undef when it is empty.

$board->side_at($point);       # 'black'

set

Puts a man of a side on a point, or clears the point when the side is undef. Returns the board.

$board->set($point, 'black');
$board->set($point, undef);

empty

True when no man is on the point.

$board->empty($point);

points_of

The points a side has men on, in point order.

my @points = $board->points_of('white');

count

How many men a side has on the board.

$board->count('white');

in_hand

How many men a side has yet to place.

$board->in_hand('black');

men

The men a side has left, on the board and in hand together. A side with fewer than three has lost.

$board->men('black');

in_mill

True when the man on a point is one of three of its side in a row. False for an empty point.

$board->in_mill($point);

clone

A board with the same men and the same hands, sharing nothing with this one.

my $copy = $board->clone;

CONSTANTS

EMPTY

0, a point with no man on it.

WHITE

1, a white man.

BLACK

-1, a black man.

MEN

9, the men each side starts with.

PACKAGE VARIABLES

%VALUE

The cell value of each side name.

%SIDE

The side name of each cell value.

AUTHOR

LNATION, <email at lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)