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/Result.pm »
1 package Game::Senet;
2  
3 62 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 62 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 62 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 62 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 62 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
9 62 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 62 ▶use Game::Senet::Engine qw(EMPTY LIGHT DARK SIDE_LIGHT SIDE_DARK piece_of);
Subroutine __ANON__: called CC=1 SCAR=0.0
12 62 ▶use Game::Senet::Rules;
Subroutine __ANON__: called CC=1 SCAR=0.0
13 62 ▶use Game::Senet::Variant;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 62 ▶use Game::Senet::Sticks ();
Subroutine __ANON__: called CC=1 SCAR=0.0
15 62 ▶use Game::Senet::Notation ();
Subroutine __ANON__: called CC=1 SCAR=0.0
16 62 ▶use Game::Senet::Error;
Subroutine __ANON__: called CC=1 SCAR=0.0
17 62 ▶use Game::Senet::Result;
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 62 our $VERSION = '0.02';
20  
21 62 my $E = 'Game::Senet::Engine';
22 62 my $X = 'Game::Senet::Error';
23  
24 62 my (%SIDE_OF, %OTHER, %SEATS);
25 62 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 62 %SIDE_OF = (light => SIDE_LIGHT, dark => SIDE_DARK);
27 62 %OTHER = (light => 'dark', dark => 'light', p1 => 'p2', p2 => 'p1');
28 62 %SEATS = (p1 => 1, p2 => 1);
29 }
30  
31 62 has _light_seat => (is => 'ro', init_arg => 'light', private => 1, default => 'p1');
32  
33 62 has _seed => (is => 'ro', init_arg => 'seed', private => 1);
34  
35 62 has _rules_given => (is => 'ro', init_arg => 'rules', private => 1);
36  
37 62 has _first_given => (is => 'ro', init_arg => 'first', private => 1);
38  
39 62 has _position_given => (is => 'ro', init_arg => 'position', private => 1);
40  
41 62 has _start => (is => 'rw', private => 1);
42  
43 62 has _script => (is => 'ro', init_arg => 'script', private => 1);
44  
45 62 has _variant => (is => 'rw', private => 1);
46  
47 62 has _game => (is => 'rw', private => 1);
48  
49 62 has _first => (is => 'rw', private => 1);
50  
51 62 has _throws => (is => 'rw', private => 1);
52  
53 62 has _roll => (is => 'rw', private => 1);
54  
55 62 has _sticks => (is => 'rw', private => 1);
56  
57 62 has _legal => (is => 'rw', private => 1);
58  
59 62 has _number => (is => 'rw', private => 1);
60  
61 62 has _log => (is => 'rw', private => 1);
62  
63 62 has _choices => (is => 'rw', private => 1);
64  
65 62 has _resigned => (is => 'rw', private => 1);
66  
67 62 has _error => (is => 'rw', private => 1);
68  
69 7144 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=27.1
Pod undocumented
70 7144 my ($self) = @_;
71 7144 my ($seed, $script) = ($self->_seed, $self->_script);
72 7144 ▶ 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 7143 7144
Condition77%7/9
defined $seed and not ref $seed and length $seed or ref $script eq "ARRAY"
l!l&&r!l&&!r
69901531
defined $seed and not ref $seed and length $seed
!ll&&!rl&&r
15406990
defined $seed and not ref $seed
!ll&&!rl&&r
15406990
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 7143 ▶ unless defined $self->_light_seat && $SEATS{ $self->_light_seat };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_light_seat and $SEATS{$self->_light_seat} 1 7142 7143
Condition66%2/3
defined $self->_light_seat and $SEATS{$self->_light_seat}
!ll&&!rl&&r
017142
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 7142 my $variant = Game::Senet::Variant->of($self->_rules_given);
78 7142 $self->_variant($variant);
79  
80 7142 my $first = $self->_first_given;
81 Carp::croak("Game::Senet: first is 'light' or 'dark'")
82 7142 ▶ if defined $first && !exists $SIDE_OF{$first};
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and not exists $SIDE_OF{$first} 1 7141 7142
Condition100%3/3
defined $first and not exists $SIDE_OF{$first}
!ll&&!rl&&r
144256991
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 7141 my $position = $self->_position_given;
85 7141 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) 149 6992 7141
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 7140 $self->_start($position);
94  
95 7140 ▶ my $game = Game::Senet::Rules->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 148 6992 7140
Condition100%2/2
$first // "light"
l!l
56981294
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 7140 $self->_game($game);
100 7140 $self->_first($game->side);
101 7140 $self->_throws(0);
102 7140 $self->_log([]);
103 7140 $self->_choices([]);
104 7140 $self->_settle;
105 7140 return;
106 }
107  
108 774983 ▶sub _next_throw {
Subroutine _next_throw: called CC=5 SCAR=16.1
109 774983 my ($self, $number) = @_;
110 774983 ▶ if (my $script = $self->_script) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = $self->_script) 10387 764596 774983
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 764596 my $sticks = Game::Senet::Sticks::throw_for($self->_seed, $number);
116 764596 return (Game::Senet::Sticks::roll_of(Game::Senet::Sticks::light_of($sticks)), join '', @$sticks);
117 }
118  
119 755273 ▶sub _settle {
Subroutine _settle: called CC=5 SCAR=16.1
120 755273 my ($self) = @_;
121 755273 my $game = $self->_game;
122 755273 $self->_roll(undef);
123 755273 $self->_sticks(undef);
124 755273 $self->_number(undef);
125 755273 $self->_legal([]);
126  
127 755273 ▶ while (!$self->is_over) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_over) 774983 1770 776753
128 774983 my $number = $self->_throws;
129 774983 my ($roll, $sticks) = $self->_next_throw($number);
130 774983 ▶ return unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 206 774777 774983
131 774777 $self->_throws($number + 1);
132  
133 774777 my @moves = $game->moves($roll);
134 774777 ▶ if (@moves) {
Branch: 1 branch
BranchTrueFalseTotal
if (@moves) 753297 21480 774777
135 753297 $self->_legal(\@moves);
136 753297 $self->_roll($roll);
137 753297 $self->_sticks($sticks);
138 753297 $self->_number($number);
139 753297 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 833767 ▶sub play {
Subroutine play: called CC=14 SCAR=26.4
Pod documented
228 833767 my ($self, $what) = @_;
229 833767 $self->_error(undef);
230 833767 ▶ return $self->_refuse('game_over') if $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_over 1 833766 833767
231  
232 833766 my ($from, $to);
233 833766 ▶ 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
6174370216329
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 833766 ▶ if ($object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object) { } 216329 617437 833766
235 216329 ▶ ($from, $to) = ($what->from, $what->off ? 'off' : $what->to);
Branch: 1 branch
BranchTrueFalseTotal
$what->off ? : 10804 205525 216329
236 }
237 else {
238 617437 my ($parsed, $why) = Game::Senet::Notation::parse_move($what);
239 617437 ▶ return $self->_refuse('bad_move', text => $what, why => $why) unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 6897 610540 617437
240 610540 ($from, $to) = @{$parsed}{qw(from to)};
241 }
242 826869 ▶ return $self->_refuse('no_roll') unless defined $self->_roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_roll 1 826868 826869
243  
244 826868 my $game = $self->_game;
245 826868 my $roll = $self->_roll;
246 826868 my $wire = $from . '-' . $to;
247 826868 my ($move) = grep { Game::Senet::Notation::format_move($_) eq $wire } @{ $self->_legal };
248 826868 ▶ $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 826867 826868
Condition88%8/9
$move and $object and $what->roll != $roll || $what->side ne $game->side
!ll&&!rl&&r
6105392163281
$move and $object
!ll&&!rl&&r
78734531805216329
$what->roll != $roll or $what->side ne $game->side
l!l&&r!l&&!r
10216328
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 826868 ▶ return $self->_refuse($self->_why_not($from, $to), from => $from, to => $to, roll => $roll)
Branch: 1 branch
BranchTrueFalseTotal
unless $move 78735 748133 826868
250 unless $move;
251  
252 748133 push @{ $self->_choices }, {
253 748133 depth => $game->depth, log => scalar @{ $self->_log },
254 throws => $self->_throws, roll => $roll, sticks => $self->_sticks, number => $self->_number,
255 };
256 748133 my $side = $game->side;
257 748133 my $ply = $game->ply;
258 748133 $game->apply($move);
259 748133 ▶ push @{ $self->_log }, {
Branch: 1 branch
BranchTrueFalseTotal
!$game->is_over && $game->side eq $side ? : 300922 447211 748133
Condition100%3/3
not $game->is_over and $game->side eq $side
!ll&&!rl&&r
1769445442300922
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 748133 $self->_settle;
265 748133 return $move;
266 }
267  
268 1069 ▶sub play_or_die {
Subroutine play_or_die: called CC=2 SCAR=8.4
Pod documented
269 1069 my ($self, $what) = @_;
270 1069 my $move = $self->play($what);
271 1069 ▶ return $move if $move;
Branch: 1 branch
BranchTrueFalseTotal
if $move 1069 0 1069
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 4943546 ▶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 4938524 4943546
Condition100%3/3
defined $_[0]->_resigned or $_[0]->_game->is_over
l!l&&r!l&&!r
850144938524
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 10541 ▶sub result {
Subroutine result: called CC=4 SCAR=13.9
Pod documented
308 10541 my ($self) = @_;
309 10541 ▶ return undef unless $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_over 9126 1415 10541
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 551161 ▶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 551161 551161
325  
326 1579235 ▶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 1579235 1579235
327  
328 92495 ▶sub sticks {
Subroutine sticks: called CC=3 SCAR=11.1
Pod documented
329 92495 my ($self) = @_;
330 92495 ▶ my $sticks = $self->is_over ? undef : $self->_sticks;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_over ? : 0 92495 92495
331 92495 ▶ return defined $sticks ? [ split //, $sticks ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $sticks ? : 20355 72140 92495
332 }
333  
334 9766 ▶sub throw {
Subroutine throw: called CC=3 SCAR=11.0
Pod documented
335 9766 my ($self) = @_;
336 9766 my $roll = $self->roll;
337 9766 ▶ return undef unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 0 9766 9766
338 9766 ▶ return $roll == 5 ? 0 : $roll;
Branch: 1 branch
BranchTrueFalseTotal
$roll == 5 ? : 618 9148 9766
339 }
340  
341 403353 ▶sub legal {
Subroutine legal: called CC=4 SCAR=14.6
Pod documented
342 403353 my ($self) = @_;
343 403353 ▶ return wantarray ? () : 0 unless defined $self->roll;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->roll 0 403353 403353
wantarray ? : 0 0 0
344 403353 my @legal = @{ $self->_legal };
345 403353 ▶ return wantarray ? @legal : scalar @legal;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 362353 41000 403353
346 }
347  
348 225229 ▶sub turn {
Subroutine turn: called CC=7 SCAR=19.5
Pod documented
349 225229 my ($self) = @_;
350 225229 ▶ return undef if $self->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_over 244 224985 225229
351 224985 my $side = $self->_game->side;
352 224985 my $segment = 1;
353 224985 for my $entry (reverse @{ $self->_log }) {
354 254947 ▶ last unless $entry->{side} eq $side && $entry->{again};
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"side"} eq $side and $entry->{"again"} 151432 103515 254947
Condition66%2/3
$entry->{"side"} eq $side and $entry->{"again"}
!ll&&!rl&&r
1514320103515
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 103515 $segment++;
356 }
357 224985 my $roll = $self->_roll;
358 return {
359 224985 ▶ side => $side,
Branch: 1 branch
BranchTrueFalseTotal
defined $roll ? : 224982 3 224985
Condition100%2/2
$self->_game->only || undef
l!l
5479219506
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 95439 ▶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 6898 ▶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 90347 ▶sub ply { $_[0]->_game->ply }
Subroutine ply: called CC=1 SCAR=0.0
Pod documented
387  
388 88863 ▶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 12732 ▶sub home { $_[0]->_game->home($_[1]) }
Subroutine home: called CC=1 SCAR=0.0
Pod documented
393  
394 503340 ▶sub at {
Subroutine at: called CC=5 SCAR=16.8
Pod documented
395 503340 my ($self, $house) = @_;
396 503340 ▶ Carp::croak("Game::Senet: there is no house " . ($house // 'undef'))
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Notation::house_ok($house) 0 503340 503340
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 503340 my $piece = $self->_game->board->at($house);
399 503340 ▶ return $piece == EMPTY ? undef : $piece == LIGHT ? 'light' : 'dark';
Branch: 2 branches
BranchTrueFalseTotal
$piece == 0 ? : 357468 145872 503340
$piece == 1 ? : 71017 74855 145872
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 12702 ▶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 7094 ▶sub to_record {
Subroutine to_record: called CC=6 SCAR=17.9
Pod documented
435 7094 my ($self) = @_;
436 7094 my $variant = $self->_variant;
437 my %record = (
438 42564 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 704872 ▶ (defined $_->{sticks} ? (sticks => $_->{sticks}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'sticks'} ? : 704867 5 704872
443 7094 } } @{ $self->_log } ],
444 );
445 7094 ▶ $record{position} = $self->_start if defined $self->_start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_start 47 7047 7094
446 7094 ▶ $record{seed} = unpack 'H*', $self->_seed if defined $self->_seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_seed 7053 41 7094
447 7094 ▶ if (my $result = $self->result) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $self->result) 871 6223 7094
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 7094 return Game::Senet::Notation::format_record(\%record);
451 }
452  
453 5667 ▶sub replay {
Subroutine replay: called CC=30 SCAR=35.7
Pod documented
454 5667 my ($class, $record, %option) = @_;
455 5667 ▶ my $bad = sub { return (undef, $X->of('bad_record', @_)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
456  
457 5667 ▶ if (!ref $record) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $record) 5663 4 5667
458 5663 my ($parsed, $problem) = Game::Senet::Notation::parse_record($record);
459 5663 ▶ return $bad->(line => $problem->{line}, why => $problem->{error}) unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 41 5622 5663
460 5622 $record = $parsed;
461 }
462 5626 ▶ my @plies = @{ $record->{plies} || [] };
Condition50%1/2
$record->{'plies'} || []
l!l
56260
MC/DC0%0/1
$record->{'plies'} || []
$record->{'plies'}
Truth table50%1/2
A
A= $record->{'plies'}
Aresult
11
00
463 5626 my %fields = %{ $record->{variant} };
464 5626 my $exits = delete $fields{name};
465 5626 my $rules = $option{rules};
466 5626 ▶ unless (defined $rules) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rules) 5625 1 5626
467 5625 ▶ 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 5625 5625
468 5625 $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 5626 ▶ rules => $rules, first => $record->{first}, (defined $record->{position} ? (position => $record->{position}) : ()));
Branch: 2 branches
BranchTrueFalseTotal
defined $record->{'seed'} ? : 5625 1 5626
defined $record->{'position'} ? : 1 5624 5625
475  
476 5626 for my $i (0 .. $#plies) {
477 535165 my $ply = $plies[$i];
478 535165 ▶ if (my $made = $game->_log->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $made = $game->_log->[$i]) 3706 531459 535165
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 531459 ▶ return $bad->(ply => $i, why => 'over') if $game->is_over;
Branch: 1 branch
BranchTrueFalseTotal
if $game->is_over 0 531459 531459
485 531459 ▶ return $bad->(ply => $i, why => 'forfeit') unless defined $ply->{move};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ply->{"move"} 0 531459 531459
486 531459 ▶ return $bad->(ply => $i, why => 'side') unless $game->side eq $ply->{side};
Branch: 1 branch
BranchTrueFalseTotal
unless $game->side eq $ply->{"side"} 0 531459 531459
487 531459 ▶ 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 531458 531459
Condition66%2/3
defined $game->roll and $game->roll == $ply->{"roll"}
!ll&&!rl&&r
01531458
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 531458 ▶ unless ($game->play($ply->{move})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($game->play($ply->{"move"})) 4 531454 531458
489 4 my $error = $game->error;
490 4 return (undef, $X->of($error->code, %{ $error->detail }, ply => $i));
491 }
492 }
493 5620 ▶ return $bad->(ply => scalar @plies, why => 'length') if @{ $game->_log } > @plies;
Branch: 1 branch
BranchTrueFalseTotal
if @{$game->_log;} > @plies 0 5620 5620
494  
495 5620 ▶ if (my $result = $record->{result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $record->{"result"}) 471 5149 5620
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 5620 return ($game, undef);
508 }
509  
510 6251 ▶sub to_text { $_[0]->to_record }
Subroutine to_text: called CC=1 SCAR=0.0
Pod documented
511  
512 5178 ▶sub from_text {
Subroutine from_text: called CC=8 SCAR=33.4
Pod documented
513 5178 my ($class, $text) = @_;
514 5178 ▶ 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 5178 5178
defined $text ? : 0 0 0
Condition33%1/3
not defined $text or ref $text
l!l&&r!l&&!r
005178
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 5178 my ($game, $error) = $class->replay($text);
518 5178 ▶ return $game if $game;
Branch: 1 branch
BranchTrueFalseTotal
if $game 5178 0 5178
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 62 1;
526  
527 __END__
« blib/lib/Game/Senet/Notation.pm ↑ Summary blib/lib/Game/Senet/Result.pm »