Eval/Omaha.pm

filter: Statementstmt 100% 38 / 38 Branchbran 83.3% 10 / 12 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 94.5% 69 / 73 CC 11 SCAR 12.8
CC
11
Cov
95%
best_hand
6.0
_build_combos
3.0
__ANON__
3.0
CRAP 3.6
« Game/CourchevalHiLo.pm ↑ Summary Game/Stud.pm »
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
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 31 31
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
BranchTrueFalseTotal
unless $self->community_cards and scalar @{$self->community_cards;} >= 3 10 31 41
Condition66%2/3
$self->community_cards and scalar @{$self->community_cards;} >= 3
!ll&&!rl&&r
01031
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $cards and scalar @$cards >= 3 131 31 162
Condition100%3/3
$cards and scalar @$cards >= 3
!ll&&!rl&&r
123831
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if 5 > scalar @$hole + scalar(@{$self->community_cards;}) 0 10 10
57  
58 10 my $iter = combinations( $hole, 2 );
59 10 ▶ while ( my $hole_combo = $iter->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hole_combo = $iter->next) 76 10 86
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
BranchTrueFalseTotal
if (defined $score and $score >= $hand->score) 50 710 760
Condition100%3/3
defined $score and $score >= $hand->score
!ll&&!rl&&r
21449650
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
ABresult
0X0
100
111
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;
« Game/CourchevalHiLo.pm ↑ Summary Game/Stud.pm »