| 1 | package Poker::Score::LowA5; | ||||||||||||||||||||
| 2 | 4 | our $VERSION = '0.12'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 4 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use Algorithm::Combinatorics qw(combinations); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | Poker::Score::LowA5 - Identify and score lowball A-5 poker hand. | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Version 0.12 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head1 INTRODUCTION | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | Straights and flushes do not affect the strengh of your hand and Aces always play low. | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | See Poker::Score for code example. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 4 | extends 'Poker::Score'; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | ▶ | sub _build_rank_map { | ||||||||||||||||||
|
Subroutine
_build_rank_map: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 3 | my $self = shift; | |||||||||||||||||||
| 33 | 3 | $self->_rank_map({ | |||||||||||||||||||
| 34 | 'A' => '01', | ||||||||||||||||||||
| 35 | '2' => '02', | ||||||||||||||||||||
| 36 | '3' => '03', | ||||||||||||||||||||
| 37 | '4' => '04', | ||||||||||||||||||||
| 38 | '5' => '05', | ||||||||||||||||||||
| 39 | '6' => '06', | ||||||||||||||||||||
| 40 | '7' => '07', | ||||||||||||||||||||
| 41 | '8' => '08', | ||||||||||||||||||||
| 42 | '9' => '09', | ||||||||||||||||||||
| 43 | 'T' => '10', | ||||||||||||||||||||
| 44 | 'J' => '11', | ||||||||||||||||||||
| 45 | 'Q' => '12', | ||||||||||||||||||||
| 46 | 'K' => '13', | ||||||||||||||||||||
| 47 | }); | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 3 | ▶ | sub _build_hands { # generates all possible lowA5 hands | ||||||||||||||||||
|
Subroutine
_build_hands: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 3 | my $self = shift; | |||||||||||||||||||
| 52 | 3 | my %map = ( 1 => 'Five-of-a-Kind' ); | |||||||||||||||||||
| 53 | 3 | my @hands = @{ $self->fives }; | |||||||||||||||||||
| 54 | 3 | $map{ $#hands } = 'Four-of-a-Kind'; | |||||||||||||||||||
| 55 | 3 | push(@hands, @{ $self->fours }); | |||||||||||||||||||
| 56 | 3 | $map{ $#hands } = 'a Full House'; | |||||||||||||||||||
| 57 | 3 | push(@hands, @{ $self->houses }); | |||||||||||||||||||
| 58 | 3 | $map{ $#hands } = 'Three-of-a-Kind'; | |||||||||||||||||||
| 59 | 3 | push(@hands, @{ $self->threes }); | |||||||||||||||||||
| 60 | 3 | $map{ $#hands } = 'Two Pair'; | |||||||||||||||||||
| 61 | 3 | push(@hands, @{ $self->two_pair }); | |||||||||||||||||||
| 62 | 3 | $map{ $#hands } = 'One Pair'; | |||||||||||||||||||
| 63 | 3 | push(@hands, @{ $self->one_pair }); | |||||||||||||||||||
| 64 | 3 | $map{ $#hands } = 'a High Card'; | |||||||||||||||||||
| 65 | 3 | push(@hands, @{ $self->unpaired }); | |||||||||||||||||||
| 66 | 3 | $self->hands( [ @hands ] ); | |||||||||||||||||||
| 67 | 3 | $self->_hand_map( \%map ); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 3 | ▶ | sub unpaired { | ||||||||||||||||||
|
Subroutine
unpaired: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | 3 | my $self = shift; | |||||||||||||||||||
| 72 | 3 | my @scores; | |||||||||||||||||||
| 73 | 3 | my $iter = combinations([1..13], 5); | |||||||||||||||||||
| 74 | 3 | ▶ | while (my $c = $iter->next) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 3861 | push( @scores, join( "", map { sprintf("%02d", $_) } sort { $b <=> $a } @$c ) ); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | #$self->hands([ sort { $b <=> $a } @scores ]); | ||||||||||||||||||||
| 78 | 3 | return [ sort { $b <=> $a } @scores ]; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | # one pair | ||||||||||||||||||||
| 82 | 3 | ▶ | sub one_pair { | ||||||||||||||||||
|
Subroutine
one_pair: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 83 | 3 | my @temp; | |||||||||||||||||||
| 84 | 3 | for my $card ( 1 .. 13 ) { | |||||||||||||||||||
| 85 | 39 | for my $c ( | |||||||||||||||||||
| 86 | 507 | reverse combinations( [ reverse grep { $_ != $card } ( 1 .. 13 ) ], 3 ) ) | |||||||||||||||||||
| 87 | #reverse combinations( [ grep { $_ != $card } ( 1 .. 13 ) ], 3 ) ) | ||||||||||||||||||||
| 88 | { | ||||||||||||||||||||
| 89 | push @temp, | ||||||||||||||||||||
| 90 | join( '', | ||||||||||||||||||||
| 91 | 42900 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 92 | 8580 | sort { $b <=> $a } ( ($card) x 2, @$c ) ); | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # two pair | ||||||||||||||||||||
| 99 | 3 | ▶ | sub two_pair { | ||||||||||||||||||
|
Subroutine
two_pair: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 100 | 3 | my @temp; | |||||||||||||||||||
| 101 | 3 | for my $c ( reverse combinations( [ reverse( 1 .. 13 ) ], 2 ) ) { | |||||||||||||||||||
| 102 | 234 | ▶ | for my $card ( grep { $_ != $c->[0] && $_ != $c->[1] } ( 1 .. 13 ) ) { | ||||||||||||||||||
|
Condition100%3/3
$_ != $c->[0] && $_ != $c->[1]
MC/DC100%2/2
$_ != $c->[0] && $_ != $c->[1]
$_ != $c->[0]
$_ != $c->[1]
Truth table100%3/3
A && B
A= $_ != $c->[0]B= $_ != $c->[1]
| |||||||||||||||||||||
| 103 | push @temp, | ||||||||||||||||||||
| 104 | join( '', | ||||||||||||||||||||
| 105 | 12870 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 106 | 2574 | sort { $b <=> $a } ( ( $c->[0] ) x 2, ( $c->[1] ) x 2, $card ) ); | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | # three-of-a-kind | ||||||||||||||||||||
| 113 | 3 | ▶ | sub threes { | ||||||||||||||||||
|
Subroutine
threes: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 114 | 3 | my @temp; | |||||||||||||||||||
| 115 | 3 | for my $card ( 1 .. 13 ) { | |||||||||||||||||||
| 116 | 39 | for my $c ( | |||||||||||||||||||
| 117 | 507 | reverse combinations( [ reverse grep { $_ != $card } ( 1 .. 13 ) ], 2 ) ) | |||||||||||||||||||
| 118 | { | ||||||||||||||||||||
| 119 | push @temp, join( | ||||||||||||||||||||
| 120 | '', | ||||||||||||||||||||
| 121 | 12870 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 2574 | sort { $b <=> $a } ($card) x 3, @$c | |||||||||||||||||||
| 124 | ); | ||||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | # full house | ||||||||||||||||||||
| 131 | 3 | ▶ | sub houses { | ||||||||||||||||||
|
Subroutine
houses: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 132 | 3 | my @temp; | |||||||||||||||||||
| 133 | 3 | for my $card1 ( 1 .. 13 ) { | |||||||||||||||||||
| 134 | 39 | for my $card2 ( grep { $_ != $card1 } ( 1 .. 13 ) ) { | |||||||||||||||||||
| 135 | push @temp, | ||||||||||||||||||||
| 136 | join( '', | ||||||||||||||||||||
| 137 | 2340 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 138 | 468 | sort { $b <=> $a } ( ($card1) x 3, ($card2) x 2 ) ); | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | # four-of-a-kind | ||||||||||||||||||||
| 145 | 3 | ▶ | sub fours { | ||||||||||||||||||
|
Subroutine
fours: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 146 | 3 | my @temp; | |||||||||||||||||||
| 147 | 3 | for my $card1 ( 1 .. 13 ) { | |||||||||||||||||||
| 148 | 39 | for my $card2 ( grep { $_ != $card1 } ( 1 .. 13 ) ) { | |||||||||||||||||||
| 149 | push @temp, | ||||||||||||||||||||
| 150 | join( '', | ||||||||||||||||||||
| 151 | 2340 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 152 | 468 | sort { $b <=> $a } ( ($card1) x 4, $card2 ) ); | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | # five-of-a-kind | ||||||||||||||||||||
| 159 | 3 | ▶ | sub fives { | ||||||||||||||||||
|
Subroutine
fives: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 160 | 3 | my @temp; | |||||||||||||||||||
| 161 | 3 | for my $card ( 1 .. 13 ) { | |||||||||||||||||||
| 162 | push @temp, | ||||||||||||||||||||
| 163 | join( '', | ||||||||||||||||||||
| 164 | 39 | map { sprintf( "%02d", $_ ) } | |||||||||||||||||||
| 165 | ($card) x 5); | ||||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | 3 | return [reverse @temp]; | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =head1 AUTHOR | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | Nathaniel Graham, C<< <ngraham at cpan.org> >> | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | Copyright 2016 Nathaniel Graham. | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 179 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||
| 180 | copy of the full license at: | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 4 | 1; | |||||||||||||||||||