| 1 | package Poker::Game::CrazyPineapple; | ||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Poker::Eval::Community; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Poker::Score::High; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Poker::Game::CrazyPineapple - Crazy Pineapple | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Version 0.12 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | use Poker::Game::CrazyPineapple; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my $game = Poker::Game::CrazyPineapple->new; | ||||||||||||||||||||||||||||
| 27 | my $hero = $game->deal_hole(['As', 'Kd', '7c']); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $game->flop(['Ah', 'Kc', '2d']); | ||||||||||||||||||||||||||||
| 30 | # Must discard one hole card before turn/runout | ||||||||||||||||||||||||||||
| 31 | $game->discard($hero, '7c'); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | $game->turn('9s'); | ||||||||||||||||||||||||||||
| 34 | $game->river('3c'); | ||||||||||||||||||||||||||||
| 35 | $game->evaluate($hero); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Crazy Pineapple: three hole cards, five community cards. After the flop | ||||||||||||||||||||||||||||
| 40 | each player discards one hole card. C<runout>, C<turn>, and C<river> are | ||||||||||||||||||||||||||||
| 41 | blocked until C<discard> has been called (via C<pending_discards>). | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | extends 'Poker::Game'; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | has '+hole_count' => ( default => sub { 3 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | has '+board_size' => ( default => sub { 5 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||
| 51 | 2 | my ( $orig, $class, @args ) = @_; | |||||||||||||||||||||||||||
| 52 | 2 | my $args = $class->$orig(@args); | |||||||||||||||||||||||||||
| 53 | 2 | ▶ | $args = {} unless ref $args eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | $args->{scorer} //= Poker::Score::High->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"scorer"} //= "Poker::Score::High"->new
MC/DC0%0/2
$args->{"scorer"} //= "Poker::Score::High"->new
$args->{"scorer"}
"Poker::Score::High"->new
Truth table33%1/3
A //= B
A= $args->{"scorer"}B= "Poker::Score::High"->new
| |||||||||||||||||||||||||||||
| 56 | $args->{eval_engine} //= Poker::Eval::Community->new( | ||||||||||||||||||||||||||||
| 57 | scorer => $args->{scorer}, | ||||||||||||||||||||||||||||
| 58 | 2 | ▶ | ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"eval_engine"} //= "Poker::Eval::Community"->new("scorer", $args->{"scorer"})
MC/DC0%0/2
$args->{"eval_engine"} //= "Poker::Eval::Community"->new("scorer", $args->{"scorer"})
$args->{"eval_engine"}
"Poker::Eval::Community"->new("scorer", $args->{"scorer"})
Truth table33%1/3
A //= B
A= $args->{"eval_engine"}B= "Poker::Eval::Community"->new("scorer", $args->{"scorer"})
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | return $args; | |||||||||||||||||||||||||||
| 61 | 1 | }; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 flop | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Deals the flop and sets C<pending_discards> so further board cards are | ||||||||||||||||||||||||||||
| 66 | blocked until C<discard> is called. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | around flop => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 2 | my ( $orig, $self, @args ) = @_; | |||||||||||||||||||||||||||
| 72 | 2 | my $board = $self->$orig(@args); | |||||||||||||||||||||||||||
| 73 | 2 | $self->pending_discards(1); | |||||||||||||||||||||||||||
| 74 | 2 | return $board; | |||||||||||||||||||||||||||
| 75 | 1 | }; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 discard | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | $game->discard($hand, '7c'); # by card name | ||||||||||||||||||||||||||||
| 80 | $game->discard($hand, $card_obj); # by Poker::Card | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Remove one hole card from C<$hand> and clear the pending-discard flag. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub discard { | ||||||||||||||||||||||||||
|
Subroutine
discard: called CC=12 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 2 | my ( $self, $hand, $which ) = @_; | |||||||||||||||||||||||||||
| 88 | 2 | ▶ | die "discard requires a Poker::Hand" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hand and $hand->isa("Poker::Hand")
MC/DC0%0/2
$hand and $hand->isa("Poker::Hand")
$hand
$hand->isa("Poker::Hand")
Truth table33%1/3
A and B
A= $handB= $hand->isa("Poker::Hand")
| |||||||||||||||||||||||||||||
| 89 | unless $hand && $hand->isa('Poker::Hand'); | ||||||||||||||||||||||||||||
| 90 | 2 | ▶ | die "no pending discard" unless $self->pending_discards; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | die "discard requires a card" unless defined $which; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | my @keep; | |||||||||||||||||||||||||||
| 94 | 2 | my $removed = 0; | |||||||||||||||||||||||||||
| 95 | 2 | for my $card ( @{ $hand->cards } ) { | |||||||||||||||||||||||||||
| 96 | 6 | my $name = $card->rank . $card->suit; | |||||||||||||||||||||||||||
| 97 | 6 | ▶ | my $match = | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$card == $which or $name eq $which->rank . $which->suit
MC/DC0%0/2
$card == $which or $name eq $which->rank . $which->suit
$card == $which
$name eq $which->rank . $which->suit
Truth table0%0/3
A or B
A= $card == $whichB= $name eq $which->rank . $which->suit
| |||||||||||||||||||||||||||||
| 98 | ref $which | ||||||||||||||||||||||||||||
| 99 | ? ( $card == $which || $name eq ( $which->rank . $which->suit ) ) | ||||||||||||||||||||||||||||
| 100 | : ( $name eq $which ); | ||||||||||||||||||||||||||||
| 101 | 6 | ▶ | if ( $match && !$removed ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$match and not $removed
MC/DC50%1/2
$match and not $removed
$match
not $removed
Truth table66%2/3
A and not(B)
A= $matchB= not $removed
| |||||||||||||||||||||||||||||
| 102 | 1 | $removed = 1; | |||||||||||||||||||||||||||
| 103 | 1 | next; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 5 | push @keep, $card; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 2 | ▶ | die "card not found in hand: $which" unless $removed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 1 | ▶ | die "Crazy Pineapple discard must leave 2 hole cards" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | unless @keep == 2; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | $hand->cards( \@keep ); | |||||||||||||||||||||||||||
| 112 | 1 | $self->pending_discards(0); | |||||||||||||||||||||||||||
| 113 | 1 | return $hand; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Nathaniel Graham, C<< <ngraham at cpan.org> >> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Copyright 2016-2026 Nathaniel Graham. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||