| 1 | package Poker::Game::Stud; | ||||||||||||||||||||||||||||
| 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::Hand; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Poker::Game::Stud - Base class for stud-style games | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Version 0.12 | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Stud games have no community board. Each player is dealt their own | ||||||||||||||||||||||||||||
| 24 | cards across streets. Final hand size defaults to 7 (seven-card stud); | ||||||||||||||||||||||||||||
| 25 | best five are scored via the eval engine. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Street helpers enforce typical seven-card stud structure: | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | third_street -- deal 3 (start) | ||||||||||||||||||||||||||||
| 30 | fourth_street -- deal 1 (hand size 4) | ||||||||||||||||||||||||||||
| 31 | fifth_street -- deal 1 (hand size 5) | ||||||||||||||||||||||||||||
| 32 | sixth_street -- deal 1 (hand size 6) | ||||||||||||||||||||||||||||
| 33 | seventh_street / river -- deal 1 (hand size 7) | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | extends 'Poker::Game'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | has '+hole_count' => ( default => sub { 7 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | has '+board_size' => ( default => sub { 0 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 deal_to | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | $game->deal_to($hand, 3); | ||||||||||||||||||||||||||||
| 45 | $game->deal_to($hand, 1, ['As']); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Append cards to an existing hand. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | ▶ | sub deal_to { | ||||||||||||||||||||||||||
|
Subroutine
deal_to: called CC=6 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 6 | my ( $self, $hand, $count, $specific ) = @_; | |||||||||||||||||||||||||||
| 53 | 6 | ▶ | die "deal_to 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")
| |||||||||||||||||||||||||||||
| 54 | unless $hand && $hand->isa('Poker::Hand'); | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | $count //= 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$count //= 1
MC/DC0%0/1
$count //= 1
$count
Truth table50%1/2
A
A= $count
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | my $new; | |||||||||||||||||||||||||||
| 58 | 6 | ▶ | if ( defined $specific ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 6 | my $cards = $self->_normalize_cards( $count, $specific ); | |||||||||||||||||||||||||||
| 60 | 6 | ▶ | die "expected $count cards" unless @$cards == $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 6 | $new = $self->deal_cards($cards); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||
| 64 | 0 | $new = $self->dealer->deal($count); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 6 | push @{ $hand->cards }, @$new; | |||||||||||||||||||||||||||
| 67 | 6 | return $hand; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 7 | ▶ | sub _assert_hand_size { | ||||||||||||||||||||||||||
|
Subroutine
_assert_hand_size: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 7 | my ( $self, $hand, $expect ) = @_; | |||||||||||||||||||||||||||
| 72 | 7 | my $n = scalar @{ $hand->cards }; | |||||||||||||||||||||||||||
| 73 | 7 | ▶ | die "expected hand size $expect, got $n" unless $n == $expect; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 third_street | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Deal the first three cards to an empty hand. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub third_street { | ||||||||||||||||||||||||||
|
Subroutine
third_street: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 2 | my ( $self, $hand, $specific ) = @_; | |||||||||||||||||||||||||||
| 84 | 2 | $self->_assert_hand_size( $hand, 0 ); | |||||||||||||||||||||||||||
| 85 | 2 | return $self->deal_to( $hand, 3, $specific ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head2 fourth_street / fifth_street / sixth_street / seventh_street | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Deal one additional card at each street. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | ▶ | sub fourth_street { | ||||||||||||||||||||||||||
|
Subroutine
fourth_street: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 1 | my ( $self, $hand, $specific ) = @_; | |||||||||||||||||||||||||||
| 96 | 1 | $self->_assert_hand_size( $hand, 3 ); | |||||||||||||||||||||||||||
| 97 | 1 | return $self->deal_to( $hand, 1, $specific ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | sub fifth_street { | ||||||||||||||||||||||||||
|
Subroutine
fifth_street: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 2 | my ( $self, $hand, $specific ) = @_; | |||||||||||||||||||||||||||
| 102 | 2 | $self->_assert_hand_size( $hand, 4 ); | |||||||||||||||||||||||||||
| 103 | 1 | return $self->deal_to( $hand, 1, $specific ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | ▶ | sub sixth_street { | ||||||||||||||||||||||||||
|
Subroutine
sixth_street: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 1 | my ( $self, $hand, $specific ) = @_; | |||||||||||||||||||||||||||
| 108 | 1 | $self->_assert_hand_size( $hand, 5 ); | |||||||||||||||||||||||||||
| 109 | 1 | return $self->deal_to( $hand, 1, $specific ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub seventh_street { | ||||||||||||||||||||||||||
|
Subroutine
seventh_street: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 1 | my ( $self, $hand, $specific ) = @_; | |||||||||||||||||||||||||||
| 114 | 1 | $self->_assert_hand_size( $hand, 6 ); | |||||||||||||||||||||||||||
| 115 | 1 | return $self->deal_to( $hand, 1, $specific ); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub river { shift->seventh_street(@_) } | ||||||||||||||||||||||||||
|
Subroutine
river: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 deal_hole | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | For stud, C<deal_hole> starts an empty hand and deals third street | ||||||||||||||||||||||||||||
| 123 | (3 cards), or accepts a specific list of up to 7 cards. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 3 | ▶ | around deal_hole => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.0
| |||||||||||||||||||||||||||||
| 128 | 3 | my ( $orig, $self, $arg ) = @_; | |||||||||||||||||||||||||||
| 129 | 3 | ▶ | if ( ref $arg eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 3 | return $self->$orig($arg); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 0 | my $hand = Poker::Hand->new( cards => [] ); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $n = defined $arg ? $arg : 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | return $self->deal_to( $hand, $n ); | |||||||||||||||||||||||||||
| 135 | 1 | }; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||