File Coverage

blib/lib/Poker/Score/Badugi.pm
Criterion Covered Total %
statement 6 25 24.0
branch n/a
condition n/a
subroutine 2 5 40.0
pod 0 1 0.0
total 8 31 25.8


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