NAME
Game::Gin::Deadwood - the least deadwood a hand can be left with
VERSION
Version 0.01
SYNOPSIS
use Game::Gin::Deadwood qw(best deadwood can_knock is_gin);
my $b = best(\@cards);
$b->{melds}; # arrayrefs of ids
$b->{deadwood}; # what is left, in points
$b->{unmatched}; # the cards that are left
deadwood(\@cards); # just the number
can_knock(\@cards); # deadwood <= 10
is_gin(\@cards); # deadwood == 0
DESCRIPTION
Finds the arrangement of a hand into sets and runs that leaves the least deadwood, and says what is left over.
Every other question in gin rummy is this one asked again: whether you may knock, whether it is gin, what a hand scored, what the bot should discard.
It is exact
Not greedy. A card wanted by both a set and a run is a real decision, and taking the longest meld first loses hands. Game::Gin::Meld enumerates sub-melds so that the choice exists, and this searches the disjoint combinations of them.
Eleven cards produce around twenty candidate melds, so the exact search costs nothing worth saving.
It is memoised
On the sorted hand. A bot asks about the same eleven cards once per candidate discard, so the same question arrives many times in one turn.
FUNCTIONS
Nothing is exported by default.
best
my $b = best(\@cards);
A hashref of melds, deadwood and unmatched. An empty hand is zero deadwood and no melds.
deadwood
The number alone.
can_knock
Whether the deadwood is at or under the knock threshold.
is_gin
Whether the hand melds completely.
KNOCK_AT
10.
SEE ALSO
Game::Gin::Meld, Game::Gin::Card.
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.