| 1 | package Game::Durak; | ||||||||||||||||||||||||||||||||||||||||||
| 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::Durak::Card (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use Game::Durak::Deck qw(HAND_SIZE); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use Game::Durak::Bout (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use Game::Durak::Error (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 21 | ▶ | use Game::Durak::Rules qw(cap_for legal_attacks legal_beats forced closes); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 21 | ▶ | use Game::Durak::Result qw(out_seats result_for resign_for); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 21 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 21 | has seed => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 21 | has number => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 21 | has trump => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 21 | has trump_card => (is => 'rw', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 21 | has hands => (is => 'rw', isa => HashRef); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 21 | has talon => (is => 'rw', isa => ArrayRef); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 21 | has discard => (is => 'rw', isa => Int, default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 21 | has bout => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 21 | has six_owner => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 21 | has over => (is => 'rw', isa => Int, default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 21 | has result => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | has history => (is => 'rw', isa => ArrayRef, default => sub { [] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 664 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 664 | my ($class, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 664 | my $seed = $o{seed}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 664 | ▶ | return Game::Durak::Error->new_code('no_seed') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $seed and length $seed == 32
MC/DC100%2/2
defined $seed and length $seed == 32
defined $seed
length $seed == 32
Truth table100%3/3
A and B
A= defined $seedB= length $seed == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | unless defined $seed && length $seed == 32; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 662 | ▶ | my $number = defined $o{number} ? $o{number} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 662 | ▶ | return Game::Durak::Error->new_code('bad_deal') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | unless $number =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 661 | ▶ | my $seats = defined $o{seats} ? $o{seats} : Game::Durak::Deck::SEATS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 661 | ▶ | return Game::Durak::Error->new_code('bad_seats') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seats =~ /\A[0-9]+\z/ and $seats == 2
MC/DC50%1/2
$seats =~ /\A[0-9]+\z/ and $seats == 2
$seats =~ /\A[0-9]+\z/
$seats == 2
Truth table66%2/3
A and B
A= $seats =~ /\A[0-9]+\z/B= $seats == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | unless $seats =~ /\A[0-9]+\z/ && $seats == Game::Durak::Deck::SEATS; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 660 | my $deal = Game::Durak::Deck::deal_for($seed, $number, $seats); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 660 | my $six = Game::Durak::Card::six_of($deal->{trump}); | |||||||||||||||||||||||||||||||||||||||||
| 49 | my ($owner) = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 660 | scalar grep { $_ == $six } @{ $deal->{hands}{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 51 | } 1 .. $seats; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | seed => $seed, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | number => $number, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | trump => $deal->{trump}, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | trump_card => $deal->{trump_card}, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1320 | hands => { map { $_ => [ @{ $deal->{hands}{$_} } ] } 1 .. $seats }, | |||||||||||||||||||||||||||||||||||||||||
| 59 | 660 | talon => [ @{ $deal->{talon} } ], | |||||||||||||||||||||||||||||||||||||||||
| 60 | discard => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | bout => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | six_owner => $owner, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | over => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | result => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | history => [], | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 660 | $self->_open_bout($deal->{first}); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 660 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 15940 | ▶ | sub _other { return 3 - $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_other: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 189385 | ▶ | sub hand_of { return $_[0]->hands->{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hand_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 165132 | ▶ | sub count_of { return scalar @{ $_[0]->hands->{ $_[1] } } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 83344 | ▶ | sub talon_left { return scalar @{ $_[0]->talon } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
talon_left: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 17882 | ▶ | sub seats { return ( 1, 2 ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 63092 | ▶ | sub six_of_trumps { return Game::Durak::Card::six_of($_[0]->trump) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
six_of_trumps: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 9572 | ▶ | sub turn_up_left { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn_up_left: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 9572 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 9572 | my $up = $self->trump_card; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 9572 | ▶ | return scalar(grep { $_ == $up } @{ $self->talon }) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 101773 | ▶ | sub can_swap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_swap: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 101773 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 101773 | ▶ | return 0 if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 101772 | my $owner = $self->six_owner; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 101772 | ▶ | return 0 unless defined $owner && defined $seat && $owner == $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $owner and defined $seat and $owner == $seat
defined $owner and defined $seat
MC/DC66%2/3
defined $owner and defined $seat and $owner == $seat
defined $owner
defined $seat
$owner == $seat
Truth table75%3/4
A and B and C
A= defined $ownerB= defined $seatC= $owner == $seat
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 16527 | my $six = $self->six_of_trumps; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 16527 | ▶ | return 0 unless grep { $_ == $six } @{ $self->hand_of($seat) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 6894 | return $self->turn_up_left; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 345432 | ▶ | sub phase { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
phase: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 345432 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 345432 | ▶ | return 'over' if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 345226 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 345226 | ▶ | return 'over' unless $bout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 345226 | ▶ | return 'pile_on' if $bout->taken; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 306966 | ▶ | return 'defend' if defined $bout->unbeaten; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 178055 | return 'attack'; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 192051 | ▶ | sub turn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 192051 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 192051 | my $phase = $self->phase; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 192051 | ▶ | return undef if $phase eq 'over'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 191848 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 191848 | ▶ | return $phase eq 'defend' ? $bout->defender : $bout->attacker; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 42131 | ▶ | sub legal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legal: called CC=14 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 42131 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 42131 | ▶ | return [] if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 42126 | ▶ | return [] unless defined $seat && $seat =~ /\A[12]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $seat and $seat =~ /\A[12]\z/
MC/DC0%0/2
defined $seat and $seat =~ /\A[12]\z/
defined $seat
$seat =~ /\A[12]\z/
Truth table33%1/3
A and B
A= defined $seatB= $seat =~ /\A[12]\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 42126 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 42126 | ▶ | return [] unless defined $turn && $turn == $seat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $turn and $turn == $seat
MC/DC50%1/2
defined $turn and $turn == $seat
defined $turn
$turn == $seat
Truth table66%2/3
A and B
A= defined $turnB= $turn == $seat
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 42093 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 42093 | my $hand = $self->hand_of($seat); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 42093 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 42093 | my $swap = $self->can_swap($seat); | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 42093 | ▶ | if ($self->phase eq 'defend') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 15190 | my $beats = legal_beats($hand, $bout, $self->trump); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 15190 | push @out, map { { kind => 'beat', card => $_ } } @$beats; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 15190 | ▶ | push @out, { kind => 'take' } if @$beats || $swap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$beats or $swap
MC/DC0%0/2
@$beats or $swap
@$beats
$swap
Truth table66%2/3
A or B
A= @$beatsB= $swap
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 15190 | ▶ | push @out, { kind => 'swap' } if $swap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 15190 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 26903 | my $attacks = legal_attacks($hand, $bout); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 26903 | push @out, map { { kind => 'attack', card => $_ } } @$attacks; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 26903 | ▶ | push @out, { kind => 'done' } if $bout->size && (@$attacks || $swap); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$bout->size and @$attacks || $swap
@$attacks or $swap
MC/DC100%3/3
$bout->size and @$attacks || $swap
$bout->size
@$attacks
$swap
Truth table100%4/4
A and B or C
A= $bout->sizeB= @$attacksC= $swap
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 26903 | ▶ | push @out, { kind => 'swap' } if $swap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 26903 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2025 | ▶ | sub view { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2025 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 2025 | ▶ | die "Game::Durak: a view is for a seat\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $seat and $seat =~ /\A[12]\z/
MC/DC0%0/2
defined $seat and $seat =~ /\A[12]\z/
defined $seat
$seat =~ /\A[12]\z/
Truth table33%1/3
A and B
A= defined $seatB= $seat =~ /\A[12]\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | unless defined $seat && $seat =~ /\A[12]\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 2025 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | seat => $seat, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 2025 | ▶ | ply => scalar @{ $self->history }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | phase => $self->phase, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | turn => $self->turn, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | trump => $self->trump, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | trump_card => $self->turn_up_left ? $self->trump_card : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | talon => $self->talon_left, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | discard => $self->discard, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 2025 | hand => [ @{ $self->hand_of($seat) } ], | |||||||||||||||||||||||||||||||||||||||||
| 163 | 4050 | ▶ | counts => { map { $_ => $self->count_of($_) } $self->seats }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | swap => $self->can_swap($seat), | ||||||||||||||||||||||||||||||||||||||||||
| 165 | legal => $self->legal($seat), | ||||||||||||||||||||||||||||||||||||||||||
| 166 | over => $self->over, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | result => $self->result, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | bout => $bout ? { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | attacker => $bout->attacker, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | defender => $bout->defender, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | cap => $bout->cap, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | size => $bout->size, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | taken => $bout->taken, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | unbeaten => $bout->unbeaten, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | pairs => [ map { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 2025 | { attack => $bout->attacks->[$_], beat => $bout->beats->[$_] } | |||||||||||||||||||||||||||||||||||||||||
| 177 | } 0 .. $bout->size - 1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 21 | my %HANDLER = ( | |||||||||||||||||||||||||||||||||||||||||
| 183 | attack => '_attack', | ||||||||||||||||||||||||||||||||||||||||||
| 184 | beat => '_beat', | ||||||||||||||||||||||||||||||||||||||||||
| 185 | take => '_take', | ||||||||||||||||||||||||||||||||||||||||||
| 186 | done => '_done', | ||||||||||||||||||||||||||||||||||||||||||
| 187 | swap => '_swap', | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 21 | my %STAGE = ( | |||||||||||||||||||||||||||||||||||||||||
| 191 | attack => { attack => 1, pile_on => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | beat => { defend => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | take => { defend => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | done => { attack => 1, pile_on => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | swap => { attack => 1, pile_on => 1, defend => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | resign => { attack => 1, pile_on => 1, defend => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 43399 | ▶ | sub apply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 43399 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 43399 | ▶ | return Game::Durak::Error->new_code('game_over') if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 43395 | ▶ | return Game::Durak::Error->new_code('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $seat and $seat =~ /\A[12]\z/
MC/DC50%1/2
defined $seat and $seat =~ /\A[12]\z/
defined $seat
$seat =~ /\A[12]\z/
Truth table66%2/3
A and B
A= defined $seatB= $seat =~ /\A[12]\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | unless defined $seat && $seat =~ /\A[12]\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 43393 | ▶ | my $kind = ref $move eq 'HASH' && defined $move->{kind} ? $move->{kind} : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $move eq "HASH" and defined $move->{"kind"}
MC/DC50%1/2
ref $move eq "HASH" and defined $move->{"kind"}
ref $move eq "HASH"
defined $move->{"kind"}
Truth table66%2/3
A and B
A= ref $move eq "HASH"B= defined $move->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 43393 | ▶ | return Game::Durak::Error->new_code('not_legal') unless $STAGE{$kind}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 43390 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 43390 | ▶ | if ($kind eq 'resign') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | @out = $self->_resign($seat); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 43388 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 43388 | ▶ | return Game::Durak::Error->new_code('not_your_turn') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $turn and $turn == $seat
MC/DC50%1/2
defined $turn and $turn == $seat
defined $turn
$turn == $seat
Truth table66%2/3
A and B
A= defined $turnB= $turn == $seat
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | unless defined $turn && $turn == $seat; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | return Game::Durak::Error->new_code('wrong_phase') | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 43384 | ▶ | unless $STAGE{$kind}{ $self->phase }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 43381 | my $handler = $HANDLER{$kind}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 43381 | @out = $self->$handler($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 43381 | ▶ | return $out[0] if @out == 1 && ref $out[0] eq 'Game::Durak::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@out == 1 and ref $out[0] eq "Game::Durak::Error"
MC/DC100%2/2
@out == 1 and ref $out[0] eq "Game::Durak::Error"
@out == 1
ref $out[0] eq "Game::Durak::Error"
Truth table100%3/3
A and B
A= @out == 1B= ref $out[0] eq "Game::Durak::Error"
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 43369 | push @out, $self->_advance; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 43371 | $self->history([ @{ $self->history }, @out ]); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 43371 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 2063 | ▶ | sub is_move { return $STAGE{ defined $_[1] ? $_[1] : '' } ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_move: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 26 | ▶ | sub moves_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
moves_of: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 26 | my ($class, $events) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 26 | ▶ | return [ grep { $class->is_move($_->{kind}) && defined $_->{seat} } @$events ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$class->is_move($_->{'kind'}) && defined $_->{'seat'}
MC/DC50%1/2
$class->is_move($_->{'kind'}) && defined $_->{'seat'}
$class->is_move($_->{'kind'})
defined $_->{'seat'}
Truth table66%2/3
A && B
A= $class->is_move($_->{'kind'})B= defined $_->{'seat'}
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 30 | ▶ | sub replay { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replay: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 30 | my ($class, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 30 | my $moves = delete $o{moves}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 30 | ▶ | $moves = [] unless defined $moves; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 30 | my $game = $class->build(%o); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 30 | ▶ | return $game if ref $game eq 'Game::Durak::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 30 | my @events; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 30 | for my $move (@$moves) { | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1294 | my @out = $game->apply($move->{seat}, $move); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 1294 | ▶ | return $out[0] if ref $out[0] eq 'Game::Durak::Error'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1291 | push @events, @out; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 27 | return { game => $game, events => \@events }; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 33185 | ▶ | sub _held { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_held: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 33185 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 33185 | ▶ | my $card = ref $move eq 'HASH' ? $move->{card} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | return Game::Durak::Error->new_code('card_not_held') | ||||||||||||||||||||||||||||||||||||||||||
| 261 | unless defined $card && $card =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 33185 | ▶ | && grep { $_ == $card } @{ $self->hand_of($seat) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $card and $card =~ /\A[1-9][0-9]*\z/ and grep {$_ == $card;} @{$self->hand_of($seat);}
defined $card and $card =~ /\A[1-9][0-9]*\z/
MC/DC100%3/3
defined $card and $card =~ /\A[1-9][0-9]*\z/ and grep {$_ == $card;} @{$self->hand_of($seat);}
defined $card
$card =~ /\A[1-9][0-9]*\z/
grep {$_ == $card;} @{$self->hand_of($seat);}
Truth table100%4/4
A and B and C
A= defined $cardB= $card =~ /\A[1-9][0-9]*\z/C= grep {$_ == $card;} @{$self->hand_of($seat);}
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 33180 | return $card; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 22543 | ▶ | sub _attack { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attack: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 22543 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 22543 | my $card = $self->_held($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 22543 | ▶ | return $card if ref $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 22539 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 22539 | ▶ | return Game::Durak::Error->new_code('bout_full') if $bout->room < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 22538 | ▶ | if ($bout->size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | return Game::Durak::Error->new_code('rank_not_in_bout') | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 6670 | ▶ | unless $bout->ranks->{ Game::Durak::Card::rank_of($card) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 22536 | $self->_remove($seat, $card); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 22536 | $bout->add_attack($card); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 22536 | return ({ kind => 'attack', seat => $seat, card => $card }); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 10642 | ▶ | sub _beat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_beat: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 10642 | my ($self, $seat, $move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 10642 | my $card = $self->_held($seat, $move); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 10642 | ▶ | return $card if ref $card; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 10641 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 10641 | my $att = $bout->unbeaten; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 10641 | ▶ | die "Game::Durak: the defending stage with nothing to beat\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | unless defined $att; | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 10641 | ▶ | return Game::Durak::Error->new_code('beats_nothing') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | unless Game::Durak::Card::beats($card, $att, $self->trump); | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 10640 | $self->_remove($seat, $card); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 10640 | $bout->add_beat($card); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 10640 | return ({ kind => 'beat', seat => $seat, card => $card }); | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5009 | ▶ | sub _take { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 5009 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 5009 | $self->bout->taken(1); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 5009 | return ({ kind => 'take', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 4825 | ▶ | sub _done { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_done: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 4825 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 4825 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 4825 | ▶ | return Game::Durak::Error->new_code('must_attack') unless $bout->size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 4824 | ▶ | return ({ kind => 'done', seat => $seat }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | $self->_close_bout($bout->taken ? 'taken' : 'done')); | ||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 362 | ▶ | sub _swap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_swap: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 362 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 362 | my $six = $self->six_of_trumps; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 362 | my $owner = $self->six_owner; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | return Game::Durak::Error->new_code('not_the_six') | ||||||||||||||||||||||||||||||||||||||||||
| 323 | unless defined $owner && $owner == $seat | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 362 | ▶ | && grep { $_ == $six } @{ $self->hand_of($seat) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $owner and $owner == $seat and grep {$_ == $six;} @{$self->hand_of($seat);}
defined $owner and $owner == $seat
MC/DC33%1/3
defined $owner and $owner == $seat and grep {$_ == $six;} @{$self->hand_of($seat);}
defined $owner
$owner == $seat
grep {$_ == $six;} @{$self->hand_of($seat);}
Truth table50%2/4
A and B and C
A= defined $ownerB= $owner == $seatC= grep {$_ == $six;} @{$self->hand_of($seat);}
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 361 | ▶ | return Game::Durak::Error->new_code('talon_shut') unless $self->turn_up_left; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 360 | my $up = $self->trump_card; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 360 | my $talon = [ @{ $self->talon } ]; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 360 | ▶ | die "Game::Durak: the turn-up is not the last card of the talon\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$talon and $talon->[-1] == $up
MC/DC0%0/2
@$talon and $talon->[-1] == $up
@$talon
$talon->[-1] == $up
Truth table33%1/3
A and B
A= @$talonB= $talon->[-1] == $up
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | unless @$talon && $talon->[-1] == $up; | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 360 | $talon->[-1] = $six; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 360 | $self->talon($talon); | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 360 | $self->_remove($seat, $six); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 360 | $self->_give($seat, $up); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 360 | $self->trump_card($six); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 360 | $self->six_owner(undef); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 360 | return ({ kind => 'swap', seat => $seat }); | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | sub _resign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resign: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | my $result = resign_for($seat, [ $self->seats ]); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | $self->_finish($result); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | return ({ kind => 'resign', seat => $seat }, | |||||||||||||||||||||||||||||||||||||||||
| 349 | { kind => 'game_end', %$result }); | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 43369 | ▶ | sub _advance { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_advance: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 43369 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 43369 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 43369 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 357 | 58683 | ▶ | last if $self->over; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 58108 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 58108 | ▶ | last unless $bout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 58108 | ▶ | if ($bout->taken) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 11954 | ▶ | last unless $bout->room < 1 || $self->_forced($bout->attacker); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$bout->room < 1 or $self->_forced($bout->attacker)
MC/DC100%2/2
$bout->room < 1 or $self->_forced($bout->attacker)
$bout->room < 1
$self->_forced($bout->attacker)
Truth table100%3/3
A or B
A= $bout->room < 1B= $self->_forced($bout->attacker)
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 7016 | push @out, $self->_close_bout('taken'); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 7016 | next; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 46154 | my $how = closes($bout, $self->count_of($bout->defender)); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 46154 | ▶ | if ($how) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 71 | push @out, $self->_close_bout($how); | |||||||||||||||||||||||||||||||||||||||||
| 370 | 71 | next; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 46083 | my $turn = $self->turn; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 46083 | ▶ | last unless $self->_forced($turn); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 8227 | ▶ | if ($self->phase eq 'defend') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 4283 | $bout->taken(1); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 4283 | next; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 3944 | ▶ | last unless $bout->size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 3944 | push @out, $self->_close_bout('exhausted'); | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 43369 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 57643 | ▶ | sub _forced { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_forced: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 57643 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 57643 | return forced($self->hand_of($seat), $self->bout, $self->trump, | |||||||||||||||||||||||||||||||||||||||||
| 391 | $self->phase, $self->can_swap($seat)); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 15855 | ▶ | sub _close_bout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_bout: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 15855 | my ($self, $how) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 15855 | my $bout = $self->bout; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 15855 | my @cards = $bout->cards; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 15855 | ▶ | my $taken = $bout->taken ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 15855 | my $attacker = $bout->attacker; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 15855 | my $defender = $bout->defender; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 15855 | ▶ | my $next = $taken ? $attacker : $defender; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 15855 | ▶ | if ($taken) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 9292 | my $hands = { %{ $self->hands } }; | |||||||||||||||||||||||||||||||||||||||||
| 406 | $hands->{$defender} = | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 9292 | [ sort { $a <=> $b } @{ $hands->{$defender} }, @cards ]; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 9292 | $self->hands($hands); | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 9292 | my $six = $self->six_of_trumps; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 9292 | my $owner = $self->six_owner; | |||||||||||||||||||||||||||||||||||||||||
| 412 | $self->six_owner(undef) | ||||||||||||||||||||||||||||||||||||||||||
| 413 | if defined $owner && $owner != $defender | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 9292 | ▶ | && grep { $_ == $six } @cards; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $owner and $owner != $defender and grep {$_ == $six;} @cards
defined $owner and $owner != $defender
MC/DC100%3/3
defined $owner and $owner != $defender and grep {$_ == $six;} @cards
defined $owner
$owner != $defender
grep {$_ == $six;} @cards
Truth table100%4/4
A and B and C
A= defined $ownerB= $owner != $defenderC= grep {$_ == $six;} @cards
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 6563 | $self->discard($self->discard + scalar @cards); | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 15855 | my $event = { | |||||||||||||||||||||||||||||||||||||||||
| 421 | kind => 'bout_end', | ||||||||||||||||||||||||||||||||||||||||||
| 422 | taken => $taken, | ||||||||||||||||||||||||||||||||||||||||||
| 423 | how => $how, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | cards => scalar @cards, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | discard => $self->discard, | ||||||||||||||||||||||||||||||||||||||||||
| 426 | next_attacker => $next, | ||||||||||||||||||||||||||||||||||||||||||
| 427 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 15855 | $self->bout(undef); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 15855 | return ($event, $self->_refill($attacker, $defender), | |||||||||||||||||||||||||||||||||||||||||
| 431 | $self->_after_bout($next)); | ||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 15855 | ▶ | sub _refill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refill: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 15855 | my ($self, $first, $second) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 15855 | my %drawn = (1 => 0, 2 => 0); | |||||||||||||||||||||||||||||||||||||||||
| 437 | 15855 | $drawn{$_} = $self->_draw_to($_) for $first, $second; | |||||||||||||||||||||||||||||||||||||||||
| 438 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 15855 | kind => 'refill', | |||||||||||||||||||||||||||||||||||||||||
| 440 | drawn => \%drawn, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | talon => $self->talon_left, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 31710 | ▶ | sub _draw_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_to: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 31710 | my ($self, $seat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 31710 | my $talon = [ @{ $self->talon } ]; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 31710 | my $six = $self->six_of_trumps; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 31710 | my $drawn = 0; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 31710 | ▶ | while (@$talon && $self->count_of($seat) < HAND_SIZE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$talon and $self->count_of($seat) < 6
MC/DC100%2/2
@$talon and $self->count_of($seat) < 6
@$talon
$self->count_of($seat) < 6
Truth table100%3/3
A and B
A= @$talonB= $self->count_of($seat) < 6
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 13580 | my $card = shift @$talon; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 13580 | $self->_give($seat, $card); | |||||||||||||||||||||||||||||||||||||||||
| 455 | 13580 | ▶ | $self->six_owner($seat) if $card == $six; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 13580 | $drawn++; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 31710 | $self->talon($talon); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 31710 | return $drawn; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 15855 | ▶ | sub _after_bout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_after_bout: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 15855 | my ($self, $next) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 15855 | my $counts = { map { $_ => $self->count_of($_) } $self->seats }; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 15855 | my $result = result_for($counts, $self->talon_left); | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 15855 | ▶ | unless ($result) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 15280 | $self->_open_bout($next); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 15280 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 575 | my @out = map { { kind => 'out', seat => $_ } } | |||||||||||||||||||||||||||||||||||||||||
| 475 | out_seats($counts, $self->talon_left); | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 575 | $self->_finish($result); | |||||||||||||||||||||||||||||||||||||||||
| 478 | 575 | return (@out, { kind => 'game_end', %$result }); | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 577 | ▶ | sub _finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 577 | my ($self, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 577 | ▶ | die "Game::Durak: the deal has a result already\n" if $self->result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 577 | $self->result($result); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 577 | $self->over(1); | |||||||||||||||||||||||||||||||||||||||||
| 486 | 577 | return; | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 15940 | ▶ | sub _open_bout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_bout: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 15940 | my ($self, $attacker) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 15940 | my $defender = _other($attacker); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 15940 | $self->bout(Game::Durak::Bout->build( | |||||||||||||||||||||||||||||||||||||||||
| 493 | attacker => $attacker, | ||||||||||||||||||||||||||||||||||||||||||
| 494 | defender => $defender, | ||||||||||||||||||||||||||||||||||||||||||
| 495 | cap => cap_for($self->count_of($defender)), | ||||||||||||||||||||||||||||||||||||||||||
| 496 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 15940 | return; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 13940 | ▶ | sub _give { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_give: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 13940 | my ($self, $seat, @cards) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 13940 | my $hands = { %{ $self->hands } }; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 13940 | $hands->{$seat} = [ sort { $a <=> $b } @{ $hands->{$seat} }, @cards ]; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 13940 | $self->hands($hands); | |||||||||||||||||||||||||||||||||||||||||
| 505 | 13940 | return; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 33536 | ▶ | sub _remove { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 33536 | my ($self, $seat, $card) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 33536 | my $hands = { %{ $self->hands } }; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 33536 | my $gone = 0; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 33536 | my @left; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 33536 | for my $id (@{ $hands->{$seat} }) { | |||||||||||||||||||||||||||||||||||||||||
| 514 | 221834 | ▶ | if (!$gone && $id == $card) { $gone = 1; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $gone and $id == $card
MC/DC100%2/2
not $gone and $id == $card
not $gone
$id == $card
Truth table100%3/3
not(A) and B
A= not $goneB= $id == $card
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 188298 | push @left, $id; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 33536 | $hands->{$seat} = \@left; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 33536 | $self->hands($hands); | |||||||||||||||||||||||||||||||||||||||||
| 519 | 33536 | return $gone; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | __END__ | ||||||||||||||||||||||||||||||||||||||||||