| 1 | package Game::Gin::Deal; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Game::Gin::Deck (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Game::Gin::Hand (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Game::Gin::Error (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Game::Gin::Deadwood qw(KNOCK_AT); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Game::Gin::Scoring qw(settle); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | has number => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | has dealer => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | has hands => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | has stock => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | has discard => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | has turn => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | has phase => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | has taken => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | has result => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 10 | has history => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 31998 | ▶ | sub other { return $_[0] eq 'p1' ? 'p2' : 'p1' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
other: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2069 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2069 | my ($class, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 2069 | my $seed = $o{seed}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 2069 | ▶ | return Game::Gin::Error->new_code('no_seed') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $seed and length $seed == 32
MC/DC0%0/2
defined $seed and length $seed == 32
defined $seed
length $seed == 32
Truth table33%1/3
A and B
A= defined $seedB= length $seed == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2069 | ▶ | my $number = $o{number} || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o{'number'} || 1
MC/DC0%0/1
$o{'number'} || 1
$o{'number'}
Truth table50%1/2
A
A= $o{'number'}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2069 | ▶ | my $dealer = $o{dealer} || 'p1'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o{'dealer'} || 'p1'
MC/DC0%0/1
$o{'dealer'} || 'p1'
$o{'dealer'}
Truth table50%1/2
A
A= $o{'dealer'}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2069 | my $pone = other($dealer); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2069 | my $deal = Game::Gin::Deck::deal_for($seed, $number); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 44 | seed => $seed, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | number => $number, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | dealer => $dealer, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | hands => { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 2069 | $pone => Game::Gin::Hand->new(cards => [ @{ $deal->{non_dealer} } ]), | |||||||||||||||||||||||||||||||||||||||||
| 49 | 2069 | $dealer => Game::Gin::Hand->new(cards => [ @{ $deal->{dealer} } ]), | |||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 2069 | stock => [ @{ $deal->{stock} } ], | |||||||||||||||||||||||||||||||||||||||||
| 52 | 2069 | discard => [ $deal->{upcard} ], | |||||||||||||||||||||||||||||||||||||||||
| 53 | turn => $pone, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | phase => 'upcard', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | taken => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | history => [], | ||||||||||||||||||||||||||||||||||||||||||
| 57 | result => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 2069 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 217258 | ▶ | sub over { return $_[0]->result ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
over: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 54140 | ▶ | sub upcard { my $d = $_[0]->discard; return @$d ? $d->[-1] : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upcard: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 210830 | ▶ | sub hand_of { return $_[0]->hands->{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 84303 | ▶ | sub stock_left { return scalar @{ $_[0]->stock } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stock_left: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 55939 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 55939 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 55939 | ▶ | return [] if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 55939 | ▶ | return [] unless defined $seat && ($self->turn // '') eq $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $seat and ($self->turn // "") eq $seat
$self->turn // ""
MC/DC0%0/2
defined $seat and ($self->turn // "") eq $seat
defined $seat
$self->turn
Truth table33%1/3
A and B
A= defined $seatB= $self->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 55938 | my $phase = $self->phase; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 55938 | ▶ | return [ { kind => 'take' }, { kind => 'pass' } ] if $phase eq 'upcard'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 53631 | ▶ | return [ { kind => 'draw' } ] if $phase eq 'forced_draw'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 53299 | ▶ | if ($phase eq 'draw') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 25683 | my @out = ({ kind => 'draw' }); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 25683 | ▶ | push @out, { kind => 'take' } if defined $self->upcard; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 25683 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 27616 | my $hand = $self->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 27616 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 27616 | ▶ | push @out, { kind => 'big_gin' } if $hand->deadwood == 0 && $hand->full; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hand->deadwood == 0 and $hand->full
MC/DC50%1/2
$hand->deadwood == 0 and $hand->full
$hand->deadwood == 0
$hand->full
Truth table66%2/3
A and B
A= $hand->deadwood == 0B= $hand->full
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 27616 | for my $card (@{ $hand->cards }) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 303776 | ▶ | next if defined $self->taken && $self->taken && $card == $self->taken; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->taken and $self->taken and $card == $self->taken
defined $self->taken and $self->taken
MC/DC66%2/3
defined $self->taken and $self->taken and $card == $self->taken
defined $self->taken
$self->taken
$card == $self->taken
Truth table75%3/4
A and B and C
A= defined $self->takenB= $self->takenC= $card == $self->taken
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 297235 | push @out, { kind => 'discard', card => $card }; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 297235 | my @rest = grep { $_ != $card } @{ $hand->cards }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 297235 | my $left = Game::Gin::Deadwood::deadwood(\@rest); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 297235 | ▶ | push @out, { kind => 'discard', card => $card, knock => 1 } if $left <= KNOCK_AT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 27616 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 59994 | ▶ | sub apply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply: called CC=18 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 59994 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 59994 | ▶ | return Game::Gin::Error->new_code('hand_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 59994 | ▶ | return Game::Gin::Error->new_code('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $seat and ($self->turn // "") eq $seat
$self->turn // ""
MC/DC0%0/2
defined $seat and ($self->turn // "") eq $seat
defined $seat
$self->turn
Truth table33%1/3
A and B
A= defined $seatB= $self->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | unless defined $seat && ($self->turn // '') eq $seat; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 59992 | ▶ | my $kind = ref $move eq 'HASH' ? ($move->{kind} // '') : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$move->{"kind"} // ""
MC/DC0%0/1
$move->{"kind"} // ""
$move->{"kind"}
Truth table50%1/2
A
A= $move->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 59992 | my $phase = $self->phase; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 59992 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 59992 | ▶ | if ($phase eq 'upcard') { @out = $self->_first_turn($seat, $kind) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($phase eq 'forced_draw') { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 368 | ▶ | return Game::Gin::Error->new_code('not_legal') unless $kind eq 'draw'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 367 | @out = $self->_draw($seat); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif ($phase eq 'draw') { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 27536 | ▶ | if ($kind eq 'draw') { @out = $self->_draw($seat) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 5443 | elsif ($kind eq 'take') { @out = $self->_take($seat) } | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | else { return Game::Gin::Error->new_code('not_legal') } | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | elsif ($kind eq 'big_gin') { @out = $self->_big_gin($seat) } | |||||||||||||||||||||||||||||||||||||||||
| 117 | 29579 | elsif ($kind eq 'discard') { @out = $self->_discard($seat, $move) } | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | else { return Game::Gin::Error->new_code('not_legal') } | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 59991 | ▶ | return $out[0] if @out == 1 && ref $out[0] eq 'Game::Gin::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@out == 1 and ref $out[0] eq "Game::Gin::Error"
MC/DC100%2/2
@out == 1 and ref $out[0] eq "Game::Gin::Error"
@out == 1
ref $out[0] eq "Game::Gin::Error"
Truth table100%3/3
A and B
A= @out == 1B= ref $out[0] eq "Game::Gin::Error"
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 59985 | ▶ | $self->history([ @{ $self->history || [] }, @out ]); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->history || []
MC/DC100%1/1
$self->history || []
$self->history
Truth table100%2/2
A
A= $self->history
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 59985 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 2503 | ▶ | sub _first_turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_first_turn: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2503 | my ($self, $seat, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 2503 | ▶ | return $self->_take($seat) if $kind eq 'take'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 809 | ▶ | return Game::Gin::Error->new_code('not_legal') unless $kind eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 809 | my @out = ({ kind => 'pass', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 809 | ▶ | if ($seat eq $self->dealer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 368 | $self->turn(other($self->dealer)); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 368 | $self->phase('forced_draw'); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 441 | $self->turn($self->dealer); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 809 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 7137 | ▶ | sub _take { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 7137 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 7137 | my $card = $self->upcard; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 7137 | ▶ | return Game::Gin::Error->new_code('not_legal') unless defined $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 7137 | my @pile = @{ $self->discard }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 7137 | pop @pile; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 7137 | $self->discard(\@pile); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 7137 | $self->hand_of($seat)->add($card); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 7137 | $self->taken($card); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 7137 | $self->phase('discard'); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 7137 | return ({ kind => 'take', seat => $seat, card => $card }); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 22460 | ▶ | sub _draw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 22460 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 22460 | my @stock = @{ $self->stock }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 22460 | ▶ | return Game::Gin::Error->new_code('not_legal') unless @stock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 22459 | my $card = shift @stock; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 22459 | $self->stock(\@stock); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 22459 | $self->hand_of($seat)->add($card); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 22459 | $self->taken(0); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 22459 | $self->phase('discard'); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 22459 | return ({ kind => 'draw', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 29579 | ▶ | sub _discard { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_discard: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 29579 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 29579 | my $card = $move->{card}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 29579 | my $hand = $self->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 29579 | ▶ | return Game::Gin::Error->new_code('not_held') unless $hand->has_card($card); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 29576 | ▶ | return Game::Gin::Error->new_code('just_taken') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->taken and $card == $self->taken
MC/DC100%2/2
$self->taken and $card == $self->taken
$self->taken
$card == $self->taken
Truth table100%3/3
A and B
A= $self->takenB= $card == $self->taken
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | if $self->taken && $card == $self->taken; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 29575 | $hand->remove($card); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 29575 | $self->discard([ @{ $self->discard }, $card ]); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 29575 | $self->taken(0); | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 29575 | my $left = $hand->deadwood; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 29575 | ▶ | if ($move->{knock}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 2016 | ▶ | return Game::Gin::Error->new_code('cannot_knock') if $left > KNOCK_AT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 2015 | my @out = ({ kind => 'discard', seat => $seat, card => $card, knock => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 2015 | ▶ | push @out, $self->_finish($seat, gin => ($left == 0 ? 1 : 0)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2015 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 27559 | my @out = ({ kind => 'discard', seat => $seat, card => $card }); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 27559 | ▶ | if ($self->stock_left <= 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 19 | $self->result({ kind => 'cancelled', winner => undef, points => 0 }); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 19 | $self->turn(undef); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 19 | $self->phase('over'); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 19 | push @out, { kind => 'cancelled' }; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 27540 | $self->turn(other($seat)); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 27540 | $self->phase('draw'); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 27540 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | sub _big_gin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_big_gin: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | my $hand = $self->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | ▶ | return Game::Gin::Error->new_code('not_big_gin') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hand->full and $hand->deadwood == 0
MC/DC0%0/2
$hand->full and $hand->deadwood == 0
$hand->full
$hand->deadwood == 0
Truth table33%1/3
A and B
A= $hand->fullB= $hand->deadwood == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | unless $hand->full && $hand->deadwood == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | return ({ kind => 'big_gin', seat => $seat }, $self->_finish($seat, big_gin => 1)); | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 2021 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 2021 | my ($self, $knocker, %how) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 2021 | my $defender = other($knocker); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 2021 | my $hand = $self->hand_of($knocker); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 2021 | my $best = $hand->best; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | my $r = settle( | ||||||||||||||||||||||||||||||||||||||||||
| 216 | knocker => $knocker, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | defender => $defender, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | knocker_deadwood => $best->{deadwood}, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | knocker_melds => $best->{melds}, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | defender_cards => $self->hand_of($defender)->cards, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | gin => ($how{gin} || $how{big_gin} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2021 | ▶ | big_gin => ($how{big_gin} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$how{"gin"} or $how{"big_gin"}
MC/DC100%2/2
$how{"gin"} or $how{"big_gin"}
$how{"gin"}
$how{"big_gin"}
Truth table100%3/3
A or B
A= $how{"gin"}B= $how{"big_gin"}
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 2021 | $self->result($r); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 2021 | $self->turn(undef); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 2021 | $self->phase('over'); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 2021 | return ({ %$r, how => $r->{kind}, kind => 'hand_end' }); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | __END__ | ||||||||||||||||||||||||||||||||||||||||||