Score/Bring/Wild.pm

filter: Statementstmt 8.2% 12 / 146 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 18.7% 3 / 16 Podpod 8.3% 1 / 12 totaltotal 8.2% 16 / 195 CC 23 SCAR 32.9
CC
23
Cov
7%
score
90.0
one_pair3
12.0
one_pair4
12.0
CRAP 26.8
« Eval/Chinese.pm ↑ Summary Eval/Wild.pm »
1 package Poker::Score::Bring::Wild;
2 1 our $VERSION = '0.12';
3  
4  
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Algorithm::Combinatorics qw(combinations combinations_with_repetition);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::Util qw(max);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Poker::Score::Bring::Wild - Scoring system used in highball Stud with wildcards to decide which player starts the action.
12  
13 =head1 VERSION
14  
15 Version 0.12
16  
17 =cut
18  
19  
20 =head1 SYNOPSIS
21  
22 See Poker::Score for code example.
23  
24 =cut
25  
26  
27 1 extends 'Poker::Score::Bring::High';
28  
29 0 ▶sub score {
Subroutine score: not called CC=9 SCAR=45.0
Pod documented
30 0 my ( $self, $hole ) = @_;
31 0 my $score = 0;
32 0 my ( @wild, @normal );
33 0 for my $card (@$hole) {
34 0 ▶ if ( $card->is_wild ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($card->is_wild) { } 0 0 0
35 0 push @wild, $card;
36 }
37 else {
38 0 push @normal, $card;
39 }
40 }
41 0 my $wild_count = scalar @wild;
42 0 my $norm_count = scalar @normal;
43 0 my @wild_combos;
44
45 0 ▶ if ( $norm_count == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($norm_count == 0) { } 0 0 0
elsif ($wild_count == 3) { } 0 0 0
46 0 my $flat_hand = '14' x $wild_count;
47 0 $score = $self->hand_score($flat_hand);
48 }
49  
50 elsif ( $wild_count == 3 ) {
51 0 my @ranks = sort { $a <=> $b }
52 0 map { $self->rank_val( $_->rank ) } @normal;
53 0 my $high_rank = sprintf( "%02d", pop @ranks );
54 0 my $flat_hand = join '', ($high_rank) x 4;
55 0 $score = $self->hand_score($flat_hand);
56 }
57  
58 else {
59 @wild_combos =
60 0 combinations_with_repetition( [ map { sprintf( "%02d", $_ ) } 2 .. 14 ],
61 $wild_count );
62 0 my $norm_iter = combinations( [@normal], $norm_count );
63 0 ▶ while ( my $norm_combo = $norm_iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $norm_combo = $norm_iter->next) 0 0 0
64  
65 0 my @norm_ranks = map { $self->rank_val( $_->rank ) } @$norm_combo;
66 0 for my $wild_combo (@wild_combos) {
67 my $flat_combo =
68 0 join( '', sort { $b <=> $a } ( @$wild_combo, @norm_ranks ) );
69  
70 0 my $temp_score = $self->hand_score($flat_combo);
71  
72 0 ▶ if ( defined $temp_score && $temp_score >= $score ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $temp_score and $temp_score >= $score) 0 0 0
Condition0%0/3
defined $temp_score and $temp_score >= $score
!ll&&!rl&&r
000
MC/DC0%0/2
defined $temp_score and $temp_score >= $score
defined $temp_score $temp_score >= $score
Truth table0%0/3
A and B
A= defined $temp_scoreB= $temp_score >= $score
ABresult
0X0
100
111
73 0 $score = $temp_score;
74 }
75 }
76 }
77 }
78 0 return $score . '.05';
79 }
80  
81 0 ▶sub _build_hands { # generates all possible bring hands
Subroutine _build_hands: not called CC=1 SCAR=6.9
82 0 my $self = shift;
83  
84 # one card
85 0 my @hands = @{ $self->unpaired1 };
86  
87 # two cards
88 0 push( @hands, @{ $self->unpaired2 } );
89 0 push( @hands, @{ $self->one_pair2 } );
90  
91 # three cards
92 0 push( @hands, @{ $self->unpaired3 } );
93 0 push( @hands, @{ $self->one_pair3 } );
94 0 push( @hands, @{ $self->threes3 } );
95  
96 # four cards
97 0 push( @hands, @{ $self->unpaired4 } );
98 0 push( @hands, @{ $self->one_pair4 } );
99 0 push( @hands, @{ $self->two_pair4 } );
100 0 push( @hands, @{ $self->threes4 } );
101 0 push( @hands, @{ $self->fours4 } );
102  
103 0 $self->hands( [@hands] );
104 }
105  
106 ############
107 # one card #
108 ############
109  
110 # unpaired
111  
112 0 ▶sub unpaired1 {
Subroutine unpaired1: not called CC=2 SCAR=17.9
Pod undocumented
113 0 my @temp;
114 0 for my $card ( 2 .. 14 ) {
115 0 push @temp, join( '', sprintf( "%02d", $card ) );
116 }
117 0 return [@temp];
118 }
119  
120 #############
121 # two cards #
122 #############
123  
124 # unpaired
125  
126 0 ▶sub unpaired2 {
Subroutine unpaired2: not called CC=2 SCAR=17.9
Pod undocumented
127 0 my $self = shift;
128 0 my @scores;
129 0 my $iter = combinations( [ reverse( 2 .. 14 ) ], 2 );
130 0 ▶ while ( my $c = $iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
131 push( @scores,
132 0 join( "", map { sprintf( "%02d", $_ ) } sort { $b <=> $a } @$c ) );
133 }
134 0 return [ sort { $a <=> $b } @scores ];
135 }
136  
137 # one pair
138 0 ▶sub one_pair2 {
Subroutine one_pair2: not called CC=2 SCAR=17.9
Pod undocumented
139 0 my @temp;
140 0 for my $card ( 2 .. 14 ) {
141 push @temp,
142 join( '',
143 0 map { sprintf( "%02d", $_ ) }
144 0 sort { $b <=> $a } ( ($card) x 2 ) );
145 }
146 0 return [@temp];
147 }
148  
149 ###############
150 # three cards #
151 ###############
152  
153 # unpaired
154  
155 0 ▶sub unpaired3 {
Subroutine unpaired3: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my $self = shift;
157 0 my @scores;
158 0 my $iter = combinations( [ reverse( 2 .. 14 ) ], 3 );
159 0 ▶ while ( my $c = $iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
160 push( @scores,
161 0 join( "", map { sprintf( "%02d", $_ ) } sort { $b <=> $a } @$c ) );
162 }
163 0 return [ sort { $a <=> $b } @scores ];
164 }
165  
166 # one pair
167 0 ▶sub one_pair3 {
Subroutine one_pair3: not called CC=3 SCAR=24.8
Pod undocumented
168 0 my @temp;
169 0 for my $card1 ( 2 .. 14 ) {
170 0 for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) {
171 push @temp,
172 join( '',
173 0 map { sprintf( "%02d", $_ ) }
174 0 sort { $b <=> $a } ( ($card1) x 2, $card2 ) );
175 }
176 }
177 0 return [@temp];
178 }
179  
180 # three-of-a-kind
181 0 ▶sub threes3 {
Subroutine threes3: not called CC=2 SCAR=17.9
Pod undocumented
182 0 my @temp;
183 0 for my $card1 ( 2 .. 14 ) {
184 push @temp,
185 join(
186 0 '', map { sprintf( "%02d", $_ ) }
187 0 sort { $b <=> $a } ($card1) x 3
188 );
189 }
190 0 return [@temp];
191 }
192  
193 ##############
194 # four cards #
195 ##############
196  
197 # unpaired
198 0 ▶sub unpaired4 {
Subroutine unpaired4: not called CC=2 SCAR=17.9
Pod undocumented
199 0 my $self = shift;
200 0 my @scores;
201 0 my $iter = combinations( [ reverse( 2 .. 14 ) ], 4 );
202 0 ▶ while ( my $c = $iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
203 push( @scores,
204 0 join( "", map { sprintf( "%02d", $_ ) } sort { $b <=> $a } @$c ) );
205 }
206 0 return [ sort { $a <=> $b } @scores ];
207 }
208  
209 # one pair
210 0 ▶sub one_pair4 {
Subroutine one_pair4: not called CC=3 SCAR=24.8
Pod undocumented
211 0 my @temp;
212 0 for my $card1 ( 2 .. 14 ) {
213 0 for my $card2 (
214 0 reverse combinations( [ reverse grep { $_ != $card1 } ( 2 .. 14 ) ], 2 ) )
215 {
216 push @temp,
217 join( '',
218 0 map { sprintf( "%02d", $_ ) }
219 0 sort { $b <=> $a } ( ($card1) x 2, @$card2 ) );
220 }
221 }
222 0 return [@temp];
223 }
224  
225 # two pair
226 0 ▶sub two_pair4 {
Subroutine two_pair4: not called CC=2 SCAR=17.9
Pod undocumented
227 0 my @temp;
228 0 for my $card1 ( reverse combinations( [ reverse( 2 .. 14 ) ], 2 ) ) {
229 push @temp,
230 join( '',
231 0 map { sprintf( "%02d", $_ ) }
232 0 sort { $b <=> $a } ( ( $card1->[0] ) x 2, ( $card1->[1] ) x 2 ) );
233 }
234 0 return [@temp];
235 }
236  
237 # three-of-a-kind
238 0 ▶sub threes4 {
Subroutine threes4: not called CC=3 SCAR=24.8
Pod undocumented
239 0 my @temp;
240 0 for my $card1 ( 2 .. 14 ) {
241 0 for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) {
242 push @temp,
243 join( '',
244 0 map { sprintf( "%02d", $_ ) }
245 0 sort { $b <=> $a } ($card1) x 3, ($card2) );
246 }
247 }
248 0 return [@temp];
249 }
250  
251 # four-of-a-kind
252 0 ▶sub fours4 {
Subroutine fours4: not called CC=2 SCAR=17.9
Pod undocumented
253 0 my @temp;
254 0 for my $card ( 2 .. 14 ) {
255  
256 #for my $suit ( qw(c d h s) ) {
257 0 push @temp, join( '', map { sprintf( "%02d", $_ ) } ($card) x 4 );
258  
259 #($card) x 4 ) . $suit;
260 #}
261 }
262 0 return [@temp];
263 }
264  
265 =head1 AUTHOR
266  
267 Nathaniel Graham, C<< <ngraham at cpan.org> >>
268  
269 =head1 LICENSE AND COPYRIGHT
270  
271 Copyright 2016 Nathaniel Graham.
272  
273 This program is free software; you can redistribute it and/or modify it
274 under the terms of the the Artistic License (2.0). You may obtain a
275 copy of the full license at:
276  
277 L<http://www.perlfoundation.org/artistic_license_2_0>
278  
279 =cut
280  
281 1 1;
« Eval/Chinese.pm ↑ Summary Eval/Wild.pm »