| 1 | package Game::Schnapsen::Deal; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 21 | ▶ | use Game::Schnapsen::Card (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use Game::Schnapsen::Deck (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use Game::Schnapsen::Hand (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use Game::Schnapsen::Error (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 21 | ▶ | use Game::Schnapsen::Variant (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 21 | ▶ | use Game::Schnapsen::Trick qw(winner_of value_of legal_follows); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 21 | ▶ | use Game::Schnapsen::Declare qw(marriages_in exchange_card); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 21 | ▶ | use Game::Schnapsen::Scoring qw(deal_result); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 21 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 21 | has variant => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 21 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 21 | has number => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 21 | has dealer => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 21 | has trump => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 21 | has hands => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 21 | has talon => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 21 | has turn_up => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 21 | has drawn => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 21 | has closed => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 21 | has closed_by => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 21 | has close_state => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 21 | has tricks => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 21 | has taken => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 21 | has melds => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 21 | has turn => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 21 | has leader => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | has lead => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 21 | has must_lead => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 21 | has result => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 21 | has history => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 181177 | ▶ | sub _v { return $_[0]->variant } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_v: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 62858 | ▶ | sub other { return $_[0] eq 'p1' ? 'p2' : 'p1' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
other: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 4450 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 4450 | my ($class, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 4450 | my $bad = Game::Schnapsen::Variant::check_variant($o{variant}); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 4450 | ▶ | return $bad if $bad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 4448 | my $seed = $o{seed}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 4448 | ▶ | return Game::Schnapsen::Error->new_code('no_seed') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $seed and length $seed == 32
MC/DC50%1/2
defined $seed and length $seed == 32
defined $seed
length $seed == 32
Truth table66%2/3
A and B
A= defined $seedB= length $seed == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 4447 | ▶ | my $number = defined $o{number} ? $o{number} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4447 | ▶ | return Game::Schnapsen::Error->new_code('bad_deal') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | unless $number =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 4446 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4446 | my $pone = other($dealer); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 4446 | my $deal = Game::Schnapsen::Deck::deal_for($seed, $number, $o{variant}); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | variant => $o{variant}, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | seed => $seed, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | number => $number, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | dealer => $dealer, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | trump => Game::Schnapsen::Card::suit_of($deal->{turn_up}), | ||||||||||||||||||||||||||||||||||||||||||
| 75 | hands => { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 4446 | $pone => Game::Schnapsen::Hand->new(cards => [ @{ $deal->{non_dealer} } ]), | |||||||||||||||||||||||||||||||||||||||||
| 77 | 4446 | $dealer => Game::Schnapsen::Hand->new(cards => [ @{ $deal->{dealer} } ]), | |||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 4446 | talon => [ @{ $deal->{talon} } ], | |||||||||||||||||||||||||||||||||||||||||
| 80 | turn_up => $deal->{turn_up}, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 4446 | drawn => 1, | |||||||||||||||||||||||||||||||||||||||||
| 82 | closed => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | closed_by => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | close_state => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | tricks => [], | ||||||||||||||||||||||||||||||||||||||||||
| 86 | taken => { p1 => 0, p2 => 0 }, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | melds => [], | ||||||||||||||||||||||||||||||||||||||||||
| 88 | turn => $pone, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | leader => $pone, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | lead => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | must_lead => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | result => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | history => [], | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 983827 | ▶ | sub hand_of { return $_[0]->hands->{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 158221 | ▶ | sub points_of { return $_[0]->taken->{ $_[1] } || 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
points_of: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]->taken->{$_[1]} || 0
MC/DC100%1/1
$_[0]->taken->{$_[1]} || 0
$_[0]->taken->{$_[1]}
Truth table100%2/2
A
A= $_[0]->taken->{$_[1]}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 96732 | ▶ | sub tricks_won { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tricks_won: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 96732 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 96732 | return scalar grep { $_->{winner} eq $seat } @{ $self->tricks }; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 431605 | ▶ | sub talon_left { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
talon_left: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 431605 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 431605 | ▶ | return scalar(@{ $self->talon }) + (defined $self->turn_up ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 388417 | ▶ | sub draw_left { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw_left: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 388417 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 388417 | ▶ | return 0 if $self->closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 363505 | return $self->talon_left; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 187019 | ▶ | sub phase { return $_[0]->draw_left ? 1 : 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
phase: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 439814 | ▶ | sub cards_out { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cards_out: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 439814 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 439814 | ▶ | return $self->hand_of('p1')->count == 0 && $self->hand_of('p2')->count == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->hand_of("p1")->count == 0 and $self->hand_of("p2")->count == 0
MC/DC100%2/2
$self->hand_of("p1")->count == 0 and $self->hand_of("p2")->count == 0
$self->hand_of("p1")->count == 0
$self->hand_of("p2")->count == 0
Truth table100%3/3
A and B
A= $self->hand_of("p1")->count == 0B= $self->hand_of("p2")->count == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 406922 | ▶ | sub over { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
over: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 406922 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 406922 | ▶ | return 1 if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 402573 | return $self->cards_out; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 9168 | ▶ | sub last_trick { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_trick: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 9168 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 9168 | my $t = $self->tricks; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 9168 | ▶ | return @$t ? $t->[-1] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 320944 | ▶ | sub pending_draw { return $_[0]->drawn ? 0 : 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pending_draw: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 68743 | ▶ | sub can_exchange { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_exchange: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 68743 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 68743 | ▶ | return undef if $self->closed || $self->pending_draw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->closed or $self->pending_draw
MC/DC50%1/2
$self->closed or $self->pending_draw
$self->closed
$self->pending_draw
Truth table66%2/3
A or B
A= $self->closedB= $self->pending_draw
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 61146 | ▶ | return undef unless $self->draw_left && defined $self->turn_up; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->draw_left and defined $self->turn_up
MC/DC50%1/2
$self->draw_left and defined $self->turn_up
$self->draw_left
defined $self->turn_up
Truth table66%2/3
A and B
A= $self->draw_leftB= defined $self->turn_up
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 41303 | ▶ | return undef if Game::Schnapsen::Variant::exchange_needs_trick($self->_v) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
Game::Schnapsen::Variant::exchange_needs_trick($self->_v) and not $self->tricks_won($seat)
MC/DC100%2/2
Game::Schnapsen::Variant::exchange_needs_trick($self->_v) and not $self->tricks_won($seat)
Game::Schnapsen::Variant::exchange_needs_trick($self->_v)
not $self->tricks_won($seat)
Truth table100%3/3
A and not(B)
A= Game::Schnapsen::Variant::exchange_needs_trick($self->_v)B= not $self->tricks_won($seat)
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | && !$self->tricks_won($seat); | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 37735 | return exchange_card($self->hand_of($seat)->cards, $self->trump, | |||||||||||||||||||||||||||||||||||||||||
| 144 | Game::Schnapsen::Variant::exchange_rank($self->_v)); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 83528 | ▶ | sub can_close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_close: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 83528 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 83528 | ▶ | return 0 if $self->closed || !$self->draw_left; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->closed or not $self->draw_left
MC/DC100%2/2
$self->closed or not $self->draw_left
$self->closed
not $self->draw_left
Truth table100%3/3
A or not(B)
A= $self->closedB= not $self->draw_left
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 56086 | ▶ | return 0 if $self->pending_draw | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->pending_draw and not Game::Schnapsen::Variant::close_before_draw($self->_v)
MC/DC0%0/2
$self->pending_draw and not Game::Schnapsen::Variant::close_before_draw($self->_v)
$self->pending_draw
not Game::Schnapsen::Variant::close_before_draw($self->_v)
Truth table66%2/3
A and not(B)
A= $self->pending_drawB= not Game::Schnapsen::Variant::close_before_draw($self->_v)
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | && !Game::Schnapsen::Variant::close_before_draw($self->_v); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 56086 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 85009 | ▶ | sub can_claim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_claim: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 85009 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 85009 | ▶ | return 0 if $self->over || defined $self->lead; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->over or defined $self->lead
MC/DC50%1/2
$self->over or defined $self->lead
$self->over
defined $self->lead
Truth table66%2/3
A or B
A= $self->overB= defined $self->lead
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 85005 | ▶ | return 0 unless ($self->turn // '') eq $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->turn // ""
MC/DC0%0/1
$self->turn // ""
$self->turn
Truth table50%1/2
A
A= $self->turn
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 85003 | ▶ | return 1 if @{ $self->tricks }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 7961 | ▶ | return 1 if grep { $_->{seat} eq $seat } @{ $self->melds }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 6846 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 70031 | ▶ | sub can_marry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_marry: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 70031 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 70031 | ▶ | return [] if $self->must_lead || $self->pending_draw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->must_lead or $self->pending_draw
MC/DC50%1/2
$self->must_lead or $self->pending_draw
$self->must_lead
$self->pending_draw
Truth table66%2/3
A or B
A= $self->must_leadB= $self->pending_draw
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 64143 | ▶ | return [] unless Game::Schnapsen::Variant::marriage_after_close($self->_v) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
Game::Schnapsen::Variant::marriage_after_close($self->_v) or $self->phase == 1
MC/DC100%2/2
Game::Schnapsen::Variant::marriage_after_close($self->_v) or $self->phase == 1
Game::Schnapsen::Variant::marriage_after_close($self->_v)
$self->phase == 1
Truth table100%3/3
A or B
A= Game::Schnapsen::Variant::marriage_after_close($self->_v)B= $self->phase == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | || $self->phase == 1; | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 50201 | return marriages_in($self->hand_of($seat)->cards, $self->trump); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 136945 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 136945 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 136945 | ▶ | return [] if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 136941 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 136938 | my $hand = $self->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 136938 | ▶ | if (defined $self->lead) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 54430 | my $can = legal_follows($hand->cards, $self->lead, $self->trump, $self->phase); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 54430 | return [ map { { kind => 'follow', card => $_ } } @$can ]; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 82508 | ▶ | if ($self->pending_draw) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 15494 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 15494 | ▶ | push @out, { kind => 'claim' } if $self->can_claim($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 15494 | ▶ | push @out, { kind => 'close' } if $self->can_close($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 15494 | push @out, { kind => 'draw' }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 15494 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 67014 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 67014 | ▶ | push @out, { kind => 'claim' } if $self->can_claim($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 67014 | ▶ | push @out, { kind => 'exchange' } if $self->can_exchange($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 67014 | ▶ | push @out, { kind => 'close' } if $self->can_close($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | push @out, { kind => 'marriage', suit => $_->{suit}, value => $_->{value} } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 67014 | for @{ $self->can_marry($seat) }; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 67014 | ▶ | my $leads = $self->must_lead || $hand->cards; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->must_lead || $hand->cards
MC/DC0%0/2
$self->must_lead || $hand->cards
$self->must_lead
$hand->cards
Truth table66%2/3
A || B
A= $self->must_leadB= $hand->cards
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 67014 | push @out, { kind => 'lead', card => $_ } for @$leads; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 67014 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 21 | my %HANDLER = ( | |||||||||||||||||||||||||||||||||||||||||
| 205 | lead => '_lead', | ||||||||||||||||||||||||||||||||||||||||||
| 206 | follow => '_follow', | ||||||||||||||||||||||||||||||||||||||||||
| 207 | draw => '_draw_move', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | marriage => '_marriage', | ||||||||||||||||||||||||||||||||||||||||||
| 209 | exchange => '_exchange', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | close => '_close', | ||||||||||||||||||||||||||||||||||||||||||
| 211 | claim => '_claim', | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 93049 | ▶ | sub apply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 93049 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 93049 | ▶ | return Game::Schnapsen::Error->new_code('deal_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 93047 | ▶ | return Game::Schnapsen::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
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | unless defined $seat && ($self->turn // '') eq $seat; | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 93044 | ▶ | my $kind = ref $move eq 'HASH' ? ($move->{kind} // '') : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$move->{"kind"} // ""
MC/DC100%1/1
$move->{"kind"} // ""
$move->{"kind"}
Truth table100%2/2
A
A= $move->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 93044 | ▶ | my @allowed = defined $self->lead ? ('follow') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | : $self->pending_draw ? ('draw', 'close', 'claim') | ||||||||||||||||||||||||||||||||||||||||||
| 224 | : ('lead', 'marriage', 'exchange', 'close', 'claim'); | ||||||||||||||||||||||||||||||||||||||||||
| 225 | return Game::Schnapsen::Error->new_code('not_legal') | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 93044 | ▶ | unless grep { $_ eq $kind } @allowed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 93040 | my $handler = $HANDLER{$kind}; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 93040 | my @out = $self->$handler($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 93040 | ▶ | return $out[0] if @out == 1 && ref $out[0] eq 'Game::Schnapsen::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@out == 1 and ref $out[0] eq "Game::Schnapsen::Error"
MC/DC100%2/2
@out == 1 and ref $out[0] eq "Game::Schnapsen::Error"
@out == 1
ref $out[0] eq "Game::Schnapsen::Error"
Truth table100%3/3
A and B
A= @out == 1B= ref $out[0] eq "Game::Schnapsen::Error"
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 93020 | ▶ | $self->history([ @{ $self->history || [] }, @out ]); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->history || []
MC/DC0%0/1
$self->history || []
$self->history
Truth table50%1/2
A
A= $self->history
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 93020 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 74533 | ▶ | sub _held { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_held: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 74533 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 74533 | my $card = $move->{card}; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 74533 | ▶ | return Game::Schnapsen::Error->new_code('not_held') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $card and $card =~ /\A[1-9][0-9]*\z/ and $self->hand_of($seat)->has_card($card)
defined $card and $card =~ /\A[1-9][0-9]*\z/
MC/DC66%2/3
defined $card and $card =~ /\A[1-9][0-9]*\z/ and $self->hand_of($seat)->has_card($card)
defined $card
$card =~ /\A[1-9][0-9]*\z/
$self->hand_of($seat)->has_card($card)
Truth table75%3/4
A and B and C
A= defined $cardB= $card =~ /\A[1-9][0-9]*\z/C= $self->hand_of($seat)->has_card($card)
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | unless defined $card && $card =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||
| 241 | && $self->hand_of($seat)->has_card($card); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 74525 | return $card; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 37286 | ▶ | sub _lead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lead: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 37286 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 37286 | my $card = $self->_held($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 37286 | ▶ | return $card if ref $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 37282 | ▶ | if (my $must = $self->must_lead) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | return Game::Schnapsen::Error->new_code('must_lead') | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 2772 | ▶ | unless grep { $_ == $card } @$must; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 37281 | $self->hand_of($seat)->remove($card); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 37281 | $self->must_lead(undef); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 37281 | $self->leader($seat); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 37281 | $self->lead($card); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 37281 | $self->turn(other($seat)); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 37281 | return ({ kind => 'lead', seat => $seat, card => $card }); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 39586 | ▶ | sub _count_melds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_count_melds: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 39586 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 39586 | my $add = 0; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 39586 | for my $m (@{ $self->melds }) { | |||||||||||||||||||||||||||||||||||||||||
| 268 | 17800 | ▶ | next if $m->{counted} || $m->{seat} ne $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$m->{"counted"} or $m->{"seat"} ne $seat
MC/DC100%2/2
$m->{"counted"} or $m->{"seat"} ne $seat
$m->{"counted"}
$m->{"seat"} ne $seat
Truth table100%3/3
A or B
A= $m->{"counted"}B= $m->{"seat"} ne $seat
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 2997 | $m->{counted} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 2997 | $add += $m->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 39586 | ▶ | return 0 unless $add; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 2997 | my $taken = { %{ $self->taken } }; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 2997 | $taken->{$seat} += $add; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 2997 | $self->taken($taken); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 2997 | return $add; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 3017 | ▶ | sub _marriage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_marriage: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 3017 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 3017 | ▶ | my $suit = ref $move eq 'HASH' ? $move->{suit} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 3017 | ▶ | return Game::Schnapsen::Error->new_code('no_marriage') unless defined $suit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 3017 | my ($m) = grep { $_->{suit} eq $suit } @{ $self->can_marry($seat) }; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 3017 | ▶ | return Game::Schnapsen::Error->new_code('no_marriage') unless $m; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 3012 | $self->melds([ @{ $self->melds }, | |||||||||||||||||||||||||||||||||||||||||
| 288 | 3012 | { seat => $seat, suit => $suit, value => $m->{value}, counted => 0 } ]); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 3012 | ▶ | $self->_count_melds($seat) if $self->tricks_won($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 3012 | $self->must_lead([ $m->{king}, $m->{queen} ]); | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 3012 | return ({ kind => 'marriage', seat => $seat, suit => $suit, value => $m->{value} }); | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 1717 | ▶ | sub _exchange { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exchange: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 1717 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 1717 | my $card = $self->can_exchange($seat); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 1717 | ▶ | return Game::Schnapsen::Error->new_code('no_exchange') unless defined $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 1717 | $self->_swap_trump($seat, $card); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 1717 | return ({ kind => 'exchange', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 1741 | ▶ | sub _swap_trump { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_swap_trump: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 1741 | my ($self, $seat, $card) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 1741 | my $up = $self->turn_up; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 1741 | $self->hand_of($seat)->remove($card); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 1741 | $self->hand_of($seat)->add($up); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 1741 | $self->turn_up($card); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 1741 | return; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 1012 | ▶ | sub _close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 1012 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 1012 | ▶ | return Game::Schnapsen::Error->new_code('cannot_close') unless $self->can_close($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | $self->close_state({ | ||||||||||||||||||||||||||||||||||||||||||
| 317 | by => $seat, | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 1010 | map { ($_ => { tricks => $self->tricks_won($_), points => $self->points_of($_) }) } | |||||||||||||||||||||||||||||||||||||||||
| 319 | qw(p1 p2), | ||||||||||||||||||||||||||||||||||||||||||
| 320 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 1010 | $self->closed(1); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 1010 | $self->closed_by($seat); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 1010 | $self->drawn(1); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 1010 | my @out = ({ kind => 'close', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1010 | ▶ | if (Game::Schnapsen::Variant::exchange_on_close($self->_v) && defined $self->turn_up) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
Game::Schnapsen::Variant::exchange_on_close($self->_v) and defined $self->turn_up
MC/DC50%1/2
Game::Schnapsen::Variant::exchange_on_close($self->_v) and defined $self->turn_up
Game::Schnapsen::Variant::exchange_on_close($self->_v)
defined $self->turn_up
Truth table66%2/3
A and B
A= Game::Schnapsen::Variant::exchange_on_close($self->_v)B= defined $self->turn_up
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 679 | my $them = other($seat); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 679 | my $card = exchange_card($self->hand_of($them)->cards, $self->trump, | |||||||||||||||||||||||||||||||||||||||||
| 330 | Game::Schnapsen::Variant::exchange_rank($self->_v)); | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 679 | ▶ | if (defined $card) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 24 | $self->_swap_trump($them, $card); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 24 | push @out, { kind => 'exchange', seat => $them }; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1010 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 4223 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 4223 | my ($self, $how, $by) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 341 | my $r = deal_result( | ||||||||||||||||||||||||||||||||||||||||||
| 342 | variant => $self->variant, | ||||||||||||||||||||||||||||||||||||||||||
| 343 | how => $how, | ||||||||||||||||||||||||||||||||||||||||||
| 344 | by => $by, | ||||||||||||||||||||||||||||||||||||||||||
| 345 | points => { p1 => $self->points_of('p1'), p2 => $self->points_of('p2') }, | ||||||||||||||||||||||||||||||||||||||||||
| 346 | tricks => { p1 => $self->tricks_won('p1'), p2 => $self->tricks_won('p2') }, | ||||||||||||||||||||||||||||||||||||||||||
| 347 | closed_by => $self->closed_by, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | close_state => $self->close_state, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 4223 | ▶ | last_trick => ($self->last_trick ? $self->last_trick->{winner} : undef), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 4223 | $self->result($r); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 4223 | return { %$r, kind => 'deal_end' }; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 2481 | ▶ | sub _claim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_claim: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2481 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 2481 | ▶ | return Game::Schnapsen::Error->new_code('cannot_claim') unless $self->can_claim($seat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 2479 | return ({ kind => 'claim', seat => $seat }, $self->_finish('claim', $seat)); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 10280 | ▶ | sub _draw_move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_move: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 10280 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 10280 | $self->_draw_now; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 10280 | return ({ kind => 'draw', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 37247 | ▶ | sub _follow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_follow: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 37247 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 37247 | my $card = $self->_held($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 370 | 37247 | ▶ | return $card if ref $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 37243 | my $can = legal_follows($self->hand_of($seat)->cards, | |||||||||||||||||||||||||||||||||||||||||
| 373 | $self->lead, $self->trump, $self->phase); | ||||||||||||||||||||||||||||||||||||||||||
| 374 | return Game::Schnapsen::Error->new_code('must_follow') | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 37243 | ▶ | unless grep { $_ == $card } @$can; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 37241 | $self->hand_of($seat)->remove($card); | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 37241 | my $lead = $self->lead; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 37241 | my $leader = $self->leader; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 37241 | my $best = winner_of($lead, $card, $self->trump); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 37241 | ▶ | my $winner = $best == $lead ? $leader : $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 37241 | my $taken = { %{ $self->taken } }; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 37241 | $taken->{$winner} += value_of($lead, $card); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 37241 | $self->taken($taken); | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 37241 | $self->tricks([ @{ $self->tricks }, | |||||||||||||||||||||||||||||||||||||||||
| 389 | { leader => $leader, lead => $lead, follow => $card, | ||||||||||||||||||||||||||||||||||||||||||
| 390 | winner => $winner } ]); | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 37241 | $self->lead(undef); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 37241 | $self->leader($winner); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 37241 | $self->turn($winner); | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 37241 | $self->_count_melds($winner); | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 37241 | $self->drawn(1); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 37241 | ▶ | if ($self->draw_left) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 20642 | ▶ | if (Game::Schnapsen::Variant::close_before_draw($self->_v)) { $self->drawn(0) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 10172 | else { $self->_draw_now } | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 37241 | my @out = ({ kind => 'follow', seat => $seat, card => $card }, | |||||||||||||||||||||||||||||||||||||||||
| 405 | { kind => 'trick', winner => $winner }); | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 37241 | ▶ | push @out, $self->_finish('exhausted') if $self->cards_out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 37241 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 20452 | ▶ | sub _draw_now { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_now: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 20452 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 20452 | $self->drawn(1); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 20452 | ▶ | return unless $self->draw_left; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 20452 | my $winner = $self->leader; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 20452 | for my $seat ($winner, other($winner)) { | |||||||||||||||||||||||||||||||||||||||||
| 417 | 40904 | my $card; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 40904 | ▶ | if (@{ $self->talon }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 37869 | my @rest = @{ $self->talon }; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 37869 | $card = shift @rest; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 37869 | $self->talon(\@rest); | |||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | elsif (defined $self->turn_up) { | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 3035 | $card = $self->turn_up; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 3035 | $self->turn_up(undef); | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 40904 | ▶ | last unless defined $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 40904 | $self->hand_of($seat)->add($card); | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 20452 | return; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | __END__ | ||||||||||||||||||||||||||||||||||||||||||