blib/lib/Games/Poker/Omaha/Hutchison.pm

filter: Statementstmt 92.9% 119 / 128 Branchbran 93.3% 28 / 30 Conditioncond 85.7% 30 / 35 MC/DCmcdc 69.5% 16 / 23 Subroutinesub 94.2% 33 / 35 Podpod 100% 2 / 2 totaltotal 90.1% 228 / 253 CC 33 SCAR 9.9
CC
33
Cov
92%
_unique_pips
6.0
new
5.0
_ace_court
4.0
CRAP 2.7
↑ Summary
1 package Games::Poker::Omaha::Hutchison;
2  
3 2 our $VERSION = '1.04';
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use List::Util 'sum';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Class::Struct 'Games::Poker::Omaha::Hutchison::Card' =>
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 [ suit => '$', pips => '$' ];
12  
13 0 ▶sub Games::Poker::Omaha::Hutchison::Card::rank {
Subroutine rank: not called CC=1 SCAR=6.9
14 0 return (qw/ 0 0 l l l l x h h h c c c c a /)[ shift->pips ];
15 }
16  
17 15 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
18 15 my $class = shift;
19 15 ▶ my @cardes = @_ > 1 ? @_ : split / /, +shift || die "Need a hand";
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 1 14 15
Condition100%2/2
shift() || die('Need a hand')
l!l
131
MC/DC100%1/1
shift() || die('Need a hand')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
20 14 my @cards = map [ split // ], @cardes;
21 14 my %remap = (A => 14, K => 13, Q => 12, J => 11, T => 10);
22 14 ▶ $_->[0] = $remap{ $_->[0] } || $_->[0] foreach @cards;
Condition66%2/3
$remap{$_->[0]} || $_->[0]
l!l&&r!l&&!r
33230
MC/DC0%0/2
$remap{$_->[0]} || $_->[0]
$remap{$_->[0]} $_->[0]
Truth table66%2/3
A || B
A= $remap{$_->[0]}B= $_->[0]
ABresult
1X1
011
000
23 14 bless {
24 cards => [
25 map Games::Poker::Omaha::Hutchison::Card->new(
26 pips => $_->[0],
27 suit => lc $_->[1]
28 ),
29 @cards
30 ]
31 } => $class;
32 }
33  
34 42 ▶sub _cards { @{ shift->{cards} } }
Subroutine _cards: called CC=1 SCAR=0.0
35  
36 14 ▶sub _by_suit {
Subroutine _by_suit: called CC=2 SCAR=6.9
37 14 my $self = shift;
38 14 my %suited;
39 56 push @{ $suited{ $_->suit } }, $_->pips
40 14 foreach sort { $b->pips <=> $a->pips } $self->_cards;
41 14 return %suited;
42 }
43  
44 14 ▶sub _by_pips {
Subroutine _by_pips: called CC=2 SCAR=6.9
45 14 my $self = shift;
46 14 my %pips;
47 14 push @{ $pips{ $_->pips } }, $_->suit foreach $self->_cards;
48 14 return %pips;
49 }
50  
51 0 ▶sub _unique_pips {
Subroutine _unique_pips: not called CC=2 SCAR=17.9
52 0 my $self = shift;
53 0 my %seen;
54 0 my %part = map { $_ => [] } qw/l x h c a/;
55 0 my @uniq = grep !$seen{ $_->pips }++, $self->_cards;
56 0 push @{ $part{ $_->rank } }, $_->pips foreach @uniq;
57 0 return %part;
58 }
59  
60 14 ▶sub hand_score {
Subroutine hand_score: called CC=1 SCAR=0.0
Pod documented
61 14 my $self = shift;
62 14 sum($self->flush_score, $self->pair_score, $self->straight_score);
63 }
64  
65 use Object::Attribute::Cached
66 2 ▶ flush_score => \&_flush_score,
Subroutine BEGIN: called CC=1 SCAR=0.0
67 pair_score => \&_pair_score,
68 2 straight_score => \&_straight_score;
69  
70 14 ▶sub _flush_score {
Subroutine _flush_score: called CC=4 SCAR=13.9
71 14 my $self = shift;
72 14 my %suited = $self->_by_suit;
73 14 my $score = 0;
74 14 foreach my $suit (keys %suited) {
75 43 my @cards = @{ $suited{$suit} };
76 43 ▶ next unless @cards > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @cards > 1 30 13 43
77 13 $score += $self->_flush_pts($cards[0]);
78 13 ▶ $score -= 2 if @cards == 4;
Branch: 1 branch
BranchTrueFalseTotal
if @cards == 4 0 13 13
79 }
80 14 $score;
81 }
82  
83 12 ▶sub _pair_pts { (0, 0, 4, 4, 4, 4, 4, 4, 4, 5, 6, 6, 7, 8, 9)[ $_[1] ] }
Subroutine _pair_pts: called CC=1 SCAR=0.0
84 13 ▶sub _flush_pts { (0, 0, 1, 1, 1, 1, 1, 1, 1, 1.5, 1.5, 2, 2.5, 3, 4)[ $_[1] ] }
Subroutine _flush_pts: called CC=1 SCAR=0.0
85  
86 14 ▶sub _pair_score {
Subroutine _pair_score: called CC=2 SCAR=6.9
87 14 my $self = shift;
88 14 my %pips = $self->_by_pips;
89 14 ▶ (sum map $self->_pair_pts($_), grep @{ $pips{$_} } == 2, keys %pips) || 0;
Branch: 1 branch
BranchTrueFalseTotal
&sum(map($self->_pair_pts($_), grep((@{$pips{$_};} == 2), keys %pips))) or 0 8 6 14
90 }
91  
92 14 ▶sub _straight_score {
Subroutine _straight_score: called CC=1 SCAR=0.0
93 14 my $self = shift;
94 14 my %seen;
95 14 my @run = grep !$seen{$_}++, map $_->pips, $self->_cards;
96 14 return Games::Poker::Omaha::Hutchison::StraightScorer->new(@run)->score;
97 }
98  
99 package Games::Poker::Omaha::Hutchison::StraightScorer;
100  
101 2 ▶use List::Util qw/sum max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 16 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
104 16 my ($proto, @cards) = @_;
105 16 ▶ my $class = ref $proto || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
2140
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
106 16 bless { cards => [ sort { $b <=> $a } @cards ] }, $class;
107 }
108  
109 134 ▶sub cards { @{ shift->{cards} } }
Subroutine cards: called CC=1 SCAR=0.0
110  
111 28 ▶sub gap {
Subroutine gap: called CC=1 SCAR=0.0
112 28 my $self = shift;
113 28 my @pips = sort { $b <=> $a } @_;
114 28 my $gap = ($pips[0] - $pips[-1]) - (@pips - 1);
115 28 return $gap;
116 }
117  
118 15 ▶sub gaploss {
Subroutine gaploss: called CC=1 SCAR=0.0
119 15 my ($self, @pips) = @_;
120 15 my $gap = $self->gap(@pips);
121 15 return (0, 1, 1, 2, (0) x 10)[$gap];
122 }
123  
124 26 ▶sub ace { grep { $_ == 14 } shift->cards; }
Subroutine ace: called CC=1 SCAR=0.0
125 9 ▶sub court { grep { $_ > 9 and $_ < 14 } shift->cards; }
Subroutine court: called CC=2 SCAR=6.9
Condition100%3/3
$_ > 9 && $_ < 14
!ll&&!rl&&r
796
MC/DC100%2/2
$_ > 9 && $_ < 14
$_ > 9 $_ < 14
Truth table100%3/3
A && B
A= $_ > 9B= $_ < 14
ABresult
0X0
100
111
126 25 ▶sub twosix { grep { $_ > 1 and $_ < 7 } shift->cards; }
Subroutine twosix: called CC=2 SCAR=7.1
Condition66%2/3
$_ > 1 && $_ < 7
!ll&&!rl&&r
03943
MC/DC50%1/2
$_ > 1 && $_ < 7
$_ > 1 $_ < 7
Truth table66%2/3
A && B
A= $_ > 1B= $_ < 7
ABresult
0X0
100
111
127 7 ▶sub twofive { grep { $_ > 1 and $_ < 6 } shift->cards; }
Subroutine twofive: called CC=2 SCAR=7.1
Condition66%2/3
$_ > 1 && $_ < 6
!ll&&!rl&&r
0156
MC/DC50%1/2
$_ > 1 && $_ < 6
$_ > 1 $_ < 6
Truth table66%2/3
A && B
A= $_ > 1B= $_ < 6
ABresult
0X0
100
111
128 31 ▶sub sixup { grep { $_ > 5 } shift->cards; }
Subroutine sixup: called CC=1 SCAR=0.0
129 17 ▶sub sixking { grep { $_ > 5 and $_ < 14 } shift->cards; }
Subroutine sixking: called CC=2 SCAR=6.9
Condition100%3/3
$_ > 5 && $_ < 14
!ll&&!rl&&r
17526
MC/DC100%2/2
$_ > 5 && $_ < 14
$_ > 5 $_ < 14
Truth table100%3/3
A && B
A= $_ > 5B= $_ < 14
ABresult
0X0
100
111
130  
131 16 ▶sub score {
Subroutine score: called CC=4 SCAR=13.9
132 16 my $self = shift;
133 16 my @cards = $self->cards;
134  
135 16 my $score = $self->_four_high_cards;
136 16 ▶ return $score if $score;
Branch: 1 branch
BranchTrueFalseTotal
if $score 1 15 16
137  
138 15 $score += $self->_ace_low;
139 15 $score += $self->_two_low_cards;
140  
141 15 $score += my $high3 = $self->_three_high_cards;
142 15 ▶ return $score if $high3;
Branch: 1 branch
BranchTrueFalseTotal
if $high3 5 10 15
143  
144 10 ▶ $score += $self->_two_high_cards || $self->_ace_court;
Condition100%3/3
$self->_two_high_cards || $self->_ace_court
l!l&&r!l&&!r
325
MC/DC100%2/2
$self->_two_high_cards || $self->_ace_court
$self->_two_high_cards $self->_ace_court
Truth table100%3/3
A || B
A= $self->_two_high_cardsB= $self->_ace_court
ABresult
1X1
011
000
145 10 return $score;
146 }
147  
148 15 ▶sub _two_low_cards {
Subroutine _two_low_cards: called CC=3 SCAR=11.1
149 15 my $self = shift;
150 15 ▶ return 2 - $self->gaploss($self->twosix)
Branch: 1 branch
BranchTrueFalseTotal
if $self->twosix >= 2 and $self->gap($self->twosix) < 4 5 10 15
Condition66%2/3
$self->twosix >= 2 and $self->gap($self->twosix) < 4
!ll&&!rl&&r
1005
MC/DC50%1/2
$self->twosix >= 2 and $self->gap($self->twosix) < 4
$self->twosix >= 2 $self->gap($self->twosix) < 4
Truth table66%2/3
A and B
A= $self->twosix >= 2B= $self->gap($self->twosix) < 4
ABresult
0X0
100
111
151 if $self->twosix >= 2
152 and $self->gap($self->twosix) < 4;
153 }
154
155 10 ▶sub _two_high_cards {
Subroutine _two_high_cards: called CC=3 SCAR=11.0
156 10 my $self = shift;
157 10 ▶ return 4 - $self->gaploss($self->sixking)
Branch: 1 branch
BranchTrueFalseTotal
if $self->sixking == 2 and $self->gap($self->sixking) < 4 3 7 10
Condition100%3/3
$self->sixking == 2 and $self->gap($self->sixking) < 4
!ll&&!rl&&r
613
MC/DC100%2/2
$self->sixking == 2 and $self->gap($self->sixking) < 4
$self->sixking == 2 $self->gap($self->sixking) < 4
Truth table100%3/3
A and B
A= $self->sixking == 2B= $self->gap($self->sixking) < 4
ABresult
0X0
100
111
158 if $self->sixking == 2
159 and $self->gap($self->sixking) < 4;
160 }
161  
162 16 ▶sub _four_high_cards {
Subroutine _four_high_cards: called CC=3 SCAR=11.0
163 16 my $self = shift;
164 16 ▶ return 0 unless $self->sixup == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sixup == 4 14 2 16
165 2 ▶ return 0 if $self->gap($self->cards) > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $self->gap($self->cards) > 3 1 1 2
166 1 return 12 - $self->gaploss($self->cards);
167 }
168  
169 15 ▶sub _three_high_cards {
Subroutine _three_high_cards: called CC=3 SCAR=11.0
170 15 my $self = shift;
171 15 my @cards = $self->sixup;
172 15 ▶ return 0 unless @cards >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @cards >= 3 10 5 15
173 5 ▶ return 7 - $self->gaploss(@cards) if @cards == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @cards == 3 4 1 5
174 # Want 3 from 4
175 1 my @hi = @cards; pop @hi;
176 1 my @lo = @cards; shift @lo;
177 1 return max($self->new(@hi)->score, $self->new(@lo)->score);
178 }
179  
180 7 ▶sub _ace_court {
Subroutine _ace_court: called CC=4 SCAR=13.9
181 7 my $self = shift;
182 7 ▶ return 0 unless $self->ace and $self->court;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ace and $self->court 5 2 7
Condition100%3/3
$self->ace and $self->court
!ll&&!rl&&r
232
MC/DC100%2/2
$self->ace and $self->court
$self->ace $self->court
Truth table100%3/3
A and B
A= $self->aceB= $self->court
ABresult
0X0
100
111
183 2 ▶ return 0 if $self->gap($self->ace, $self->court) > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $self->gap($self->ace, $self->court) > 3 0 2 2
184 2 return 2 - $self->gaploss($self->ace, $self->court);
185 }
186  
187 15 ▶sub _ace_low {
Subroutine _ace_low: called CC=3 SCAR=11.0
188 15 my $self = shift;
189 15 ▶ return ($self->ace and $self->twofive) ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$self->ace && $self->twofive ? : 4 11 15
Condition100%3/3
$self->ace and $self->twofive
!ll&&!rl&&r
834
MC/DC100%2/2
$self->ace and $self->twofive
$self->ace $self->twofive
Truth table100%3/3
A and B
A= $self->aceB= $self->twofive
ABresult
0X0
100
111
190 }
191  
192 __END__
↑ Summary