NAME

Game::Checkers::Board - the 32 playing squares and what stands on them

VERSION

Version 0.01

SYNOPSIS

use Game::Checkers::Board;

my $board = Game::Checkers::Board->new;          # the opening position
$board->at(11);                                  # 1, a black man
$board->piece(11)->colour;                       # 'black'
$board->count('white')->{total};                 # 12

my ($board, $turn) = Game::Checkers::Board->from_fen('B:W21,22:BK7');

DESCRIPTION

The board is a position arrayref and the queries over it. Game::Checkers::Piece objects are built on demand and are never stored.

PROPERTIES

position

Read and write arrayref of 33 values, index 0 unused so a square number indexes itself. Each value is 0 for an empty square, 1 a black man, 2 a black king, -1 a white man and -2 a white king.

The signed encoding is the documented state and not an implementation detail: the search in Game::Checkers::Bot copies one of these arrays for every node it visits, so the cost of a node is the copy and nothing else, and the sign makes an evaluation symmetric. Defaults to the opening position, and is validated at construction.

$board->position;

CONSTANTS

EMPTY, BLACK_MAN, BLACK_KING, WHITE_MAN and WHITE_KING are the five position values.

FUNCTIONS

opening_position

Class method returning a fresh arrayref of the opening position, black men on 1 to 12 and white men on 21 to 32.

my $position = Game::Checkers::Board->opening_position;

at

The position value on a square.

$board->at(15);

set

Sets the position value on a square and returns the board.

$board->set(15, Game::Checkers::Board::BLACK_KING);

occupied

True when a square holds a piece.

$board->occupied(15);

empty

True when a square holds nothing.

$board->empty(15);

colour_at

black, white, or undef for an empty square.

$board->colour_at(15);

king_at

True when the square holds a king.

$board->king_at(15);

piece

A Game::Checkers::Piece for the square, or undef when it is empty. Built on demand, so two calls return two objects.

$board->piece(15);

pieces

An arrayref of Game::Checkers::Piece for one side, or for both when no side is given, in ascending square order.

$board->pieces('black');

count

A hashref of men, kings and total for one side, or for both when no side is given.

$board->count('white');

clone

A new board with a copy of the position, so mutating one leaves the other alone.

my $copy = $board->clone;

to_fen

The FEN for this position and the given side to move.

$board->to_fen('black');

from_fen

Class method building a board from a FEN. Returns the board in scalar context and the board and the side to move in list context. Dies on a malformed FEN. Pass strict => 1 to refuse more than twelve pieces of a colour.

my ($board, $turn) = Game::Checkers::Board->from_fen($fen);

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-game-checkers at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Checkers. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Game::Checkers

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)