File Coverage

blib/lib/Poker/Eval/Badugi.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 6 0.0
condition 0 6 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 13 43 30.2


line stmt bran cond sub pod time code
1             package Poker::Eval::Badugi;
2 1     1   626 use Algorithm::Combinatorics qw(combinations);
  1         1  
  1         38  
3 1     1   3 use Moo;
  1         1  
  1         3  
4 1     1   486 use Poker::Score::Badugi;
  1         1  
  1         195  
5              
6             =head1 NAME
7              
8             Poker::Eval::Badugi - Evaluate and score Badugi poker hands.
9              
10             =head1 VERSION
11              
12             Version 0.02
13              
14             =cut
15              
16             our $VERSION = '0.02';
17              
18              
19             =head1 SYNOPSIS
20              
21             See Poker::Eval for code examples
22              
23             =cut
24              
25             extends 'Poker::Eval';
26              
27             sub best_hand {
28 0     0 1   my ( $self, $hole ) = @_;
29 0           my $best = Poker::Hand->new(cards => $hole);
30 0 0         my $iter = combinations( $hole, scalar @$hole > 4 ? 4 : scalar @$hole);
31 0           while (my $combo = $iter->next ) {
32 0           my (@list, %seen);
33 0           for my $c (sort { $self->scorer->_rank_map->{$a->rank} <=> $self->scorer->_rank_map->{$b->rank} } @$combo) {
  0            
34 0 0 0       if ( !$seen{ $c->suit } && !$seen{ $c->rank } ) {
35 0           push @list, $c;
36 0           $seen{ $c->suit }++;
37 0           $seen{ $c->rank }++;
38             }
39             }
40 0           my $score = $self->scorer->score( [@list] );
41 0 0 0       if ( defined $score && $score >= $best->score ) {
42 0           $best->score($score);
43 0           $best->best_combo(\@list);
44             }
45             }
46 0           $best->name($self->scorer->hand_name( $best->score ));
47 0           return $best;
48             }
49              
50             =head1 AUTHOR
51              
52             Nathaniel Graham, C<< >>
53              
54             =head1 LICENSE AND COPYRIGHT
55              
56             Copyright 2016 Nathaniel Graham.
57              
58             This program is free software; you can redistribute it and/or modify it
59             under the terms of the the Artistic License (2.0). You may obtain a
60             copy of the full license at:
61              
62             L
63              
64             =cut
65              
66             1;