File Coverage

blib/lib/Poker/Eval/Omaha.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Poker::Eval::Omaha;
2 1     1   1901 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.02
12              
13             =cut
14              
15             our $VERSION = '0.02';
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 $hand = Poker::Hand->new(cards => $hole);
51              
52             return $hand
53             if 5 >
54             ( scalar @$hole + scalar @{ $self->community_cards } );
55              
56             my $iter = combinations( $hole, 2 );
57             while ( my $hole_combo = $iter->next ) {
58             for my $combo (@{$self->_combos}) {
59             my $combo = [ @$hole_combo, @$combo ];
60             my $score = $self->scorer->score($combo);
61             if (defined $score && $score >= $hand->score) {
62             $hand->score($score);
63             $hand->best_combo($combo);
64             }
65             }
66             }
67             $hand->name($self->scorer->hand_name($hand->score));
68             return $hand;
69              
70             }
71              
72             after 'BUILD' => sub {
73             my $self = shift;
74             $self->_build_combos;
75             };
76              
77             =head1 AUTHOR
78              
79             Nathaniel Graham, C<< >>
80              
81             =head1 LICENSE AND COPYRIGHT
82              
83             Copyright 2016 Nathaniel Graham.
84              
85             This program is free software; you can redistribute it and/or modify it
86             under the terms of the the Artistic License (2.0). You may obtain a
87             copy of the full license at:
88              
89             L
90              
91             =cut
92              
93             1;