NAME
Game::Cribbage::Score - hand scoring calculator
VERSION
Version 0.12
SYNOPSIS
use Game::Cribbage::Score;
# score a 4-card hand without the starter
my $score = Game::Cribbage::Score->new(
with_starter => 0,
cards => \@cards,
);
print $score->total_score;
# score with the starter (5th card)
my $score = Game::Cribbage::Score->new(
with_starter => 1,
cards => [@hand_cards, $starter],
);
print $score->total_score;
DESCRIPTION
Calculates the cribbage hand score for a set of Game::Cribbage::Deck::Card objects by enumerating all scoring combinations: fifteens, pairs, three/four of a kind, runs, flushes, and nobs. Scoring is performed in BUILD immediately after construction; the result is available via total_score.
PROPERTIES
total_score
Read/write integer property holding the computed total score. Set by calculate_total during construction.
$score->total_score;
scored
Readonly hashref containing the point value for each scoring category. Built automatically.
$score->scored;
# {
# fifteen => 2,
# pair => 2,
# three_of_a_kind => 6,
# four_of_a_kind => 12,
# run => [3, 4, 5],
# four_flush => 4,
# five_flush => 5,
# nobs => 1,
# }
fifteen
Read/write arrayref of card-group arrayrefs, each group summing to 15.
$score->fifteen;
pair
Read/write arrayref of paired card groups.
$score->pair;
three_of_a_kind
Read/write arrayref of three-of-a-kind card groups.
$score->three_of_a_kind;
four_of_a_kind
Read/write arrayref of four-of-a-kind card groups.
$score->four_of_a_kind;
run
Read/write arrayref of run card groups (runs of three, four, or five).
$score->run;
four_flush
Read/write arrayref populated when exactly four cards share a suit.
$score->four_flush;
five_flush
Read/write arrayref populated when all five cards (including starter) share a suit.
$score->five_flush;
nobs
Read/write arrayref populated when the hand contains a Jack whose suit matches the starter card.
$score->nobs;
cards
Read/write arrayref of Game::Cribbage::Deck::Card objects to score. The last element is treated as the starter when with_starter is true.
$score->cards;
with_starter
Readonly boolean indicating whether the last element of cards is the starter card. When true, nobs scoring is applied.
$score->with_starter;
FUNCTIONS
calculate_nob
Checks whether the hand contains a Jack matching the starter suit, and if so pushes it onto nobs. Only called when with_starter is true.
$score->calculate_nob($starter, @cards);
calculate_run
Enumerates all card subsets to find runs of three, four, or five consecutive run-values and stores them in run.
$score->calculate_run(@cards);
calculate_flush
Detects four-card or five-card flushes and populates four_flush or five_flush accordingly.
$score->calculate_flush(@cards);
calculate_fifteen
Finds all card subsets whose pip values sum to 15 and pushes them onto fifteen.
$score->calculate_fifteen(@cards);
calculate_of_a_kind
Groups cards by symbol and populates pair, three_of_a_kind, or four_of_a_kind as appropriate.
$score->calculate_of_a_kind(@cards);
calculate_total
Sums the contribution of every populated scoring category and stores the result in total_score.
$score->calculate_total();
AUTHOR
LNATION, <email at lnation.org>
BUGS
Please report any bugs or feature requests to bug-game-cribbage at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Cribbage. 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::Cribbage
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2024 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)