| 1 | package Poker::Score::Badugi; | ||||||||||
| 2 | 2 | our $VERSION = '0.12'; | |||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Algorithm::Combinatorics qw(combinations); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Poker::Score::Badugi - Identify and score specific Badugi poker hand. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 0.12 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | See Poker::Score for code example. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | 2 | extends 'Poker::Score'; | |||||||||
| 26 | |||||||||||
| 27 | 3 | ▶ | sub _build_rank_map { | ||||||||
|
Subroutine
_build_rank_map: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 3 | my $self = shift; | |||||||||
| 29 | 3 | $self->_rank_map( | |||||||||
| 30 | { | ||||||||||
| 31 | 'A' => '01', | ||||||||||
| 32 | '2' => '02', | ||||||||||
| 33 | '3' => '03', | ||||||||||
| 34 | '4' => '04', | ||||||||||
| 35 | '5' => '05', | ||||||||||
| 36 | '6' => '06', | ||||||||||
| 37 | '7' => '07', | ||||||||||
| 38 | '8' => '08', | ||||||||||
| 39 | '9' => '09', | ||||||||||
| 40 | 'T' => '10', | ||||||||||
| 41 | 'J' => '11', | ||||||||||
| 42 | 'Q' => '12', | ||||||||||
| 43 | 'K' => '13', | ||||||||||
| 44 | } | ||||||||||
| 45 | ); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 12 | ▶ | sub stringify_cards { | ||||||||
|
Subroutine
stringify_cards: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | 12 | my ( $self, $cards ) = @_; | |||||||||
| 50 | return join( '', | ||||||||||
| 51 | 36 | sort { $b <=> $a } | |||||||||
| 52 | 12 | map { sprintf( "%02d", $self->rank_val( $_->rank ) ) } @$cards ); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 3 | ▶ | sub _build_hands { # generates all possible Badugi hands | ||||||||
|
Subroutine
_build_hands: called CC=3 SCAR=11.0
| |||||||||||
| 56 | 3 | my $self = shift; | |||||||||
| 57 | 3 | my @all_scores = (); | |||||||||
| 58 | 3 | for my $count ( 1 .. 4 ) { | |||||||||
| 59 | 12 | my @scores; | |||||||||
| 60 | 12 | my $iter = combinations( [ 1 .. 13 ], $count ); | |||||||||
| 61 | 12 | ▶ | while ( my $c = $iter->next ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | push( @scores, | ||||||||||
| 63 | 3276 | join( '', map { sprintf( "%02d", $_ ) } sort { $b <=> $a } @$c ) ); | |||||||||
| 64 | } | ||||||||||
| 65 | 12 | $self->_hand_map->{scalar @all_scores} = $count . ' card Badugi'; | |||||||||
| 66 | 12 | push @all_scores, sort { $b <=> $a } @scores; | |||||||||
| 67 | } | ||||||||||
| 68 | 3 | $self->hands( [@all_scores] ); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head1 AUTHOR | ||||||||||
| 72 | |||||||||||
| 73 | Nathaniel Graham, C<< <ngraham at cpan.org> >> | ||||||||||
| 74 | |||||||||||
| 75 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 76 | |||||||||||
| 77 | Copyright 2016 Nathaniel Graham. | ||||||||||
| 78 | |||||||||||
| 79 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 80 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 81 | copy of the full license at: | ||||||||||
| 82 | |||||||||||
| 83 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | 2 | 1; | |||||||||