Score/Bring/High.pm

filter: Statementstmt 8.7% 12 / 137 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 17.6% 3 / 17 Podpod 7.6% 1 / 13 totaltotal 8.9% 16 / 179 CC 21 SCAR 27.9
CC
21
Cov
8%
score
56.0
one_pair3
12.0
one_pair4
12.0
CRAP 16.3
« Eval/Wild.pm ↑ Summary Score/HighSuit.pm »
1 package Poker::Score::Bring::High;
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);
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::High - Scoring system used in highball Stud 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 1 extends 'Poker::Score';
27  
28 0 ▶sub stringify_cards {
Subroutine stringify_cards: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my ( $self, $cards ) = @_;
30 return join( '',
31 0 sort { $b <=> $a }
32 0 map { sprintf( "%02d", $self->rank_val( $_->rank ) ) } @$cards );
33 }
34  
35 0 ▶sub score {
Subroutine score: not called CC=7 SCAR=40.3
Pod documented
36 0 my ( $self, $cards ) = @_;
37 0 my (%rank, %suit, @top);
38 0 my $score = $self->hand_score( $self->stringify_cards($cards) );
39 0 ▶ return 0 unless $score;
Branch: 1 branch
BranchTrueFalseTotal
unless $score 0 0 0
40  
41 0 for my $card (@$cards) {
42 0 $rank{ $card->rank }++;
43 }
44  
45 0 my $max = max(values %rank);
46  
47 0 for my $k (keys %rank) {
48 0 ▶ if ($rank{$k} == $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rank{$k} == $max) 0 0 0
49 0 push @top, $k;
50 }
51 }
52 0 my ($suit_rank) = sort { $self->rank_val($b) <=> $self->rank_val($a) } @top;
53  
54 0 for my $card (@$cards) {
55 0 ▶ if ($self->rank_val($card->rank) == $self->rank_val($suit_rank)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rank_val($card->rank) == $self->rank_val($suit_rank)) 0 0 0
56 0 $suit{ $card->suit } = 1;
57 }
58 }
59 0 my ($suit_val) = sort { $b <=> $a } map { $self->suit_val($_) } keys %suit;
60 0 return $score . '.' . $suit_val;
61 }
62  
63 0 ▶sub _build_hands { # generates all possible bring hands
Subroutine _build_hands: not called CC=1 SCAR=6.9
64 0 my $self = shift;
65 # one card
66 0 my @hands = @{ $self->unpaired1 };
67  
68 # two cards
69 0 push(@hands, @{ $self->unpaired2 });
70 0 push(@hands, @{ $self->one_pair2 });
71  
72 # three cards
73 0 push(@hands, @{ $self->unpaired3 });
74 0 push(@hands, @{ $self->one_pair3 });
75 0 push(@hands, @{ $self->threes3 });
76  
77 # four cards
78 0 push(@hands, @{ $self->unpaired4 });
79 0 push(@hands, @{ $self->one_pair4 });
80 0 push(@hands, @{ $self->two_pair4 });
81 0 push(@hands, @{ $self->threes4 });
82 0 push(@hands, @{ $self->fours4 });
83  
84 0 $self->hands( [ @hands ] );
85 }
86  
87 ############
88 # one card #
89 ############
90  
91 # unpaired
92  
93 0 ▶sub unpaired1 {
Subroutine unpaired1: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my @temp;
95 0 for my $card ( 2 .. 14 ) {
96 0 push @temp,
97 join( '', sprintf( "%02d", $card ));
98 }
99 0 return [ @temp ];
100 }
101  
102 #############
103 # two cards #
104 #############
105  
106 # unpaired
107  
108 0 ▶sub unpaired2 {
Subroutine unpaired2: not called CC=2 SCAR=17.9
Pod undocumented
109 0 my $self = shift;
110 0 my @scores;
111 0 my $iter = combinations([ reverse (2..14) ], 2);
112 0 ▶ while (my $c = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
113 0 push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) );
114 }
115 0 return [ sort { $a <=> $b } @scores ];
116 }
117  
118 # one pair
119 0 ▶sub one_pair2 {
Subroutine one_pair2: not called CC=2 SCAR=17.9
Pod undocumented
120 0 my @temp;
121 0 for my $card ( 2 .. 14 ) {
122 push @temp,
123 join( '',
124 0 map { sprintf( "%02d", $_ ) }
125 0 sort { $b <=> $a } ( ($card) x 2 )
126 );
127 }
128 0 return [ @temp ];
129 }
130  
131 ###############
132 # three cards #
133 ###############
134  
135 # unpaired
136  
137 0 ▶sub unpaired3 {
Subroutine unpaired3: not called CC=2 SCAR=17.9
Pod undocumented
138 0 my $self = shift;
139 0 my @scores;
140 0 my $iter = combinations([ reverse (2..14) ], 3);
141 0 ▶ while (my $c = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
142 0 push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) );
143 }
144 0 return [ sort { $a <=> $b } @scores ];
145 }
146  
147 # one pair
148 0 ▶sub one_pair3 {
Subroutine one_pair3: not called CC=3 SCAR=24.8
Pod undocumented
149 0 my @temp;
150 0 for my $card1 ( 2 .. 14 ) {
151 0 for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) {
152 push @temp,
153 join( '',
154 0 map { sprintf( "%02d", $_ ) }
155 0 sort { $b <=> $a } ( ($card1) x 2, $card2 )
156 );
157 }
158 }
159 0 return [ @temp ];
160 }
161  
162 # three-of-a-kind
163 0 ▶sub threes3 {
Subroutine threes3: not called CC=2 SCAR=17.9
Pod undocumented
164 0 my @temp;
165 0 for my $card1 ( 2 .. 14 ) {
166 push @temp,
167 join('',
168 0 map { sprintf( "%02d", $_ ) }
169 0 sort { $b <=> $a } ($card1) x 3
170 );
171 }
172 0 return [ @temp ];
173 }
174  
175 ##############
176 # four cards #
177 ##############
178  
179 # unpaired
180 0 ▶sub unpaired4 {
Subroutine unpaired4: not called CC=2 SCAR=17.9
Pod undocumented
181 0 my $self = shift;
182 0 my @scores;
183 0 my $iter = combinations([ reverse (2..14) ], 4);
184 0 ▶ while (my $c = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $iter->next) 0 0 0
185 0 push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) );
186 }
187 0 return [ sort { $a <=> $b } @scores ];
188 }
189  
190 # one pair
191 0 ▶sub one_pair4 {
Subroutine one_pair4: not called CC=3 SCAR=24.8
Pod undocumented
192 0 my @temp;
193 0 for my $card1 ( 2 .. 14 ) {
194 0 for my $card2 (
195 0 reverse combinations( [ reverse grep { $_ != $card1 } ( 2 .. 14 ) ], 2 ) )
196 {
197 push @temp,
198 join( '',
199 0 map { sprintf( "%02d", $_ ) }
200 0 sort { $b <=> $a } ( ($card1) x 2, @$card2 ) );
201 }
202 }
203 0 return [ @temp ];
204 }
205  
206 # two pair
207 0 ▶sub two_pair4 {
Subroutine two_pair4: not called CC=2 SCAR=17.9
Pod undocumented
208 0 my @temp;
209 0 for my $card1 ( reverse combinations( [ reverse ( 2 .. 14 ) ], 2 ) ) {
210 push @temp,
211 join( '',
212 0 map { sprintf( "%02d", $_ ) }
213 0 sort { $b <=> $a } ( ( $card1->[0] ) x 2, ( $card1->[1] ) x 2 )
214 );
215 }
216 0 return [ @temp ];
217 }
218  
219 # three-of-a-kind
220 0 ▶sub threes4 {
Subroutine threes4: not called CC=3 SCAR=24.8
Pod undocumented
221 0 my @temp;
222 0 for my $card1 ( 2 .. 14 ) {
223 0 for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) {
224 push @temp,
225 join('',
226 0 map { sprintf( "%02d", $_ ) }
227 0 sort { $b <=> $a } ($card1) x 3, ($card2)
228 );
229 }
230 }
231 0 return [ @temp ];
232 }
233  
234 # four-of-a-kind
235 0 ▶sub fours4 {
Subroutine fours4: not called CC=2 SCAR=17.9
Pod undocumented
236 0 my @temp;
237 0 for my $card ( 2 .. 14 ) {
238 #for my $suit ( qw(c d h s) ) {
239 push @temp,
240 join( '',
241 0 map { sprintf( "%02d", $_ ) }
242 ($card) x 4 );
243 #($card) x 4 ) . $suit;
244 #}
245 }
246 0 return [ @temp ];
247 }
248  
249 =head1 AUTHOR
250  
251 Nathaniel Graham, C<< <ngraham at cpan.org> >>
252  
253 =head1 LICENSE AND COPYRIGHT
254  
255 Copyright 2016 Nathaniel Graham.
256  
257 This program is free software; you can redistribute it and/or modify it
258 under the terms of the the Artistic License (2.0). You may obtain a
259 copy of the full license at:
260  
261 L<http://www.perlfoundation.org/artistic_license_2_0>
262  
263 =cut
264  
265 1 1;
« Eval/Wild.pm ↑ Summary Score/HighSuit.pm »