File Coverage

blib/lib/Poker/Eval/Community.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Poker::Eval::Community;
2 1     1   3419 use Algorithm::Combinatorics qw(combinations);
  0            
  0            
3             use Moo;
4              
5             =head1 NAME
6              
7             Poker::Eval::Community - Evaluate and score hand using any combination of hole and community cards.
8              
9             =head1 VERSION
10              
11             Version 0.02
12              
13             =cut
14              
15             our $VERSION = '0.02';
16              
17              
18             =head1 SYNOPSIS
19              
20             See Poker::Eval for example code.
21              
22             =cut
23              
24             extends 'Poker::Eval';
25              
26             has 'card_count' => (
27             is => 'rw',
28             builder => '_build_card_count',
29             );
30              
31             sub _build_card_count {
32             return 5;
33             }
34              
35             sub best_hand {
36             my ( $self, $hole ) = @_;
37             my $hand = Poker::Hand->new(cards => $hole);
38             return $hand
39             if $self->card_count >
40             ( scalar @$hole + scalar @{ $self->community_cards } );
41             my $iter = $self->make_iter($hole);
42             while ( my $combo = $iter->next ) {
43             my $score = $self->scorer->score($combo);
44             if ( defined $score && $score >= $hand->score ) {
45             $hand->score($score);
46             $hand->best_combo($combo);
47             }
48             }
49             $hand->name($self->scorer->hand_name( $hand->score ));
50             return $hand;
51             }
52              
53             sub make_iter {
54             my ( $self, $hole ) = @_;
55             my $iter =
56             combinations( [ @$hole, @{ $self->community_cards } ], $self->card_count );
57             return $iter;
58             }
59              
60             =head1 AUTHOR
61              
62             Nathaniel Graham, C<< >>
63              
64             =head1 LICENSE AND COPYRIGHT
65              
66             Copyright 2016 Nathaniel Graham.
67              
68             This program is free software; you can redistribute it and/or modify it
69             under the terms of the the Artistic License (2.0). You may obtain a
70             copy of the full license at:
71              
72             L
73              
74             =cut
75              
76             1;