line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poker::Eval; |
2
|
1
|
|
|
1
|
|
39264
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
515
|
use Poker::Score::High; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Algorithm::Combinatorics qw(combinations); |
6
|
|
|
|
|
|
|
use Moo; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Poker::Eval - Evaluate and score hole cards in relation to community cards. Base class for specific game types. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is just a base class. Poker::Eval::Omaha shows a real example. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Poker::Dealer; |
26
|
|
|
|
|
|
|
use Poker::Eval::Omaha; # Omaha rules |
27
|
|
|
|
|
|
|
use Poker::Score::High; # Highball scoring system |
28
|
|
|
|
|
|
|
use feature qw(say); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Create dealer and shuffle deck |
31
|
|
|
|
|
|
|
my $dealer = Poker::Dealer->new; |
32
|
|
|
|
|
|
|
$dealer->shuffle_deck; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Create Omaha evaluation object |
35
|
|
|
|
|
|
|
my $eval = Poker::Eval::Omaha->new( |
36
|
|
|
|
|
|
|
scorer => Poker::Score::High->new, # standard highball |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# deal out five community cards |
40
|
|
|
|
|
|
|
$eval->community_cards( $dealer->deal_up(5) ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# deal yourself four cards |
43
|
|
|
|
|
|
|
my $hole_cards = $dealer->deal_down(4); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# score of the best hand you can make (higher is better) |
46
|
|
|
|
|
|
|
say $eval->best_hand_score($hole_cards); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# name of the best hand you can make (e.g. 'Two Pair') |
49
|
|
|
|
|
|
|
say $eval->best_hand_name($hole_cards); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# cards of best hand you can make in human-readable form. |
52
|
|
|
|
|
|
|
say $eval->best_hand_flat($hole_cards); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# array_ref of Poker::Card objects. |
55
|
|
|
|
|
|
|
$array_ref = $eval->best_hand_cards($hole_cards); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 INTRODUCTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
In most poker variants, Holdem and Stud for example, any combination of hole and community cards can be used to make the best hand. Poker::Eval::Community is the correct subclass for those games. But in Omaha, your best hand is made using EXACTLY two hole cards and EXACTLY three community cards, so Poker::Eval::Omaha is what you want. Other subclasses include Badugi, Chinese, and Wild. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SEE ALSO |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Poker::Eval::Community, Poker::Eval::Omaha, Poker::Eval::Wild, Poker::Eval::Badugi, Poker::Eval::Chinese, Poker::Eval::Bitch, Poker::Eval::Badugi27, Poker::Score, Poker::Dealer |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 community_cards |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Array ref of Poker::Card objects representing community cards |
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has 'community_cards' => ( |
74
|
|
|
|
|
|
|
is => 'rw', |
75
|
|
|
|
|
|
|
isa => sub { die "Not an array ref!" unless ref($_[0]) eq 'ARRAY' }, |
76
|
|
|
|
|
|
|
builder => '_build_community_cards', |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _build_community_cards { |
80
|
|
|
|
|
|
|
return []; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 scorer |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Required attribute that identifies the scoring system. Must be a Poker::Score |
86
|
|
|
|
|
|
|
object. See Poker::Score for available options. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has 'scorer' => ( |
91
|
|
|
|
|
|
|
is => 'rw', |
92
|
|
|
|
|
|
|
isa => sub { die "Not an Score object!" unless $_[0]->isa('Poker::Score') }, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 best_hand_name |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Name of the best hand you can make (e.g. 'Two Pair') |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub best_hand_name { |
104
|
|
|
|
|
|
|
my ($self, $hole) = @_; |
105
|
|
|
|
|
|
|
return $self->best_hand($hole)->{name}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 best_hand_score |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Numerical score of the best hand you can make |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub best_hand_score { |
116
|
|
|
|
|
|
|
my ($self, $hole) = @_; |
117
|
|
|
|
|
|
|
return $self->best_hand($hole)->{score}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 best_hand_cards |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Array_ref of Poker::Card objects representing the best hand you can make. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub best_hand_cards { |
127
|
|
|
|
|
|
|
my ($self, $hole) = @_; |
128
|
|
|
|
|
|
|
return $self->best_hand($hole)->{hand}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub flatten { |
132
|
|
|
|
|
|
|
my ($self, $cards) = @_; |
133
|
|
|
|
|
|
|
return join('', map { $_->rank . $_->suit } @{ $cards }); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 best_hand_flat |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Cards of the best hand you can make in human-readable form. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub best_hand_flat { |
143
|
|
|
|
|
|
|
my ($self, $hole) = @_; |
144
|
|
|
|
|
|
|
return $self->flatten($self->best_hand_cards($hole)); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 best_hand |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
All of the above returned in a single hash ref for convenience and efficiency. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 community_flat |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Community cards in human-readable form. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub community_flat { |
160
|
|
|
|
|
|
|
my $self = shift; |
161
|
|
|
|
|
|
|
return $self->flatten($self->community_cards); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub BUILD { } |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 BUGS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Probably. Only developer tested so far. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Nathaniel Graham, C<< >> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Copyright 2016 Nathaniel Graham. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
179
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
180
|
|
|
|
|
|
|
copy of the full license at: |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |