line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poker::Eval::Omaha; |
2
|
1
|
|
|
1
|
|
2061
|
use Algorithm::Combinatorics qw(combinations); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Moo; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Poker::Eval::Omaha - Evaluate and score Omaha poker hands. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.01 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
See Poker::Eval for code example. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 INTRODUCTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
In Omaha style games, the best hand is made using EXACTLY two hole cards and EXACTLY three community cards. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
extends 'Poker::Eval'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has '_combos' => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => sub { die "Not an array ref!" unless ref($_[0]) eq 'ARRAY' }, |
32
|
|
|
|
|
|
|
predicate => 'has_combos', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_combos { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
return unless $self->community_cards && scalar @{ $self->community_cards } >= 3; |
38
|
|
|
|
|
|
|
my @combos = combinations( $self->community_cards, 3 ); |
39
|
|
|
|
|
|
|
$self->_combos([ @combos ]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
after 'community_cards' => sub { |
43
|
|
|
|
|
|
|
my ($self, $cards) = @_; |
44
|
|
|
|
|
|
|
return unless $cards && scalar @$cards >= 3; |
45
|
|
|
|
|
|
|
$self->_build_combos; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub best_hand { |
49
|
|
|
|
|
|
|
my ( $self, $hole ) = @_; |
50
|
|
|
|
|
|
|
my $best = { score => 0 }; |
51
|
|
|
|
|
|
|
return $best |
52
|
|
|
|
|
|
|
if 5 > |
53
|
|
|
|
|
|
|
( scalar @$hole + scalar @{ $self->community_cards } ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $iter = combinations( $hole, 2 ); |
56
|
|
|
|
|
|
|
while ( my $hole_combo = $iter->next ) { |
57
|
|
|
|
|
|
|
for my $combo (@{$self->_combos}) { |
58
|
|
|
|
|
|
|
my $hand = [ @$hole_combo, @$combo ]; |
59
|
|
|
|
|
|
|
my $score = $self->scorer->score($hand); |
60
|
|
|
|
|
|
|
if (defined $score && $score >= $best->{score}) { |
61
|
|
|
|
|
|
|
$best = { |
62
|
|
|
|
|
|
|
score => $score, |
63
|
|
|
|
|
|
|
hand => $hand, |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
$best->{name} = $self->scorer->hand_name($best->{score}), |
69
|
|
|
|
|
|
|
return $best; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
after 'BUILD' => sub { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
$self->_build_combos; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Nathaniel Graham, C<< >> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Copyright 2016 Nathaniel Graham. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
87
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
88
|
|
|
|
|
|
|
copy of the full license at: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |