blib/lib/Game/Senet.pm

filter: Statementstmt 97.8% 365 / 373 Branchbran 82.5% 198 / 240 Conditioncond 68.2% 73 / 107 MC/DCmcdc 51.6% 32 / 62 Subroutinesub 100% 54 / 54 Podpod 97.1% 34 / 35 totaltotal 86.8% 756 / 871 CC 164 SCAR 29.3
CC
164
Cov
88%
_why_not
45.3
replay
35.5
from_text
28.3
CRAP 18.8
« blib/lib/Game/Senet/Notation.pm ↑ Summary blib/lib/Game/Senet/Terminal.pm »
1 package Game::Senet;
2  
3 83 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 83 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 83 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 83 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 83 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
9 83 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 83 ▶use Game::Senet::Engine qw(EMPTY LIGHT DARK SIDE_LIGHT SIDE_DARK piece_of);
Subroutine __ANON__: called CC=1 SCAR=0.0
12 83 ▶use Game::Senet::Rules;
Subroutine __ANON__: called CC=1 SCAR=0.0
13 83 ▶use Game::Senet::Variant;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 83 ▶use Game::Senet::Sticks ();
Subroutine __ANON__: called CC=1 SCAR=0.0
15 83 ▶use Game::Senet::Notation ();
Subroutine __ANON__: called CC=1 SCAR=0.0
16 83 ▶use Game::Senet::Error;
Subroutine __ANON__: called CC=1 SCAR=0.0
17 83 ▶use Game::Senet::Result;
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 83 our $VERSION = '0.03';
20  
21 83 my $E = 'Game::Senet::Engine';
22 83 my $X = 'Game::Senet::Error';
23  
24 83 my (%SIDE_OF, %OTHER, %SEATS);
25 83 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 83 %SIDE_OF = (light => SIDE_LIGHT, dark => SIDE_DARK);
27 83 %OTHER = (light => 'dark', dark => 'light', p1 => 'p2', p2 => 'p1');
28 83 %SEATS = (p1 => 1, p2 => 1);
29 }
30  
31 83 has _light_seat => (is => 'ro', init_arg => 'light', private => 1, default => 'p1');
32  
33 83 has _seed => (is => 'ro', init_arg => 'seed', private => 1);
34  
35 83 has _rules_given => (is => 'ro', init_arg => 'rules', private => 1);
36  
37 83 has _first_given => (is => 'ro', init_arg => 'first', private => 1);
38  
39 83 has _position_given => (is => 'ro', init_arg => 'position', private => 1);
40  
41 83 has _start => (is => 'rw', private => 1);
42  
43 83 has _script => (is => 'ro', init_arg => 'script', private => 1);
44  
45 83 has _variant => (is => 'rw', private => 1);
46  
47 83 has _game => (is => 'rw', private => 1);
48  
49 83 has _first => (is => 'rw', private => 1);
50  
51 83 has _throws => (is => 'rw', private => 1);
52  
53 83 has _roll => (is => 'rw', private => 1);
54  
55 83 has _sticks => (is => 'rw', private => 1);
56  
57 83 has _legal => (is => 'rw', private => 1);
58  
59 83 has _number => (is => 'rw', private => 1);
60  
61 83 has _log => (is => 'rw', private => 1);
62  
63 83 has _choices => (is => 'rw', private => 1);
64  
65 83 has _resigned => (is => 'rw', private => 1);
66  
67 83 has _error => (is => 'rw', private => 1);
68  
69 7193 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=27.1
Pod undocumented
70 7193 my ($self) = @_;
71 7193 my ($seed, $script) = ($self->_seed, $self->_script);
72 7193 ▶ Carp::croak('Game::Senet: a game wants a seed: some bytes that decide every throw of its sticks')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY" 1 7192 7193
Condition77%7/9
defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY"
l!l&&r!l&&!r
70391531
defined $seed and not ref $seed and length $seed
!ll&&!rl&&r
15407039
defined $seed and not ref $seed
!ll&&!rl&&r
15407039
MC/DC50%2/4
defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY"
defined $seed not ref $seed length $seed ref $script eq "ARRAY"
Truth table42%3/7
A and not(B) and C or D
A= defined $seedB= not ref $seedC= length $seedD= ref $script eq "ARRAY"
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
73 unless (defined $seed && !ref $seed && length $seed) || ref $script eq 'ARRAY';
74 Carp::croak("Game::Senet: light is played by seat 'p1' or 'p2'")
75 7192 ▶ unless defined $self->_light_seat && $SEATS{ $self->_light_seat };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_light_seat and $SEATS{$self->_light_seat} 1 7191 7192
Condition66%2/3
defined $self->_light_seat and $SEATS{$self->_light_seat}
!ll&&!rl&&r
017191
MC/DC50%1/2
defined $self->_light_seat and $SEATS{$self->_light_seat}
defined $self->_light_seat $SEATS{$self->_light_seat}
Truth table66%2/3
A and B
A= defined $self->_light_seatB= $SEATS{$self->_light_seat}
ABresult
0X0
100
111
76  
77 7191 my $variant = Game::Senet::Variant->of($self->_rules_given);
78 7191 $self->_variant($variant);
79  
80 7191 my $first = $self->_first_given;
81 Carp::croak("Game::Senet: first is 'light' or 'dark'")
82 7191 ▶ if defined $first && !exists $SIDE_OF{$first};
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and not exists $SIDE_OF{$first} 1 7190 7191
Condition100%3/3
defined $first and not exists $SIDE_OF{$first}
!ll&&!rl&&r
144257481
MC/DC100%2/2
defined $first and not exists $SIDE_OF{$first}
defined $first not exists $SIDE_OF{$first}
Truth table100%3/3
A and not(B)
A= defined $firstB= not exists $SIDE_OF{$first}
ABresult
0X0
100
111
83  
84 7190 my $position = $self->_position_given;
85 7190 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) 149 7041 7190
86 149 my $code = Game::Senet::Notation::validate_position($position);
87 149 ▶ Carp::croak("Game::Senet: the position was refused, code $code") if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 149 149
88 149 my ($pieces) = $position =~ / (\d)\z/;
89 149 ▶ Carp::croak("Game::Senet: the position has $pieces pieces a side and the rules " . $variant->pieces)
Branch: 1 branch
BranchTrueFalseTotal
unless $pieces == $variant->pieces 1 148 149
90 unless $pieces == $variant->pieces;
91 148 ▶ $position =~ s/ [ld] (\d)\z/' ' . substr($first, 0, 1) . " $1"/e if defined $first;
Branch: 1 branch
BranchTrueFalseTotal
if defined $first 1 147 148
92 }
93 7189 $self->_start($position);
94  
95 7189 ▶ my $game = Game::Senet::Rules->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 148 7041 7189
Condition100%2/2
$first // "light"
l!l
57471294
MC/DC100%1/1
$first // "light"
$first
Truth table100%2/2
A
A= $first
Aresult
11
00
96 rules => $variant->as_hash,
97 (defined $position ? (position => $position) : (first => $first // 'light')),
98 );
99 7189 $self->_game($game);
100 7189 $self->_first($game->side);
101 7189 $self->_throws(0);
102 7189 $self->_log([]);
103 7189 $self->_choices([]);
104 7189 $self->_settle;
105 7189 return;
106 }
107  
108 775117 ▶sub _next_throw {
Subroutine _next_throw: called CC=5 SCAR=16.1
109 775117 my ($self, $number) = @_;
110 775117 ▶ if (my $script = $self->_script) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = $self->_script) 10387 764730 775117
111 10387 my $next = $script->[$number];
112 10387 ▶ return unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 206 10181 10387
113 10181 ▶ return (ref $next ? $next->{roll} : $next, ref $next ? $next->{sticks} : undef);
Branch: 2 branches
BranchTrueFalseTotal
ref $next ? : 1 10180 10181
ref $next ? : 1 10180 10181
114 }
115 764730 my $sticks = Game::Senet::Sticks::throw_for($self->_seed, $number);
116 764730 return (Game::Senet::Sticks::roll_of(Game::Senet::Sticks::light_of($sticks)), join '', @$sticks);
117 }
118  
119 755407 ▶sub _settle {
Subroutine _settle: called CC=5 SCAR=16.1
120 755407 my ($self) = @_;
121 755407 my $game = $self->_game;
122 755407 $self->_roll(undef);
123 755407 $self->_sticks(undef);
124 755407 $self->_number(undef);
125 755407 $self->_legal([]);
126  
127 755407 ▶ while (!$self->is_over) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_over) 775117 1770 776887
128 775117 my $number = $self->_throws;
129 775117 my ($roll, $sticks) = $self->_next_throw($number);
130 775117 ▶ return unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 206 774911 775117
131 774911 $self->_throws($number + 1);
132  
133 774911 my @moves = $game->moves($roll);
134 774911 ▶ if (@moves) {
Branch: 1 branch
BranchTrueFalseTotal
if (@moves) 753431 21480 774911
135 753431 $self->_legal(\@moves);
136 753431 $self->_roll($roll);
137 753431 $self->_sticks($sticks);
138 753431 $self->_number($number);
139 753431 return;
140 }
141  
142 21480 my $side = $game->side;
143 21480 my $ply = $game->ply;
144 21480 $game->forfeit($roll);
145 21480 ▶ push @{ $self->_log }, {
Branch: 1 branch
BranchTrueFalseTotal
$game->side eq $side ? : 14434 7046 21480
146 ply => $ply, side => $side, throw => $number, roll => $roll, sticks => $sticks,
147 move => undef, again => ($game->side eq $side ? 1 : 0),
148 };
149 }
150 1770 return;
151 }
152  
153 85634 ▶sub _refuse {
Subroutine _refuse: called CC=1 SCAR=0.0
154 85634 my ($self, $code, %detail) = @_;
155 85634 $self->_error($X->of($code, %detail));
156 85634 return undef;
157 }
158  
159 78735 ▶sub _why_not {
Subroutine _why_not: called CC=44 SCAR=38.1
160 78735 my ($self, $from, $to) = @_;
161 78735 my $game = $self->_game;
162 78735 my $variant = $self->_variant;
163 78735 my $board = $game->board;
164 78735 my $roll = $self->_roll;
165 78735 my $side = $SIDE_OF{ $game->side };
166 78735 my $me = piece_of($side);
167 78735 ▶ my $enemy = piece_of($side == SIDE_LIGHT ? SIDE_DARK : SIDE_LIGHT);
Branch: 1 branch
BranchTrueFalseTotal
$side == 0 ? : 43860 34875 78735
168 78735 my $rules = $E->rules($variant->as_hash);
169 78735 my @legal = $game->moves($roll);
170  
171 78735 my $piece = $board->at($from);
172 78735 ▶ return 'no_piece' if $piece == EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if $piece == 0 62803 15932 78735
173 15932 ▶ return 'not_your_piece' if $piece != $me;
Branch: 1 branch
BranchTrueFalseTotal
if $piece != $me 8342 7590 15932
174 7590 ▶ return 'bound_piece' if $game->only && $from != $game->only;
Branch: 1 branch
BranchTrueFalseTotal
if $game->only and $from != $game->only 10 7580 7590
Condition66%2/3
$game->only and $from != $game->only
!ll&&!rl&&r
7580010
MC/DC50%1/2
$game->only and $from != $game->only
$game->only $from != $game->only
Truth table66%2/3
A and B
A= $game->onlyB= $from != $game->only
ABresult
0X0
100
111
175  
176 7580 ▶ if ($from >= 26) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from >= 26) 1211 6369 7580
177 1211 my @chain = @{ $rules->{exits}{$from}{$roll} };
178 1211 ▶ return 'no_back' if $to ne 'off' && $to == $from - $roll;
Branch: 1 branch
BranchTrueFalseTotal
if $to ne "off" and $to == $from - $roll 42 1169 1211
Condition100%3/3
$to ne "off" and $to == $from - $roll
!ll&&!rl&&r
27114242
MC/DC100%2/2
$to ne "off" and $to == $from - $roll
$to ne "off" $to == $from - $roll
Truth table100%3/3
A and B
A= $to ne "off"B= $to == $from - $roll
ABresult
0X0
100
111
179 1169 ▶ return 'no_exit' if !@chain || $chain[0] eq 'stay';
Branch: 1 branch
BranchTrueFalseTotal
if not @chain or $chain[0] eq "stay" 494 675 1169
Condition66%2/3
not @chain or $chain[0] eq "stay"
l!l&&r!l&&!r
4940675
MC/DC50%1/2
not @chain or $chain[0] eq "stay"
not @chain $chain[0] eq "stay"
Truth table66%2/3
not(A) or B
A= not @chainB= $chain[0] eq "stay"
ABresult
1X1
011
000
180 675 my %target;
181 675 for my $entry (@chain) {
182 675 ▶ if ($entry eq 'off') { $target{off} = 1 }
Branch: 3 branches
BranchTrueFalseTotal
if ($entry eq 'off') { } 392 283 675
elsif ($entry eq 'walk') { } 113 170 283
elsif ($entry ne 'stay') { } 170 0 170
183 113 elsif ($entry eq 'walk') { $target{$_} = 1 for 1 .. 15 }
184 170 elsif ($entry ne 'stay') { $target{$entry} = 1 }
185 }
186 675 ▶ return 'wrong_distance' unless $target{$to};
Branch: 1 branch
BranchTrueFalseTotal
unless $target{$to} 616 59 675
187 59 ▶ return 'no_exit' unless grep { $_->from == $from } @legal;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->from == $from;} @legal 2 57 59
188 57 ▶ return 'own_piece' if $to ne 'off' && $board->at($to) == $me;
Branch: 1 branch
BranchTrueFalseTotal
if $to ne "off" and $board->at($to) == $me 7 50 57
Condition66%2/3
$to ne "off" and $board->at($to) == $me
!ll&&!rl&&r
0507
MC/DC50%1/2
$to ne "off" and $board->at($to) == $me
$to ne "off" $board->at($to) == $me
Truth table66%2/3
A and B
A= $to ne "off"B= $board->at($to) == $me
ABresult
0X0
100
111
189 50 ▶ return 'safe_house' if $to ne 'off' && $board->at($to) == $enemy;
Branch: 1 branch
BranchTrueFalseTotal
if $to ne "off" and $board->at($to) == $enemy 7 43 50
Condition66%2/3
$to ne "off" and $board->at($to) == $enemy
!ll&&!rl&&r
0437
MC/DC50%1/2
$to ne "off" and $board->at($to) == $enemy
$to ne "off" $board->at($to) == $enemy
Truth table66%2/3
A and B
A= $to ne "off"B= $board->at($to) == $enemy
ABresult
0X0
100
111
190 43 return 'wrong_distance';
191 }
192  
193 6369 ▶ my $any = $variant->reach26 eq 'any' && $from == 25;
Condition100%3/3
$variant->reach26 eq 'any' && $from == 25
!ll&&!rl&&r
32642931174
MC/DC100%2/2
$variant->reach26 eq 'any' && $from == 25
$variant->reach26 eq 'any' $from == 25
Truth table100%3/3
A && B
A= $variant->reach26 eq 'any'B= $from == 25
ABresult
0X0
100
111
194 6369 my $forward = $from + $roll;
195 6369 my $back = $from - $roll;
196 6369 ▶ return 'wrong_distance' if $to eq 'off';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "off" 196 6173 6369
197 6173 my $is_back = $to == $back;
198 6173 ▶ return 'wrong_distance' unless $to == $forward || $is_back || ($any && $to == 26);
Branch: 1 branch
BranchTrueFalseTotal
unless $to == $forward or $is_back or $any and $to == 26 5955 218 6173
Condition77%7/9
$to == $forward or $is_back or $any and $to == 26
l!l&&r!l&&!r
21805955
$to == $forward or $is_back
l!l&&r!l&&!r
471715955
$any and $to == 26
!ll&&!rl&&r
57971580
MC/DC50%2/4
$to == $forward or $is_back or $any and $to == 26
$to == $forward $is_back $any $to == 26
Truth table80%4/5
A or B or C and D
A= $to == $forwardB= $is_backC= $anyD= $to == 26
ABCDresult
1XXX1
01XX1
00111
000X0
00100
199  
200 218 ▶ if ($is_back) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_back) { } 171 47 218
elsif ($to > 26) { } 15 32 47
201 171 ▶ return 'forward_first' if grep { !$_->back } @legal;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $_->back;} @legal 170 1 171
202 1 ▶ return 'no_back' unless $variant->backward;
Branch: 1 branch
BranchTrueFalseTotal
unless $variant->backward 0 1 1
203 }
204 elsif ($to > 26) {
205 15 return 'must_land_26';
206 }
207  
208 33 ▶ my ($lo, $hi) = $from < $to ? ($from, $to) : ($to, $from);
Branch: 1 branch
BranchTrueFalseTotal
$from < $to ? : 32 1 33
209 33 ▶ if ($variant->blockade) {
Branch: 1 branch
BranchTrueFalseTotal
if ($variant->blockade) 33 0 33
210 33 for my $x ($lo + 1 .. $hi - 1) {
211 69 ▶ next unless $board->at($x) == $enemy;
Branch: 1 branch
BranchTrueFalseTotal
unless $board->at($x) == $enemy 50 19 69
212 19 my ($first, $last) = ($x, $x);
213 19 ▶ $first-- while $first > 1 && $board->at($first - 1) == $enemy;
Branch: 1 branch
BranchTrueFalseTotal
$first > 1 and $board->at($first - 1) == $enemy and do { --$first } 1 19 20
Condition66%2/3
$first > 1 and $board->at($first - 1) == $enemy
!ll&&!rl&&r
0191
MC/DC50%1/2
$first > 1 and $board->at($first - 1) == $enemy
$first > 1 $board->at($first - 1) == $enemy
Truth table66%2/3
A and B
A= $first > 1B= $board->at($first - 1) == $enemy
ABresult
0X0
100
111
214 19 ▶ $last++ while $last < 30 && $board->at($last + 1) == $enemy;
Branch: 1 branch
BranchTrueFalseTotal
$last < 30 and $board->at($last + 1) == $enemy and do { ++$last } 12 19 31
Condition66%2/3
$last < 30 and $board->at($last + 1) == $enemy
!ll&&!rl&&r
01912
MC/DC50%1/2
$last < 30 and $board->at($last + 1) == $enemy
$last < 30 $board->at($last + 1) == $enemy
Truth table66%2/3
A and B
A= $last < 30B= $board->at($last + 1) == $enemy
ABresult
0X0
100
111
215 19 ▶ return 'blockade' if $last - $first + 1 >= $variant->blockade;
Branch: 1 branch
BranchTrueFalseTotal
if $last - $first + 1 >= $variant->blockade 9 10 19
216 }
217 }
218 24 my $there = $board->at($to);
219 24 ▶ return 'own_piece' if $there == $me;
Branch: 1 branch
BranchTrueFalseTotal
if $there == $me 20 4 24
220 4 ▶ if ($there == $enemy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($there == $enemy) 4 0 4
221 4 ▶ return 'safe_house' if grep { $_ == $to } @{ $rules->{safe} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $to;} @{$$rules{"safe"};} 3 1 4
222 1 return 'protected';
223 }
224 0 return 'bad_move';
225 }
226  
227 833852 ▶sub play {
Subroutine play: called CC=14 SCAR=26.4
Pod documented
228 833852 my ($self, $what) = @_;
229 833852 $self->_error(undef);
230 833852 ▶ return $self->_refuse('game_over') if $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_over 1 833851 833852
231  
232 833851 my ($from, $to);
233 833851 ▶ my $object = Scalar::Util::blessed($what) && $what->isa('Game::Senet::Move');
Condition66%2/3
builtin::blessed($what) && $what->isa('Game::Senet::Move')
!ll&&!rl&&r
6174890216362
MC/DC50%1/2
builtin::blessed($what) && $what->isa('Game::Senet::Move')
builtin::blessed($what) $what->isa('Game::Senet::Move')
Truth table66%2/3
A && B
A= builtin::blessed($what)B= $what->isa('Game::Senet::Move')
ABresult
0X0
100
111
234 833851 ▶ if ($object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object) { } 216362 617489 833851
235 216362 ▶ ($from, $to) = ($what->from, $what->off ? 'off' : $what->to);
Branch: 1 branch
BranchTrueFalseTotal
$what->off ? : 10804 205558 216362
236 }
237 else {
238 617489 my ($parsed, $why) = Game::Senet::Notation::parse_move($what);
239 617489 ▶ return $self->_refuse('bad_move', text => $what, why => $why) unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 6897 610592 617489
240 610592 ($from, $to) = @{$parsed}{qw(from to)};
241 }
242 826954 ▶ return $self->_refuse('no_roll') unless defined $self->_roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_roll 1 826953 826954
243  
244 826953 my $game = $self->_game;
245 826953 my $roll = $self->_roll;
246 826953 my $wire = $from . '-' . $to;
247 826953 my ($move) = grep { Game::Senet::Notation::format_move($_) eq $wire } @{ $self->_legal };
248 826953 ▶ $move = undef if $move && $object && ($what->roll != $roll || $what->side ne $game->side);
Branch: 1 branch
BranchTrueFalseTotal
if $move and $object and $what->roll != $roll || $what->side ne $game->side 1 826952 826953
Condition88%8/9
$move and $object and $what->roll != $roll || $what->side ne $game->side
!ll&&!rl&&r
6105912163611
$move and $object
!ll&&!rl&&r
78734531857216362
$what->roll != $roll or $what->side ne $game->side
l!l&&r!l&&!r
10216361
MC/DC75%3/4
$move and $object and $what->roll != $roll || $what->side ne $game->side
$move $object $what->roll != $roll $what->side ne $game->side
Truth table80%4/5
A and B and C or D
A= $moveB= $objectC= $what->roll != $rollD= $what->side ne $game->side
ABCDresult
0XXX0
10XX0
11000
111X1
11011
249 826953 ▶ return $self->_refuse($self->_why_not($from, $to), from => $from, to => $to, roll => $roll)
Branch: 1 branch
BranchTrueFalseTotal
unless $move 78735 748218 826953
250 unless $move;
251  
252 748218 push @{ $self->_choices }, {
253 748218 depth => $game->depth, log => scalar @{ $self->_log },
254 throws => $self->_throws, roll => $roll, sticks => $self->_sticks, number => $self->_number,
255 };
256 748218 my $side = $game->side;
257 748218 my $ply = $game->ply;
258 748218 $game->apply($move);
259 748218 ▶ push @{ $self->_log }, {
Branch: 1 branch
BranchTrueFalseTotal
!$game->is_over && $game->side eq $side ? : 300938 447280 748218
Condition100%3/3
not $game->is_over and $game->side eq $side
!ll&&!rl&&r
1769445511300938
MC/DC100%2/2
not $game->is_over and $game->side eq $side
not $game->is_over $game->side eq $side
Truth table100%3/3
not(A) and B
A= not $game->is_overB= $game->side eq $side
ABresult
0X0
100
111
260 ply => $ply, side => $side, throw => $self->_number, roll => $roll, sticks => $self->_sticks,
261 move => $wire, back => $move->back, swap => $move->swap, off => $move->off, walk => $move->walk,
262 again => (!$game->is_over && $game->side eq $side ? 1 : 0),
263 };
264 748218 $self->_settle;
265 748218 return $move;
266 }
267  
268 1071 ▶sub play_or_die {
Subroutine play_or_die: called CC=2 SCAR=8.4
Pod documented
269 1071 my ($self, $what) = @_;
270 1071 my $move = $self->play($what);
271 1071 ▶ return $move if $move;
Branch: 1 branch
BranchTrueFalseTotal
if $move 1071 0 1071
272 0 my $error = $self->_error;
273 0 Carp::croak('Game::Senet: ' . $error->code . ': ' . $error->message);
274 }
275  
276 578 ▶sub undo {
Subroutine undo: called CC=4 SCAR=14.0
Pod documented
277 578 my ($self) = @_;
278 578 $self->_error(undef);
279 578 ▶ if (defined $self->_resigned) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_resigned) 0 578 578
280 0 $self->_resigned(undef);
281 0 return 1;
282 }
283 578 ▶ my $choice = pop @{ $self->_choices } or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $choice = pop @{$self->_choices;} or return 0 577 1 578
284 577 my $game = $self->_game;
285 577 ▶ $game->undo while $game->depth > $choice->{depth};
Branch: 1 branch
BranchTrueFalseTotal
$game->depth > $choice->{"depth"} and do { $game->undo } 584 577 1161
286 577 splice @{ $self->_log }, $choice->{log};
287 577 $self->_throws($choice->{throws});
288 577 $self->_roll($choice->{roll});
289 577 $self->_sticks($choice->{sticks});
290 577 $self->_number($choice->{number});
291 577 $self->_legal([ $game->moves($choice->{roll}) ]);
292 577 return 1;
293 }
294  
295 8 ▶sub resign {
Subroutine resign: called CC=4 SCAR=14.0
Pod documented
296 8 my ($self, $side) = @_;
297 8 $self->_error(undef);
298 8 ▶ return 0 if $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_over 0 8 8
299 8 ▶ $side = $self->_game->side unless defined $side;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $side 4 4 8
300 8 ▶ Carp::croak("Game::Senet: a side is 'light' or 'dark'") unless exists $SIDE_OF{$side};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $SIDE_OF{$side} 0 8 8
301 8 $self->_resigned($side);
302 8 return 1;
303 }
304  
305 4945082 ▶sub is_over { defined $_[0]->_resigned || $_[0]->_game->is_over ? 1 : 0 }
Subroutine is_over: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->_resigned || $_[0]->_game->is_over ? : 5022 4940060 4945082
Condition100%3/3
defined $_[0]->_resigned or $_[0]->_game->is_over
l!l&&r!l&&!r
850144940060
MC/DC100%2/2
defined $_[0]->_resigned or $_[0]->_game->is_over
defined $_[0]->_resigned $_[0]->_game->is_over
Truth table100%3/3
A or B
A= defined $_[0]->_resignedB= $_[0]->_game->is_over
ABresult
1X1
011
000
306  
307 10747 ▶sub result {
Subroutine result: called CC=4 SCAR=13.9
Pod documented
308 10747 my ($self) = @_;
309 10747 ▶ return undef unless $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_over 9332 1415 10747
310 1415 my $game = $self->_game;
311 1415 my $resigned = $self->_resigned;
312 return Game::Senet::Result->new(
313 1415 ▶ winner => (defined $resigned ? $OTHER{$resigned} : $game->winner),
Branch: 2 branches
BranchTrueFalseTotal
defined $resigned ? : 8 1407 1415
defined $resigned ? : 8 1407 1415
314 how => (defined $resigned ? 'resign' : $game->how),
315 final => $game->position,
316 home => { light => $game->home('light'), dark => $game->home('dark') },
317 plies => $game->ply,
318 throws => $self->_throws,
319 );
320 }
321  
322 78759 ▶sub error { $_[0]->_error }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
323  
324 551364 ▶sub side { $_[0]->is_over ? undef : $_[0]->_game->side }
Subroutine side: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_over ? : 0 551364 551364
325  
326 1579658 ▶sub roll { $_[0]->is_over ? undef : $_[0]->_roll }
Subroutine roll: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_over ? : 0 1579658 1579658
327  
328 92558 ▶sub sticks {
Subroutine sticks: called CC=3 SCAR=11.1
Pod documented
329 92558 my ($self) = @_;
330 92558 ▶ my $sticks = $self->is_over ? undef : $self->_sticks;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_over ? : 0 92558 92558
331 92558 ▶ return defined $sticks ? [ split //, $sticks ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $sticks ? : 20418 72140 92558
332 }
333  
334 9829 ▶sub throw {
Subroutine throw: called CC=3 SCAR=11.0
Pod documented
335 9829 my ($self) = @_;
336 9829 my $roll = $self->roll;
337 9829 ▶ return undef unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 0 9829 9829
338 9829 ▶ return $roll == 5 ? 0 : $roll;
Branch: 1 branch
BranchTrueFalseTotal
$roll == 5 ? : 618 9211 9829
339 }
340  
341 403441 ▶sub legal {
Subroutine legal: called CC=4 SCAR=14.6
Pod documented
342 403441 my ($self) = @_;
343 403441 ▶ return wantarray ? () : 0 unless defined $self->roll;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->roll 0 403441 403441
wantarray ? : 0 0 0
344 403441 my @legal = @{ $self->_legal };
345 403441 ▶ return wantarray ? @legal : scalar @legal;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 362435 41006 403441
346 }
347  
348 225359 ▶sub turn {
Subroutine turn: called CC=7 SCAR=19.5
Pod documented
349 225359 my ($self) = @_;
350 225359 ▶ return undef if $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_over 244 225115 225359
351 225115 my $side = $self->_game->side;
352 225115 my $segment = 1;
353 225115 for my $entry (reverse @{ $self->_log }) {
354 255057 ▶ last unless $entry->{side} eq $side && $entry->{again};
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"side"} eq $side and $entry->{"again"} 151525 103532 255057
Condition66%2/3
$entry->{"side"} eq $side and $entry->{"again"}
!ll&&!rl&&r
1515250103532
MC/DC50%1/2
$entry->{"side"} eq $side and $entry->{"again"}
$entry->{"side"} eq $side $entry->{"again"}
Truth table66%2/3
A and B
A= $entry->{"side"} eq $sideB= $entry->{"again"}
ABresult
0X0
100
111
355 103532 $segment++;
356 }
357 225115 my $roll = $self->_roll;
358 return {
359 225115 ▶ side => $side,
Branch: 1 branch
BranchTrueFalseTotal
defined $roll ? : 225112 3 225115
Condition100%2/2
$self->_game->only || undef
l!l
5479219636
MC/DC100%1/1
$self->_game->only || undef
$self->_game->only
Truth table100%2/2
A
A= $self->_game->only
Aresult
11
00
360 segment => $segment,
361 bound => ($self->_game->only || undef),
362 extra => (defined $roll ? Game::Senet::Sticks::extra_throw($roll) : undef),
363 };
364 }
365  
366 6900 ▶sub side_of {
Subroutine side_of: called CC=4 SCAR=14.9
Pod documented
367 6900 my ($self, $seat) = @_;
368 6900 ▶ Carp::croak("Game::Senet: a seat is 'p1' or 'p2'") unless defined $seat && $SEATS{$seat};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $SEATS{$seat} 0 6900 6900
Condition33%1/3
defined $seat and $SEATS{$seat}
!ll&&!rl&&r
006900
MC/DC0%0/2
defined $seat and $SEATS{$seat}
defined $seat $SEATS{$seat}
Truth table33%1/3
A and B
A= defined $seatB= $SEATS{$seat}
ABresult
0X0
100
111
369 6900 ▶ return $seat eq $self->_light_seat ? 'light' : 'dark';
Branch: 1 branch
BranchTrueFalseTotal
$seat eq $self->_light_seat ? : 6898 2 6900
370 }
371  
372 6899 ▶sub seat_of {
Subroutine seat_of: called CC=4 SCAR=14.9
Pod documented
373 6899 my ($self, $side) = @_;
374 6899 ▶ Carp::croak("Game::Senet: a side is 'light' or 'dark'") unless defined $side && exists $SIDE_OF{$side};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $side and exists $SIDE_OF{$side} 0 6899 6899
Condition33%1/3
defined $side and exists $SIDE_OF{$side}
!ll&&!rl&&r
006899
MC/DC0%0/2
defined $side and exists $SIDE_OF{$side}
defined $side exists $SIDE_OF{$side}
Truth table33%1/3
A and B
A= defined $sideB= exists $SIDE_OF{$side}
ABresult
0X0
100
111
375 6899 ▶ return $side eq 'light' ? $self->_light_seat : $OTHER{ $self->_light_seat };
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'light' ? : 2 6897 6899
376 }
377  
378 95589 ▶sub variant { $_[0]->_variant }
Subroutine variant: called CC=1 SCAR=0.0
Pod documented
379  
380 6897 ▶sub first { $_[0]->_first }
Subroutine first: called CC=1 SCAR=0.0
Pod documented
381  
382 6912 ▶sub seed { $_[0]->_seed }
Subroutine seed: called CC=1 SCAR=0.0
Pod documented
383  
384 90106 ▶sub throws { $_[0]->_throws }
Subroutine throws: called CC=1 SCAR=0.0
Pod documented
385  
386 90348 ▶sub ply { $_[0]->_game->ply }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
387  
388 88865 ▶sub position { $_[0]->_game->position }
Subroutine position: called CC=1 SCAR=0.0
Pod documented
389  
390 90159 ▶sub key { $_[0]->_game->key }
Subroutine key: called CC=1 SCAR=0.0
Pod documented
391  
392 12862 ▶sub home { $_[0]->_game->home($_[1]) }
Subroutine home: called CC=1 SCAR=0.0
Pod documented
393  
394 509070 ▶sub at {
Subroutine at: called CC=5 SCAR=16.8
Pod documented
395 509070 my ($self, $house) = @_;
396 509070 ▶ Carp::croak("Game::Senet: there is no house " . ($house // 'undef'))
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Notation::house_ok($house) 0 509070 509070
Condition0%0/2
$house // "undef"
l!l
00
MC/DC0%0/1
$house // "undef"
$house
Truth table0%0/2
A
A= $house
Aresult
11
00
397 unless Game::Senet::Notation::house_ok($house);
398 509070 my $piece = $self->_game->board->at($house);
399 509070 ▶ return $piece == EMPTY ? undef : $piece == LIGHT ? 'light' : 'dark';
Branch: 2 branches
BranchTrueFalseTotal
$piece == 0 ? : 361288 147782 509070
$piece == 1 ? : 71972 75810 147782
400 }
401  
402 2266 ▶sub protected {
Subroutine protected: called CC=3 SCAR=11.1
Pod documented
403 2266 my ($self, $house) = @_;
404 2266 ▶ Carp::croak("Game::Senet: there is no house " . ($house // 'undef'))
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Notation::house_ok($house) 1 2265 2266
Condition50%1/2
$house // "undef"
l!l
10
MC/DC0%0/1
$house // "undef"
$house
Truth table50%1/2
A
A= $house
Aresult
11
00
405 unless Game::Senet::Notation::house_ok($house);
406 2265 return $self->_game->protected($house);
407 }
408  
409 4202 ▶sub in_blockade {
Subroutine in_blockade: called CC=3 SCAR=13.1
Pod documented
410 4202 my ($self, $house) = @_;
411 4202 ▶ Carp::croak("Game::Senet: there is no house " . ($house // 'undef'))
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Notation::house_ok($house) 0 4202 4202
Condition0%0/2
$house // "undef"
l!l
00
MC/DC0%0/1
$house // "undef"
$house
Truth table0%0/2
A
A= $house
Aresult
11
00
412 unless Game::Senet::Notation::house_ok($house);
413 4202 return $self->_game->in_blockade($house);
414 }
415  
416 3 ▶sub rules_revision { 1 }
Subroutine rules_revision: called CC=1 SCAR=0.0
Pod documented
417  
418 6897 ▶sub chances {
Subroutine chances: called CC=2 SCAR=6.9
Pod documented
419 return map {
420 6897 my ($roll, $weight, $denominator) = @$_;
421 34485 ▶ { roll => $roll, throw => ($roll == 5 ? 0 : $roll), weight => $weight,
Branch: 1 branch
BranchTrueFalseTotal
$roll == 5 ? : 6897 27588 34485
422 denominator => $denominator, extra => Game::Senet::Sticks::extra_throw($roll) }
423 } $E->chances;
424 }
425  
426 12853 ▶sub log { [ map { { %$_ } } @{ $_[0]->_log } ] }
Subroutine log: called CC=1 SCAR=0.0
Pod documented
427  
428 7131 ▶sub forfeits_since {
Subroutine forfeits_since: called CC=3 SCAR=11.0
Pod documented
429 7131 my ($self, $ply) = @_;
430 7131 ▶ $ply = 0 unless defined $ply;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ply 0 7131 7131
431 7131 ▶ return map { { %$_ } } grep { !defined $_->{move} && $_->{ply} >= $ply } @{ $self->_log };
Condition100%3/3
!defined($_->{'move'}) && $_->{'ply'} >= $ply
!ll&&!rl&&r
69651013209
MC/DC100%2/2
!defined($_->{'move'}) && $_->{'ply'} >= $ply
!defined($_->{'move'}) $_->{'ply'} >= $ply
Truth table100%3/3
not(A) && B
A= !defined($_->{'move'})B= $_->{'ply'} >= $ply
ABresult
0X0
100
111
432 }
433  
434 7221 ▶sub to_record {
Subroutine to_record: called CC=6 SCAR=17.9
Pod documented
435 7221 my ($self) = @_;
436 7221 my $variant = $self->_variant;
437 my %record = (
438 43326 variant => { name => $variant->exits, map { $_ => $variant->$_ } grep { $_ ne 'exits' } $variant->fields },
439 first => $self->_first,
440 plies => [ map { {
441 side => $_->{side}, roll => $_->{roll}, move => $_->{move},
442 705062 ▶ (defined $_->{sticks} ? (sticks => $_->{sticks}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'sticks'} ? : 705057 5 705062
443 7221 } } @{ $self->_log } ],
444 );
445 7221 ▶ $record{position} = $self->_start if defined $self->_start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_start 47 7174 7221
446 7221 ▶ $record{seed} = unpack 'H*', $self->_seed if defined $self->_seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_seed 7180 41 7221
447 7221 ▶ if (my $result = $self->result) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $self->result) 871 6350 7221
448 871 ▶ $record{result} = { winner => ($result->is_draw ? 'draw' : $result->winner), how => $result->how };
Branch: 1 branch
BranchTrueFalseTotal
$result->is_draw ? : 0 871 871
449 }
450 7221 return Game::Senet::Notation::format_record(\%record);
451 }
452  
453 5698 ▶sub replay {
Subroutine replay: called CC=30 SCAR=35.7
Pod documented
454 5698 my ($class, $record, %option) = @_;
455 5698 ▶ my $bad = sub { return (undef, $X->of('bad_record', @_)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
456  
457 5698 ▶ if (!ref $record) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $record) 5687 11 5698
458 5687 my ($parsed, $problem) = Game::Senet::Notation::parse_record($record);
459 5687 ▶ return $bad->(line => $problem->{line}, why => $problem->{error}) unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 42 5645 5687
460 5645 $record = $parsed;
461 }
462 5656 ▶ my @plies = @{ $record->{plies} || [] };
Condition50%1/2
$record->{'plies'} || []
l!l
56560
MC/DC0%0/1
$record->{'plies'} || []
$record->{'plies'}
Truth table50%1/2
A
A= $record->{'plies'}
Aresult
11
00
463 5656 my %fields = %{ $record->{variant} };
464 5656 my $exits = delete $fields{name};
465 5656 my $rules = $option{rules};
466 5656 ▶ unless (defined $rules) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rules) 5655 1 5656
467 5655 ▶ return $bad->(ply => 0, why => 'variant') unless grep { $_ eq $exits } Game::Senet::Variant->names;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $exits;} "Game::Senet::Variant"->names 0 5655 5655
468 5655 $rules = Game::Senet::Variant->custom(exits => $exits, %fields);
469 }
470  
471 my $game = defined $record->{seed}
472 ? $class->new(seed => pack('H*', $record->{seed}), rules => $rules, first => $record->{first}, (defined $record->{position} ? (position => $record->{position}) : ()))
473 1 ▶ : $class->new(script => [ map { { roll => $_->{roll}, sticks => $_->{sticks} } } @plies ],
Branch: 1 branch
BranchTrueFalseTotal
defined $record->{'position'} ? : 0 1 1
474 5656 ▶ rules => $rules, first => $record->{first}, (defined $record->{position} ? (position => $record->{position}) : ()));
Branch: 2 branches
BranchTrueFalseTotal
defined $record->{'seed'} ? : 5655 1 5656
defined $record->{'position'} ? : 1 5654 5655
475  
476 5656 for my $i (0 .. $#plies) {
477 535217 my $ply = $plies[$i];
478 535217 ▶ if (my $made = $game->_log->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $made = $game->_log->[$i]) 3706 531511 535217
479 3706 ▶ return $bad->(ply => $i, why => 'forfeit') if defined $ply->{move} || defined $made->{move};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ply->{"move"} or defined $made->{"move"} 1 3705 3706
Condition66%2/3
defined $ply->{"move"} or defined $made->{"move"}
l!l&&r!l&&!r
103705
MC/DC50%1/2
defined $ply->{"move"} or defined $made->{"move"}
defined $ply->{"move"} defined $made->{"move"}
Truth table66%2/3
A or B
A= defined $ply->{"move"}B= defined $made->{"move"}
ABresult
1X1
011
000
480 3705 ▶ return $bad->(ply => $i, why => 'side') unless $made->{side} eq $ply->{side};
Branch: 1 branch
BranchTrueFalseTotal
unless $made->{"side"} eq $ply->{"side"} 0 3705 3705
481 3705 ▶ return $bad->(ply => $i, why => 'roll') unless $made->{roll} == $ply->{roll};
Branch: 1 branch
BranchTrueFalseTotal
unless $made->{"roll"} == $ply->{"roll"} 0 3705 3705
482 3705 next;
483 }
484 531511 ▶ return $bad->(ply => $i, why => 'over') if $game->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $game->is_over 0 531511 531511
485 531511 ▶ return $bad->(ply => $i, why => 'forfeit') unless defined $ply->{move};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ply->{"move"} 0 531511 531511
486 531511 ▶ return $bad->(ply => $i, why => 'side') unless $game->side eq $ply->{side};
Branch: 1 branch
BranchTrueFalseTotal
unless $game->side eq $ply->{"side"} 0 531511 531511
487 531511 ▶ return $bad->(ply => $i, why => 'roll') unless defined $game->roll && $game->roll == $ply->{roll};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $game->roll and $game->roll == $ply->{"roll"} 1 531510 531511
Condition66%2/3
defined $game->roll and $game->roll == $ply->{"roll"}
!ll&&!rl&&r
01531510
MC/DC50%1/2
defined $game->roll and $game->roll == $ply->{"roll"}
defined $game->roll $game->roll == $ply->{"roll"}
Truth table66%2/3
A and B
A= defined $game->rollB= $game->roll == $ply->{"roll"}
ABresult
0X0
100
111
488 531510 ▶ unless ($game->play($ply->{move})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game->play($ply->{"move"})) 4 531506 531510
489 4 my $error = $game->error;
490 4 return (undef, $X->of($error->code, %{ $error->detail }, ply => $i));
491 }
492 }
493 5650 ▶ return $bad->(ply => scalar @plies, why => 'length') if @{ $game->_log } > @plies;
Branch: 1 branch
BranchTrueFalseTotal
if @{$game->_log;} > @plies 0 5650 5650
494  
495 5650 ▶ if (my $result = $record->{result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $record->{"result"}) 471 5179 5650
496 471 ▶ if ($result->{how} eq 'resign') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'how'} eq 'resign') { } 4 467 471
497 4 ▶ return $bad->(ply => scalar @plies, why => 'result') if $game->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $game->is_over 0 4 4
498 4 $game->resign($OTHER{ $result->{winner} });
499 }
500 else {
501 467 my $ended = $game->result;
502 467 ▶ my $winner = $ended ? ($ended->is_draw ? 'draw' : $ended->winner) : '';
Branch: 2 branches
BranchTrueFalseTotal
$ended ? : 467 0 467
$ended->is_draw ? : 0 467 467
503 return $bad->(ply => scalar @plies, why => 'result')
504 467 ▶ unless $ended && $ended->how eq $result->{how} && $winner eq $result->{winner};
Branch: 1 branch
BranchTrueFalseTotal
unless $ended and $ended->how eq $result->{"how"} and $winner eq $result->{"winner"} 0 467 467
Condition33%2/6
$ended and $ended->how eq $result->{"how"} and $winner eq $result->{"winner"}
!ll&&!rl&&r
00467
$ended and $ended->how eq $result->{"how"}
!ll&&!rl&&r
00467
MC/DC0%0/3
$ended and $ended->how eq $result->{"how"} and $winner eq $result->{"winner"}
$ended $ended->how eq $result->{"how"} $winner eq $result->{"winner"}
Truth table25%1/4
A and B and C
A= $endedB= $ended->how eq $result->{"how"}C= $winner eq $result->{"winner"}
ABCresult
0XX0
10X0
1100
1111
505 }
506 }
507 5650 return ($game, undef);
508 }
509  
510 6378 ▶sub to_text { $_[0]->to_record }
Subroutine to_text: called CC=1 SCAR=0.0
Pod documented
511  
512 5198 ▶sub from_text {
Subroutine from_text: called CC=8 SCAR=33.4
Pod documented
513 5198 my ($class, $text) = @_;
514 5198 ▶ Carp::croak('Game::Senet: from_text wants the text to_text wrote, and was given '
Branch: 2 branches
BranchTrueFalseTotal
if not defined $text or ref $text 0 5198 5198
defined $text ? : 0 0 0
Condition33%1/3
not defined $text or ref $text
l!l&&r!l&&!r
005198
MC/DC0%0/2
not defined $text or ref $text
not defined $text ref $text
Truth table33%1/3
not(A) or B
A= not defined $textB= ref $text
ABresult
1X1
011
000
515 . (defined $text ? 'a reference' : 'nothing'))
516 if !defined $text || ref $text;
517 5198 my ($game, $error) = $class->replay($text);
518 5198 ▶ return $game if $game;
Branch: 1 branch
BranchTrueFalseTotal
if $game 5198 0 5198
519 0 my $detail = $error->detail;
520 0 ▶ my $where = $detail->{line} ? " at line $detail->{line}" : ' at ply ' . (($detail->{ply} // 0) + 1);
Branch: 1 branch
BranchTrueFalseTotal
$detail->{'line'} ? : 0 0 0
Condition0%0/2
$detail->{"ply"} // 0
l!l
00
MC/DC0%0/1
$detail->{"ply"} // 0
$detail->{"ply"}
Truth table0%0/2
A
A= $detail->{"ply"}
Aresult
11
00
521 Carp::croak('Game::Senet: the text was refused' . $where . ': ' . $error->message
522 0 ▶ . (defined $detail->{why} ? " ($detail->{why})" : ''));
Branch: 1 branch
BranchTrueFalseTotal
defined $detail->{'why'} ? : 0 0 0
523 }
524  
525 83 1;
526  
527 __END__
« blib/lib/Game/Senet/Notation.pm ↑ Summary blib/lib/Game/Senet/Terminal.pm »