Eval/Wild.pm

filter: Statementstmt 81.8% 45 / 55 Branchbran 62.5% 15 / 24 Conditioncond 40.0% 2 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 73.6% 67 / 91 CC 18 SCAR 31.6
CC
18
Cov
74%
best_hand
26.2
BEGIN
1.0
BEGIN
1.0
CRAP 23.7
« Score/Bring/Wild.pm ↑ Summary Score/Bring/High.pm »
1 package Poker::Eval::Wild;
2 3 our $VERSION = '0.12';
3  
4  
5 3 ▶use Algorithm::Combinatorics qw(combinations combinations_with_repetition);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Poker::Eval::Wild - Evaluate and score wildcard poker hands.
11  
12 =head1 VERSION
13  
14 Version 0.12
15  
16 =cut
17  
18  
19 =head1 SYNOPSIS
20  
21 See Poker::Eval for code example.
22  
23 =head1 INTRODUCTION
24  
25 Evaluate highball wildcard hands. The lowball wildcard evaluator doesn't quite work yet. To mark a card as wild, set the wild_flag of the Poker::Card object to true.
26  
27 =cut
28  
29 3 extends 'Poker::Eval::Community';
30  
31 3 ▶sub best_hand {
Subroutine best_hand: called CC=18 SCAR=32.6
Pod documented
32 3 my ( $self, $hole ) = @_;
33 3 my $best = Poker::Hand->new(cards => $hole);
34 return $best
35 if $self->card_count >
36 3 ▶ ( scalar @$hole + scalar @{ $self->community_cards } );
Branch: 1 branch
BranchTrueFalseTotal
if $self->card_count > scalar @$hole + scalar(@{$self->community_cards;}) 0 3 3
37 3 my ( @wild, @normal );
38 3 for my $card ( @$hole, @{ $self->community_cards } ) {
39 17 ▶ if ( $card->is_wild ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($card->is_wild) { } 4 13 17
40 4 push @wild, $card;
41 }
42 else {
43 13 push @normal, $card;
44 }
45 }
46 3 my $wild_count = scalar @wild;
47 3 ▶ $wild_count = $wild_count > 5 ? 5 : $wild_count;
Branch: 1 branch
BranchTrueFalseTotal
$wild_count > 5 ? : 0 3 3
48 3 ▶ my $norm_used = 5 > $wild_count ? 5 - $wild_count : 0;
Branch: 1 branch
BranchTrueFalseTotal
5 > $wild_count ? : 3 0 3
49 3 my @wild_combos;
50 3 ▶ if ( $wild_count > 4 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wild_count > 4) { } 0 3 3
elsif ($wild_count == 4) { } 0 3 3
51 0 my $flat_hand = '1414141414';
52 #$best->best_combo($flat_hand);
53 0 $best->score($self->scorer->hand_score($flat_hand));
54 }
55 elsif ( $wild_count == 4 ) {
56 0 my @ranks = sort { $a <=> $b }
57 0 map { $self->scorer->rank_val( $_->rank ) } @normal;
58 0 my $high_rank = sprintf( "%02d", pop @ranks);
59 0 my $flat_hand = join '', ($high_rank) x 5;
60 #$best->best_combo($flat_hand);
61 0 $best->score($self->scorer->hand_score($flat_hand));
62 }
63 else {
64 @wild_combos =
65 3 combinations_with_repetition( [ map { sprintf( "%02d", $_ ) } 2 .. 14 ],
66 $wild_count );
67 3 my $norm_iter = combinations( [@normal], $norm_used );
68 3 ▶ while ( my $norm_combo = $norm_iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $norm_combo = $norm_iter->next) 17 3 20
69  
70 17 my %suit;
71 17 my $max = 0;
72 17 my @norm_ranks = map { $self->scorer->rank_val( $_->rank ) } @$norm_combo;
73 17 for my $card (@$norm_combo) {
74 67 $suit{ $card->suit }++;
75 67 ▶ $max = $suit{ $card->suit } if $suit{ $card->suit } >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $suit{$card->suit} >= $max 65 2 67
76 }
77 17 ▶ my $flush_possible = $max + $wild_count > 4 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$max + $wild_count > 4 ? : 0 17 17
78  
79 17 for my $wild_combo (@wild_combos) {
80 my $flat_combo =
81 299 join( '', sort { $b <=> $a } ( @$wild_combo, @norm_ranks ) );
82 299 my $score = $self->scorer->hand_score($flat_combo);
83 299 ▶ if ($flush_possible) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flush_possible) 0 299 299
84 0 ▶ my $flush_score = $self->scorer->hand_score( $flat_combo . 's' ) || 0;
Condition0%0/2
$self->scorer->hand_score($flat_combo . 's') || 0
l!l
00
MC/DC0%0/1
$self->scorer->hand_score($flat_combo . 's') || 0
$self->scorer->hand_score($flat_combo . 's')
Truth table0%0/2
A
A= $self->scorer->hand_score($flat_combo . 's')
Aresult
11
00
85 0 ▶ $score = $flush_score if $flush_score > $score;
Branch: 1 branch
BranchTrueFalseTotal
if $flush_score > $score 0 0 0
86 }
87 299 ▶ if ( defined $score && $score >= $best->score ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $score and $score >= $best->score) 19 280 299
Condition66%2/3
defined $score and $score >= $best->score
!ll&&!rl&&r
028019
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
ABresult
0X0
100
111
88 #$best->best_combo($flat_combo),
89 19 $best->score($score);
90 }
91 }
92 }
93 }
94 3 $best->name($self->scorer->hand_name( $best->score ));
95 3 return $best;
96 }
97  
98 =head1 AUTHOR
99  
100 Nathaniel Graham, C<< <ngraham at cpan.org> >>
101  
102 =head1 LICENSE AND COPYRIGHT
103  
104 Copyright 2016 Nathaniel Graham.
105  
106 This program is free software; you can redistribute it and/or modify it
107 under the terms of the the Artistic License (2.0). You may obtain a
108 copy of the full license at:
109  
110 L<http://www.perlfoundation.org/artistic_license_2_0>
111  
112 =cut
113  
114 3 1;
« Score/Bring/Wild.pm ↑ Summary Score/Bring/High.pm »