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