| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Poker::Score::Bring::High; |
|
2
|
1
|
|
|
1
|
|
619
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
3
|
1
|
|
|
1
|
|
160
|
use Algorithm::Combinatorics qw(combinations); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use List::Util qw(max); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1077
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Poker::Score::Bring::High - Scoring system used in highball Stud to decide which player starts the action. |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.01 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
See Poker::Score for code example. |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
extends 'Poker::Score'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub stringify_cards { |
|
27
|
0
|
|
|
0
|
0
|
|
my ( $self, $cards ) = @_; |
|
28
|
|
|
|
|
|
|
return join( '', |
|
29
|
0
|
|
|
|
|
|
sort { $b <=> $a } |
|
30
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $self->rank_val( $_->rank ) ) } @$cards ); |
|
|
0
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub score { |
|
34
|
0
|
|
|
0
|
1
|
|
my ( $self, $cards ) = @_; |
|
35
|
0
|
|
|
|
|
|
my (%rank, %suit, @top); |
|
36
|
0
|
|
|
|
|
|
my $score = $self->hand_score( $self->stringify_cards($cards) ); |
|
37
|
0
|
0
|
|
|
|
|
return 0 unless $score; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
for my $card (@$cards) { |
|
40
|
0
|
|
|
|
|
|
$rank{ $card->rank }++; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $max = max(values %rank); |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
for my $k (keys %rank) { |
|
46
|
0
|
0
|
|
|
|
|
if ($rank{$k} == $max) { |
|
47
|
0
|
|
|
|
|
|
push @top, $k; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
|
my ($suit_rank) = sort { $self->rank_val($b) <=> $self->rank_val($a) } @top; |
|
|
0
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
for my $card (@$cards) { |
|
53
|
0
|
0
|
|
|
|
|
if ($self->rank_val($card->rank) == $self->rank_val($suit_rank)) { |
|
54
|
0
|
|
|
|
|
|
$suit{ $card->suit } = 1; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
0
|
|
|
|
|
|
my ($suit_val) = sort { $b <=> $a } map { $self->suit_val($_) } keys %suit; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $score . '.' . $suit_val; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _build_hands { # generates all possible bring hands |
|
62
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
63
|
|
|
|
|
|
|
# one card |
|
64
|
0
|
|
|
|
|
|
my @hands = @{ $self->unpaired1 }; |
|
|
0
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# two cards |
|
67
|
0
|
|
|
|
|
|
push(@hands, @{ $self->unpaired2 }); |
|
|
0
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
push(@hands, @{ $self->one_pair2 }); |
|
|
0
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# three cards |
|
71
|
0
|
|
|
|
|
|
push(@hands, @{ $self->unpaired3 }); |
|
|
0
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
push(@hands, @{ $self->one_pair3 }); |
|
|
0
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
push(@hands, @{ $self->threes3 }); |
|
|
0
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# four cards |
|
76
|
0
|
|
|
|
|
|
push(@hands, @{ $self->unpaired4 }); |
|
|
0
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
push(@hands, @{ $self->one_pair4 }); |
|
|
0
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push(@hands, @{ $self->two_pair4 }); |
|
|
0
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
push(@hands, @{ $self->threes4 }); |
|
|
0
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
push(@hands, @{ $self->fours4 }); |
|
|
0
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->hands( [ @hands ] ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
############ |
|
86
|
|
|
|
|
|
|
# one card # |
|
87
|
|
|
|
|
|
|
############ |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# unpaired |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub unpaired1 { |
|
92
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
93
|
0
|
|
|
|
|
|
for my $card ( 2 .. 14 ) { |
|
94
|
0
|
|
|
|
|
|
push @temp, |
|
95
|
|
|
|
|
|
|
join( '', sprintf( "%02d", $card )); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
############# |
|
101
|
|
|
|
|
|
|
# two cards # |
|
102
|
|
|
|
|
|
|
############# |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# unpaired |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub unpaired2 { |
|
107
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
108
|
0
|
|
|
|
|
|
my @scores; |
|
109
|
0
|
|
|
|
|
|
my $iter = combinations([ reverse (2..14) ], 2); |
|
110
|
0
|
|
|
|
|
|
while (my $c = $iter->next) { |
|
111
|
0
|
|
|
|
|
|
push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
return [ sort { $a <=> $b } @scores ]; |
|
|
0
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# one pair |
|
117
|
|
|
|
|
|
|
sub one_pair2 { |
|
118
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
119
|
0
|
|
|
|
|
|
for my $card ( 2 .. 14 ) { |
|
120
|
|
|
|
|
|
|
push @temp, |
|
121
|
|
|
|
|
|
|
join( '', |
|
122
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
123
|
0
|
|
|
|
|
|
sort { $b <=> $a } ( ($card) x 2 ) |
|
|
0
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
############### |
|
130
|
|
|
|
|
|
|
# three cards # |
|
131
|
|
|
|
|
|
|
############### |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# unpaired |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub unpaired3 { |
|
136
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
137
|
0
|
|
|
|
|
|
my @scores; |
|
138
|
0
|
|
|
|
|
|
my $iter = combinations([ reverse (2..14) ], 3); |
|
139
|
0
|
|
|
|
|
|
while (my $c = $iter->next) { |
|
140
|
0
|
|
|
|
|
|
push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
|
142
|
0
|
|
|
|
|
|
return [ sort { $a <=> $b } @scores ]; |
|
|
0
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# one pair |
|
146
|
|
|
|
|
|
|
sub one_pair3 { |
|
147
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
148
|
0
|
|
|
|
|
|
for my $card1 ( 2 .. 14 ) { |
|
149
|
0
|
|
|
|
|
|
for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) { |
|
|
0
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
push @temp, |
|
151
|
|
|
|
|
|
|
join( '', |
|
152
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
153
|
0
|
|
|
|
|
|
sort { $b <=> $a } ( ($card1) x 2, $card2 ) |
|
|
0
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# three-of-a-kind |
|
161
|
|
|
|
|
|
|
sub threes3 { |
|
162
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
163
|
0
|
|
|
|
|
|
for my $card1 ( 2 .. 14 ) { |
|
164
|
|
|
|
|
|
|
push @temp, |
|
165
|
|
|
|
|
|
|
join('', |
|
166
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
167
|
0
|
|
|
|
|
|
sort { $b <=> $a } ($card1) x 3 |
|
|
0
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
); |
|
169
|
|
|
|
|
|
|
} |
|
170
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
############## |
|
174
|
|
|
|
|
|
|
# four cards # |
|
175
|
|
|
|
|
|
|
############## |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# unpaired |
|
178
|
|
|
|
|
|
|
sub unpaired4 { |
|
179
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
180
|
0
|
|
|
|
|
|
my @scores; |
|
181
|
0
|
|
|
|
|
|
my $iter = combinations([ reverse (2..14) ], 4); |
|
182
|
0
|
|
|
|
|
|
while (my $c = $iter->next) { |
|
183
|
0
|
|
|
|
|
|
push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
|
185
|
0
|
|
|
|
|
|
return [ sort { $a <=> $b } @scores ]; |
|
|
0
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# one pair |
|
189
|
|
|
|
|
|
|
sub one_pair4 { |
|
190
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
191
|
0
|
|
|
|
|
|
for my $card1 ( 2 .. 14 ) { |
|
192
|
0
|
|
|
|
|
|
for my $card2 ( |
|
193
|
0
|
|
|
|
|
|
reverse combinations( [ reverse grep { $_ != $card1 } ( 2 .. 14 ) ], 2 ) ) |
|
194
|
|
|
|
|
|
|
{ |
|
195
|
|
|
|
|
|
|
push @temp, |
|
196
|
|
|
|
|
|
|
join( '', |
|
197
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
198
|
0
|
|
|
|
|
|
sort { $b <=> $a } ( ($card1) x 2, @$card2 ) ); |
|
|
0
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
} |
|
201
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# two pair |
|
205
|
|
|
|
|
|
|
sub two_pair4 { |
|
206
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
207
|
0
|
|
|
|
|
|
for my $card1 ( reverse combinations( [ reverse ( 2 .. 14 ) ], 2 ) ) { |
|
208
|
|
|
|
|
|
|
push @temp, |
|
209
|
|
|
|
|
|
|
join( '', |
|
210
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
211
|
0
|
|
|
|
|
|
sort { $b <=> $a } ( ( $card1->[0] ) x 2, ( $card1->[1] ) x 2 ) |
|
|
0
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# three-of-a-kind |
|
218
|
|
|
|
|
|
|
sub threes4 { |
|
219
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
220
|
0
|
|
|
|
|
|
for my $card1 ( 2 .. 14 ) { |
|
221
|
0
|
|
|
|
|
|
for my $card2 ( grep { $_ != $card1 } ( 2 .. 14 ) ) { |
|
|
0
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
push @temp, |
|
223
|
|
|
|
|
|
|
join('', |
|
224
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
225
|
0
|
|
|
|
|
|
sort { $b <=> $a } ($card1) x 3, ($card2) |
|
|
0
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
); |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
} |
|
229
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# four-of-a-kind |
|
233
|
|
|
|
|
|
|
sub fours4 { |
|
234
|
0
|
|
|
0
|
0
|
|
my @temp; |
|
235
|
0
|
|
|
|
|
|
for my $card ( 2 .. 14 ) { |
|
236
|
|
|
|
|
|
|
#for my $suit ( qw(c d h s) ) { |
|
237
|
|
|
|
|
|
|
push @temp, |
|
238
|
|
|
|
|
|
|
join( '', |
|
239
|
0
|
|
|
|
|
|
map { sprintf( "%02d", $_ ) } |
|
|
0
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
($card) x 4 ); |
|
241
|
|
|
|
|
|
|
#($card) x 4 ) . $suit; |
|
242
|
|
|
|
|
|
|
#} |
|
243
|
|
|
|
|
|
|
} |
|
244
|
0
|
|
|
|
|
|
return [ @temp ]; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 AUTHOR |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Nathaniel Graham, C<< >> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Copyright 2016 Nathaniel Graham. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
256
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
|
257
|
|
|
|
|
|
|
copy of the full license at: |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
L |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
1; |