line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poker::Eval::Chinese; |
2
|
1
|
|
|
1
|
|
2276
|
use Algorithm::Combinatorics qw(combinations); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Moo; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Poker::Eval::Chinese - Evaluate and score Chinese poker hands. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.01 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 INTRODUCTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Calculates score plus royalties for "front", "middle", and "back" Chinese poker hands. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
extends 'Poker::Eval'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'chinese_scorer' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => sub { die "Not a Score!\n" unless $_[0]->isa('Poker::Score') }, |
29
|
|
|
|
|
|
|
required => 1, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub best_hand { |
33
|
|
|
|
|
|
|
my ( $self, $front, $middle, $back ) = @_; |
34
|
|
|
|
|
|
|
my $front_score = $self->chinese_scorer->score($front); |
35
|
|
|
|
|
|
|
my $front_royalty = &_royalty_front($front_score); |
36
|
|
|
|
|
|
|
my $middle_score = $self->scorer->score($middle); |
37
|
|
|
|
|
|
|
my $middle_royalty = &_royalty_middle($middle_score); |
38
|
|
|
|
|
|
|
my $back_score = $self->scorer->score($back); |
39
|
|
|
|
|
|
|
my $back_royalty = &_royalty_back($back_score); |
40
|
|
|
|
|
|
|
if ( $back_score >= $middle_score && $middle_score >= $front_score ) { |
41
|
|
|
|
|
|
|
return { |
42
|
|
|
|
|
|
|
front => { score => $front_score, royalty => $front_royalty }, |
43
|
|
|
|
|
|
|
middle => { score => $middle_score, royalty => $middle_royalty }, |
44
|
|
|
|
|
|
|
back => { score => $back_score, royalty => $back_royalty }, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _royalty_back { |
50
|
|
|
|
|
|
|
my $score = shift; |
51
|
|
|
|
|
|
|
if ( $score >= 5853 && $score <= 5862 ) { |
52
|
|
|
|
|
|
|
return 2; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( $score >= 5863 && $score <= 7139 ) { |
55
|
|
|
|
|
|
|
return 4; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( $score >= 7140 && $score <= 7295 ) { |
58
|
|
|
|
|
|
|
return 6; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $score >= 7296 && $score <= 7451 ) { |
61
|
|
|
|
|
|
|
return 10; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ( $score >= 7452 && $score <= 7460 ) { |
64
|
|
|
|
|
|
|
return 15; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ( $score == 7461 ) { |
67
|
|
|
|
|
|
|
return 25; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
|
|
|
|
|
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _royalty_middle { |
75
|
|
|
|
|
|
|
my $score = shift; |
76
|
|
|
|
|
|
|
if ( $score >= 4995 && $score <= 5852 ) { |
77
|
|
|
|
|
|
|
return 2; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
if ( $score >= 5853 && $score <= 5862 ) { |
80
|
|
|
|
|
|
|
return 4; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $score >= 5863 && $score <= 7139 ) { |
83
|
|
|
|
|
|
|
return 8; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ( $score >= 7140 && $score <= 7295 ) { |
86
|
|
|
|
|
|
|
return 12; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif ( $score >= 7296 && $score <= 7451 ) { |
89
|
|
|
|
|
|
|
return 20; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif ( $score >= 7452 && $score <= 7460 ) { |
92
|
|
|
|
|
|
|
return 30; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( $score == 7461 ) { |
95
|
|
|
|
|
|
|
return 50; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
|
|
|
|
|
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _royalty_front { |
103
|
|
|
|
|
|
|
my $score = shift; |
104
|
|
|
|
|
|
|
if ( $score >= 2156 && $score <= 2322 ) { |
105
|
|
|
|
|
|
|
return 1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif ( $score >= 2376 && $score <= 2542 ) { |
108
|
|
|
|
|
|
|
return 2; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
elsif ( $score >= 2596 && $score <= 2762 ) { |
111
|
|
|
|
|
|
|
return 3; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif ( $score >= 2816 && $score <= 2982 ) { |
114
|
|
|
|
|
|
|
return 4; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ( $score >= 3036 && $score <= 3202 ) { |
117
|
|
|
|
|
|
|
return 5; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ( $score >= 3256 && $score <= 3422 ) { |
120
|
|
|
|
|
|
|
return 6; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif ( $score >= 3476 && $score <= 3642 ) { |
123
|
|
|
|
|
|
|
return 7; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
elsif ( $score >= 3696 && $score <= 3862 ) { |
126
|
|
|
|
|
|
|
return 8; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif ( $score >= 3916 && $score <= 4082 ) { |
129
|
|
|
|
|
|
|
return 9; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
elsif ( $score == 4995 ) { |
132
|
|
|
|
|
|
|
return 10; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
elsif ( $score == 5061 ) { |
135
|
|
|
|
|
|
|
return 11; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ( $score == 5127 ) { |
138
|
|
|
|
|
|
|
return 12; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ( $score == 5193 ) { |
141
|
|
|
|
|
|
|
return 13; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
elsif ( $score == 5259 ) { |
144
|
|
|
|
|
|
|
return 14; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ( $score == 5325 ) { |
147
|
|
|
|
|
|
|
return 15; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
elsif ( $score == 5391 ) { |
150
|
|
|
|
|
|
|
return 16; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
elsif ( $score == 5457 ) { |
153
|
|
|
|
|
|
|
return 17; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
elsif ( $score == 5523 ) { |
156
|
|
|
|
|
|
|
return 18; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
elsif ( $score == 5589 ) { |
159
|
|
|
|
|
|
|
return 19; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif ( $score == 5655 ) { |
162
|
|
|
|
|
|
|
return 20; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
elsif ( $score == 5721 ) { |
165
|
|
|
|
|
|
|
return 21; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif ( $score == 5787 ) { |
168
|
|
|
|
|
|
|
return 22; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
|
|
|
|
|
|
return 0; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Nathaniel Graham, C<< >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright 2016 Nathaniel Graham. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
184
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
185
|
|
|
|
|
|
|
copy of the full license at: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |