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