File Coverage

blib/lib/Poker/Eval/Chinese.pm
Criterion Covered Total %
statement 6 60 10.0
branch 0 72 0.0
condition 0 63 0.0
subroutine 2 6 33.3
pod 1 1 100.0
total 9 202 4.4


line stmt bran cond sub pod time code
1             package Poker::Eval::Chinese;
2 1     1   606 use Algorithm::Combinatorics qw(combinations);
  1         2  
  1         37  
3 1     1   3 use Moo;
  1         1  
  1         3  
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 0     0 1   my ( $self, $front, $middle, $back ) = @_;
34 0           my $front_score = $self->chinese_scorer->score($front);
35 0           my $front_royalty = &_royalty_front($front_score);
36 0           my $middle_score = $self->scorer->score($middle);
37 0           my $middle_royalty = &_royalty_middle($middle_score);
38 0           my $back_score = $self->scorer->score($back);
39 0           my $back_royalty = &_royalty_back($back_score);
40 0 0 0       if ( $back_score >= $middle_score && $middle_score >= $front_score ) {
41             return {
42 0           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 0     0     my $score = shift;
51 0 0 0       if ( $score >= 5853 && $score <= 5862 ) {
    0 0        
    0 0        
    0 0        
    0 0        
    0          
52 0           return 2;
53             }
54             elsif ( $score >= 5863 && $score <= 7139 ) {
55 0           return 4;
56             }
57             elsif ( $score >= 7140 && $score <= 7295 ) {
58 0           return 6;
59             }
60             elsif ( $score >= 7296 && $score <= 7451 ) {
61 0           return 10;
62             }
63             elsif ( $score >= 7452 && $score <= 7460 ) {
64 0           return 15;
65             }
66             elsif ( $score == 7461 ) {
67 0           return 25;
68             }
69             else {
70 0           return 0;
71             }
72             }
73              
74             sub _royalty_middle {
75 0     0     my $score = shift;
76 0 0 0       if ( $score >= 4995 && $score <= 5852 ) {
77 0           return 2;
78             }
79 0 0 0       if ( $score >= 5853 && $score <= 5862 ) {
    0 0        
    0 0        
    0 0        
    0 0        
    0          
80 0           return 4;
81             }
82             elsif ( $score >= 5863 && $score <= 7139 ) {
83 0           return 8;
84             }
85             elsif ( $score >= 7140 && $score <= 7295 ) {
86 0           return 12;
87             }
88             elsif ( $score >= 7296 && $score <= 7451 ) {
89 0           return 20;
90             }
91             elsif ( $score >= 7452 && $score <= 7460 ) {
92 0           return 30;
93             }
94             elsif ( $score == 7461 ) {
95 0           return 50;
96             }
97             else {
98 0           return 0;
99             }
100             }
101              
102             sub _royalty_front {
103 0     0     my $score = shift;
104 0 0 0       if ( $score >= 2156 && $score <= 2322 ) {
    0 0        
    0 0        
    0 0        
    0 0        
    0 0        
    0 0        
    0 0        
    0 0        
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
105 0           return 1;
106             }
107             elsif ( $score >= 2376 && $score <= 2542 ) {
108 0           return 2;
109             }
110             elsif ( $score >= 2596 && $score <= 2762 ) {
111 0           return 3;
112             }
113             elsif ( $score >= 2816 && $score <= 2982 ) {
114 0           return 4;
115             }
116             elsif ( $score >= 3036 && $score <= 3202 ) {
117 0           return 5;
118             }
119             elsif ( $score >= 3256 && $score <= 3422 ) {
120 0           return 6;
121             }
122             elsif ( $score >= 3476 && $score <= 3642 ) {
123 0           return 7;
124             }
125             elsif ( $score >= 3696 && $score <= 3862 ) {
126 0           return 8;
127             }
128             elsif ( $score >= 3916 && $score <= 4082 ) {
129 0           return 9;
130             }
131             elsif ( $score == 4995 ) {
132 0           return 10;
133             }
134             elsif ( $score == 5061 ) {
135 0           return 11;
136             }
137             elsif ( $score == 5127 ) {
138 0           return 12;
139             }
140             elsif ( $score == 5193 ) {
141 0           return 13;
142             }
143             elsif ( $score == 5259 ) {
144 0           return 14;
145             }
146             elsif ( $score == 5325 ) {
147 0           return 15;
148             }
149             elsif ( $score == 5391 ) {
150 0           return 16;
151             }
152             elsif ( $score == 5457 ) {
153 0           return 17;
154             }
155             elsif ( $score == 5523 ) {
156 0           return 18;
157             }
158             elsif ( $score == 5589 ) {
159 0           return 19;
160             }
161             elsif ( $score == 5655 ) {
162 0           return 20;
163             }
164             elsif ( $score == 5721 ) {
165 0           return 21;
166             }
167             elsif ( $score == 5787 ) {
168 0           return 22;
169             }
170             else {
171 0           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;