NAME
Game::Dominoes::Rules - which plays are legal, and what they would score
VERSION
Version 0.01
SYNOPSIS
use Game::Dominoes::Rules qw(candidates can_play);
my $moves = Game::Dominoes::Rules::candidates($layout, $hand);
# [ { tile => $tile, arm => 'L' }, ... ]
Game::Dominoes::Rules::can_play($layout, $hand); # 1 or 0
Game::Dominoes::Rules::score_of($layout, $tile, 'L'); # what it would score
DESCRIPTION
Move generation, as functions rather than a class, because the bot calls this far more often than anything else here.
It is deliberately not the raw unblessed array interface that Game::Checkers::Rules uses. That shape exists there because alpha-beta over a checkers position visits millions of nodes and allocating an object per move was measurable. Whether dominoes needs the same depends on how the determinised search behaves, and writing the awkward version before anything has been measured would be guessing at a cost nobody has paid yet.
FUNCTIONS
candidates
my $moves = candidates($layout, $hand);
Every legal tile and arm pairing, as an arrayref of { tile => ..., arm => ... }.
The order is stable: the hand in canonical tile order, then the arms L, R, U, D. A bot that takes the first of several equal moves therefore takes the same one on every machine and every perl, which is what makes a game replayable.
On an empty table every tile is a candidate, because the opening lead may be any tile.
can_play
can_play($layout, $hand);
Whether the hand has any legal play at all. This is the question that decides whether a turn is a decision or a forced draw.
score_of
score_of($layout, $tile, 'L');
score_of($layout, $tile, 'L', 5); # on the divided scale
What a play would score, without committing to it.
It works on a copy of the layout. Placing and then unplacing would be faster and would have to undo the spinner bookkeeping, and an undo that is subtly wrong produces a bug that surfaces several plays later in a different part of the table.
SEE ALSO
Game::Dominoes::Layout, Game::Dominoes::Scoring.
AUTHOR
LNATION <email@lnation.org>
BUGS
Please report any bugs or feature requests to bug-game-dominoes at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Dominoes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Game::Dominoes::Rules
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)