| 1 | package Poker::Eval::Badugi; | ||||||||||||||||||||||||||||
| 2 | 2 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Algorithm::Combinatorics qw(combinations); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Poker::Score::Badugi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Poker::Eval::Badugi - Evaluate and score Badugi poker hands. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Version 0.12 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | See Poker::Eval for code examples | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | extends 'Poker::Eval'; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub best_hand { | ||||||||||||||||||||||||||
|
Subroutine
best_hand: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 4 | my ( $self, $hole ) = @_; | |||||||||||||||||||||||||||
| 31 | 4 | my $best = Poker::Hand->new(cards => $hole); | |||||||||||||||||||||||||||
| 32 | 4 | ▶ | my $iter = combinations( $hole, scalar @$hole > 4 ? 4 : scalar @$hole); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | while (my $combo = $iter->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 12 | my (@list, %seen); | |||||||||||||||||||||||||||
| 35 | 12 | for my $c (sort { $self->scorer->_rank_map->{$a->rank} <=> $self->scorer->_rank_map->{$b->rank} } @$combo) { | |||||||||||||||||||||||||||
| 36 | 48 | ▶ | if ( !$seen{ $c->suit } && !$seen{ $c->rank } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seen{$c->suit} or $seen{$c->rank}
MC/DC50%1/2
$seen{$c->suit} or $seen{$c->rank}
$seen{$c->suit}
$seen{$c->rank}
Truth table66%2/3
A or B
A= $seen{$c->suit}B= $seen{$c->rank}
| |||||||||||||||||||||||||||||
| 37 | 42 | push @list, $c; | |||||||||||||||||||||||||||
| 38 | 42 | $seen{ $c->suit }++; | |||||||||||||||||||||||||||
| 39 | 42 | $seen{ $c->rank }++; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 12 | my $score = $self->scorer->score( [@list] ); | |||||||||||||||||||||||||||
| 43 | 12 | ▶ | if ( defined $score && $score >= $best->score ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $score and $score >= $best->score
MC/DC50%1/2
defined $score and $score >= $best->score
defined $score
$score >= $best->score
Truth table66%2/3
A and B
A= defined $scoreB= $score >= $best->score
| |||||||||||||||||||||||||||||
| 44 | 4 | $best->score($score); | |||||||||||||||||||||||||||
| 45 | 4 | $best->best_combo(\@list); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 4 | $best->name($self->scorer->hand_name( $best->score )); | |||||||||||||||||||||||||||
| 49 | 4 | return $best; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Nathaniel Graham, C<< <ngraham at cpan.org> >> | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Copyright 2016 Nathaniel Graham. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 61 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||
| 62 | copy of the full license at: | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | 1; | |||||||||||||||||||||||||||