blib/lib/Game/Senet/Notation.pm

filter: Statementstmt 100% 216 / 216 Branchbran 92.9% 145 / 156 Conditioncond 78.3% 58 / 74 MC/DCmcdc 52.2% 23 / 44 Subroutinesub 100% 29 / 29 Podpod 100% 8 / 8 totaltotal 90.8% 479 / 527 CC 106 SCAR 29.7
CC
106
Cov
94%
parse_record
37.0
validate_position
30.0
parse_move
11.0
CRAP 19.4
↑ Summary blib/lib/Game/Senet.pm »
1 package Game::Senet::Notation;
2  
3 83 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 83 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 83 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 83 ▶use Exporter 'import';
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 83 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 83 ▶use Game::Senet::Sticks ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 85 our $VERSION = '0.03';
13  
14 83 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 83 POS_OK => 0,
16 POS_NULL => 1,
17 POS_GROUPS => 2,
18 POS_WIDTH => 3,
19 POS_LETTER => 4,
20 POS_SIDE => 5,
21 POS_PIECES => 6,
22 POS_EXCESS => 7,
23 POS_FIELD => 8,
24 POS_LONG => 9,
25 83 };
26  
27 85 our (@EXPORT_OK, %EXPORT_TAGS);
28 85 my (@FIELDS, %FIELD_OK, %SIDE_OF, %LETTER_OF, %RESULT_OK, $MOVE_MAX);
29 85 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 85 @EXPORT_OK = qw(
31 house_ok parse_move format_move format_display format_forfeit
32 validate_position parse_record format_record
33 POS_OK POS_NULL POS_GROUPS POS_WIDTH POS_LETTER POS_SIDE
34 POS_PIECES POS_EXCESS POS_FIELD POS_LONG
35 );
36 85 %EXPORT_TAGS = (all => \@EXPORT_OK);
37  
38 85 @FIELDS = qw(pieces blockade protect backward reach26 throw_on_26);
39 85 %FIELD_OK = (
40 pieces => qr/\A[1-7]\z/,
41 blockade => qr/\A[023]\z/,
42 protect => qr/\A(?:none|run|ends)\z/,
43 backward => qr/\A[01]\z/,
44 reach26 => qr/\A(?:exact|any)\z/,
45 throw_on_26 => qr/\A[01]\z/,
46 );
47 85 %SIDE_OF = (l => 'light', d => 'dark');
48 85 %LETTER_OF = (light => 'l', dark => 'd');
49 85 %RESULT_OK = map { $_ => 1 }
50 'light home', 'dark home', 'light resign', 'dark resign', 'draw ply_cap';
51 85 $MOVE_MAX = length '30-off';
52 }
53  
54 2831938 ▶sub house_ok {
Subroutine house_ok: called CC=4 SCAR=13.9
Pod documented
55 2831938 my ($text) = @_;
56 2831938 ▶ return 0 unless defined $text && $text =~ /\A[1-9][0-9]?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and $text =~ /\A[1-9][0-9]?\z/ 3 2831935 2831938
Condition66%2/3
defined $text and $text =~ /\A[1-9][0-9]?\z/
!ll&&!rl&&r
032831935
MC/DC50%1/2
defined $text and $text =~ /\A[1-9][0-9]?\z/
defined $text $text =~ /\A[1-9][0-9]?\z/
Truth table66%2/3
A and B
A= defined $textB= $text =~ /\A[1-9][0-9]?\z/
ABresult
0X0
100
111
57 2831935 ▶ return $text <= 30 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$text <= 30 ? : 2831933 2 2831935
58 }
59  
60 2350938 ▶my $place = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
61 2350938 my ($text) = @_;
62 2350938 ▶ return ('off', undef) if lc $text eq 'off';
Branch: 1 branch
BranchTrueFalseTotal
if lc $text eq "off" 34533 2316405 2350938
63 2316405 ▶ return (undef, 'shape') unless $text =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\A[0-9]+\z/ 5 2316400 2316405
64 2316400 ▶ return (undef, 'house') unless house_ok($text);
Branch: 1 branch
BranchTrueFalseTotal
unless house_ok($text) 4 2316396 2316400
65 2316396 return ($text + 0, undef);
66 85 };
67  
68 1182375 ▶sub parse_move {
Subroutine parse_move: called CC=11 SCAR=24.0
Pod documented
69 1182375 my ($text) = @_;
70 1182375 ▶ return (undef, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 2 1182373 1182375
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
111182373
MC/DC100%2/2
defined $text and length $text
defined $text length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
71 1182373 ▶ return (undef, 'long') if length $text > $MOVE_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > $MOVE_MAX 6898 1175475 1182373
72 1175475 my @parts = split /-/, $text, -1;
73 1175475 ▶ return (undef, 'shape') unless @parts == 2 && length $parts[0] && length $parts[1];
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 and length $parts[0] and length $parts[1] 4 1175471 1175475
Condition83%5/6
@parts == 2 and length $parts[0] and length $parts[1]
!ll&&!rl&&r
401175471
@parts == 2 and length $parts[0]
!ll&&!rl&&r
311175471
MC/DC66%2/3
@parts == 2 and length $parts[0] and length $parts[1]
@parts == 2 length $parts[0] length $parts[1]
Truth table75%3/4
A and B and C
A= @parts == 2B= length $parts[0]C= length $parts[1]
ABCresult
0XX0
10X0
1100
1111
74 1175471 my ($from, $bad_from) = $place->($parts[0]);
75 1175471 ▶ return (undef, $bad_from) if $bad_from;
Branch: 1 branch
BranchTrueFalseTotal
if $bad_from 4 1175467 1175471
76 1175467 my ($to, $bad_to) = $place->($parts[1]);
77 1175467 ▶ return (undef, $bad_to) if $bad_to;
Branch: 1 branch
BranchTrueFalseTotal
if $bad_to 5 1175462 1175467
78 1175462 ▶ return (undef, 'from_off') if $from eq 'off';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "off" 1 1175461 1175462
79 1175461 ▶ return (undef, 'same') if $from eq $to;
Branch: 1 branch
BranchTrueFalseTotal
if $from eq $to 1 1175460 1175461
80 1175460 return ({ from => $from, to => $to }, undef);
81 }
82  
83 8409246 ▶my $read = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
84 8409246 my ($move, $name) = @_;
85 8409246 ▶ return $move->$name if Scalar::Util::blessed($move) && $move->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($move) and $move->can($name) 6707180 1702066 8409246
Condition66%2/3
builtin::blessed($move) and $move->can($name)
!ll&&!rl&&r
170206606707180
MC/DC50%1/2
builtin::blessed($move) and $move->can($name)
builtin::blessed($move) $move->can($name)
Truth table66%2/3
A and B
A= builtin::blessed($move)B= $move->can($name)
ABresult
0X0
100
111
86 1702066 ▶ return ref $move eq 'HASH' ? $move->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $move eq 'HASH' ? : 1702066 0 1702066
87 85 };
88  
89 2824225 ▶sub format_move {
Subroutine format_move: called CC=2 SCAR=6.9
Pod documented
90 2824225 my ($move) = @_;
91 2824225 ▶ my $to = $read->($move, 'off') ? 'off' : $read->($move, 'to');
Branch: 1 branch
BranchTrueFalseTotal
&$read($move, 'off') ? : 71013 2753212 2824225
92 2824225 return $read->($move, 'from') . '-' . lc $to;
93 }
94  
95 2528 ▶sub format_display {
Subroutine format_display: called CC=4 SCAR=13.9
Pod documented
96 2528 my ($move, $again) = @_;
97 2528 ▶ return $read->($move, 'roll') . ': ' . format_move($move)
Branch: 3 branches
BranchTrueFalseTotal
&$read($move, 'back') ? : 141 2387 2528
&$read($move, 'swap') ? : 479 2049 2528
$again ? : 7 2521 2528
98 . ($read->($move, 'back') ? '<' : '')
99 . ($read->($move, 'swap') ? 'x' : '')
100 . ($again ? '+' : '');
101 }
102  
103 5 ▶sub format_forfeit {
Subroutine format_forfeit: called CC=2 SCAR=6.9
Pod documented
104 5 my ($roll, $again) = @_;
105 5 ▶ return $roll . ': -' . ($again ? '+' : '');
Branch: 1 branch
BranchTrueFalseTotal
$again ? : 4 1 5
106 }
107  
108 752 ▶sub validate_position {
Subroutine validate_position: called CC=30 SCAR=34.0
Pod documented
109 752 my ($text) = @_;
110 752 ▶ return POS_NULL unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 1 751 752
Condition66%2/3
defined $text and length $text
!ll&&!rl&&r
01751
MC/DC50%1/2
defined $text and length $text
defined $text length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
111 751 ▶ return POS_LONG if length $text >= 48;
Branch: 1 branch
BranchTrueFalseTotal
if length $text >= 48 1 750 751
112  
113 750 my @c = split //, $text;
114 750 my ($group, $width, $i) = (0, 0, 0);
115 750 my %count = (l => 0, d => 0);
116 750 ▶ for (; $i < @c && $c[$i] ne ' '; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c and $c[$i] ne " ") 23281 711 23992
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
171023281
MC/DC100%2/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table100%3/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
117 23281 my $ch = $c[$i];
118 23281 ▶ if ($ch eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "/") 1456 21825 23281
119 1456 ▶ return POS_WIDTH if $width != 10;
Branch: 1 branch
BranchTrueFalseTotal
if $width != 10 6 1450 1456
120 1450 ▶ return POS_GROUPS if $group == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $group == 2 1 1449 1450
121 1449 $group++;
122 1449 $width = 0;
123 1449 next;
124 }
125 21825 ▶ return POS_LETTER unless $ch eq 'l' || $ch eq 'd' || $ch eq '.';
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq "l" or $ch eq "d" or $ch eq "." 31 21794 21825
Condition100%6/6
$ch eq "l" or $ch eq "d" or $ch eq "."
l!l&&r!l&&!r
29021889231
$ch eq "l" or $ch eq "d"
l!l&&r!l&&!r
1447145518923
MC/DC100%3/3
$ch eq "l" or $ch eq "d" or $ch eq "."
$ch eq "l" $ch eq "d" $ch eq "."
Truth table100%4/4
A or B or C
A= $ch eq "l"B= $ch eq "d"C= $ch eq "."
ABCresult
1XX1
01X1
0011
0000
126 21794 ▶ return POS_WIDTH if $width >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $width >= 10 1 21793 21794
127 21793 ▶ $count{$ch}++ if $ch ne '.';
Branch: 1 branch
BranchTrueFalseTotal
if $ch ne "." 2902 18891 21793
128 21793 $width++;
129 }
130 711 ▶ return POS_GROUPS if $group != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $group != 2 4 707 711
131 707 ▶ return POS_WIDTH if $width != 10;
Branch: 1 branch
BranchTrueFalseTotal
if $width != 10 1 706 707
132  
133 706 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 1 705 706
Condition66%2/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
10705
MC/DC50%1/2
$i < @c and $c[$i] eq " "
$i < @c $c[$i] eq " "
Truth table66%2/3
A and B
A= $i < @cB= $c[$i] eq " "
ABresult
0X0
100
111
134 705 $i++;
135 705 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 0 705 705
136 705 ▶ return POS_SIDE unless $c[$i] eq 'l' || $c[$i] eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] eq "l" or $c[$i] eq "d" 3 702 705
Condition100%3/3
$c[$i] eq "l" or $c[$i] eq "d"
l!l&&r!l&&!r
648543
MC/DC100%2/2
$c[$i] eq "l" or $c[$i] eq "d"
$c[$i] eq "l" $c[$i] eq "d"
Truth table100%3/3
A or B
A= $c[$i] eq "l"B= $c[$i] eq "d"
ABresult
1X1
011
000
137 702 $i++;
138 702 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 1 701 702
139 701 ▶ return POS_SIDE unless $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] eq " " 1 700 701
140 700 $i++;
141 700 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 1 699 700
142 699 ▶ return POS_PIECES unless $c[$i] =~ /\A[1-7]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] =~ /\A[1-7]\z/ 3 696 699
143 696 my $pieces = $c[$i];
144 696 $i++;
145 696 ▶ return POS_PIECES if $i < @c && $c[$i] ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c and $c[$i] ne " " 1 695 696
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
69411
MC/DC100%2/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table100%3/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
146 695 ▶ return POS_FIELD if $i < @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c 1 694 695
147 694 ▶ return POS_EXCESS if $count{l} > $pieces || $count{d} > $pieces;
Branch: 1 branch
BranchTrueFalseTotal
if $count{"l"} > $pieces or $count{"d"} > $pieces 3 691 694
Condition100%3/3
$count{"l"} > $pieces or $count{"d"} > $pieces
l!l&&r!l&&!r
21691
MC/DC100%2/2
$count{"l"} > $pieces or $count{"d"} > $pieces
$count{"l"} > $pieces $count{"d"} > $pieces
Truth table100%3/3
A or B
A= $count{"l"} > $piecesB= $count{"d"} > $pieces
ABresult
1X1
011
000
148 691 return POS_OK;
149 }
150  
151 7268 ▶my $variant_text = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
152 7268 my ($variant) = @_;
153 7268 return join ' ', $variant->{name}, map { "$_=$variant->{$_}" } @FIELDS;
154 85 };
155  
156 5715 ▶my $variant_of = sub {
Subroutine __ANON__: called CC=9 SCAR=22.5
157 5715 my ($text) = @_;
158 5715 my ($name, @pairs) = split / /, $text, -1;
159 5715 ▶ return undef unless defined $name && $name =~ /\A[a-z][a-z0-9_]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/ 0 5715 5715
Condition33%1/3
defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/
!ll&&!rl&&r
005715
MC/DC0%0/2
defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/
defined $name $name =~ /\A[a-z][a-z0-9_]*\z/
Truth table33%1/3
A and B
A= defined $nameB= $name =~ /\A[a-z][a-z0-9_]*\z/
ABresult
0X0
100
111
160 5715 my (%variant, @names) = (name => $name);
161 5715 for my $pair (@pairs) {
162 34284 ▶ my ($field, $value) = $pair =~ /\A([a-z_0-9]+)=([a-z0-9]+)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $pair =~ /\A([a-z_0-9]+)=([a-z0-9]+)\z/ or return undef 34284 0 34284
163 34284 push @names, $field;
164 34284 ▶ return undef unless $FIELD_OK{$field} && $value =~ $FIELD_OK{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless $FIELD_OK{$field} and $value =~ /$FIELD_OK{$field}/ 1 34283 34284
Condition66%2/3
$FIELD_OK{$field} and $value =~ /$FIELD_OK{$field}/
!ll&&!rl&&r
0134283
MC/DC50%1/2
$FIELD_OK{$field} and $value =~ /$FIELD_OK{$field}/
$FIELD_OK{$field} $value =~ /$FIELD_OK{$field}/
Truth table66%2/3
A and B
A= $FIELD_OK{$field}B= $value =~ /$FIELD_OK{$field}/
ABresult
0X0
100
111
165 34283 ▶ $variant{$field} = $value =~ /\A\d+\z/ ? $value + 0 : $value;
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\A\d+\z/ ? : 22855 11428 34283
166 }
167 5714 ▶ return undef unless "@names" eq "@FIELDS";
Branch: 1 branch
BranchTrueFalseTotal
unless join($", @names) eq join($", @FIELDS) 2 5712 5714
168 5712 return \%variant;
169 85 };
170  
171 7268 ▶sub format_record {
Subroutine format_record: called CC=8 SCAR=20.8
Pod documented
172 7268 my ($record) = @_;
173 my @lines = (
174 '[variant ' . $variant_text->($record->{variant}) . ']',
175 7268 '[first ' . $record->{first} . ']',
176 );
177 7268 ▶ push @lines, '[position ' . $record->{position} . ']' if defined $record->{position};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"position"} 47 7221 7268
178 7268 ▶ push @lines, '[seed ' . $record->{seed} . ']' if defined $record->{seed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"seed"} 7226 42 7268
179 7268 my $n = 0;
180 7268 ▶ for my $ply (@{ $record->{plies} || [] }) {
Condition50%1/2
$record->{'plies'} || []
l!l
72680
MC/DC0%0/1
$record->{'plies'} || []
$record->{'plies'}
Truth table50%1/2
A
A= $record->{'plies'}
Aresult
11
00
181 712638 $n++;
182 push @lines, $n . '. ' . $LETTER_OF{ $ply->{side} } . ' ' . $ply->{roll}
183 . (defined $ply->{sticks} ? ' ' . $ply->{sticks} : '')
184 712638 ▶ . ': ' . (defined $ply->{move} ? $ply->{move} : '-');
Branch: 2 branches
BranchTrueFalseTotal
defined $ply->{'sticks'} ? : 712628 10 712638
defined $ply->{'move'} ? : 706613 6025 712638
185 }
186 push @lines, '[result ' . $record->{result}{winner} . ' ' . $record->{result}{how} . ']'
187 7268 ▶ if $record->{result};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"result"} 914 6354 7268
188 7268 return join("\n", @lines) . "\n";
189 }
190  
191 5757 ▶sub parse_record {
Subroutine parse_record: called CC=36 SCAR=36.1
Pod documented
192 5757 my ($text) = @_;
193 5757 ▶ my $fail = sub { return (undef, { line => $_[0], error => $_[1] }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
194 5757 ▶ return $fail->(0, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 5757 5757
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
005757
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
195 5757 ▶ return $fail->(0, 'no_newline') unless $text =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n\z/ 1 5756 5757
196  
197 5756 my @lines = split /\n/, $text, -1;
198 5756 pop @lines;
199 5756 my %record = (plies => []);
200 5756 my ($at, $done) = (0, 0);
201  
202 22890 ▶ my $header = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
203 22890 my ($name, $pattern) = @_;
204 22890 ▶ return undef unless $at < @lines && $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/ 5765 17125 22890
Condition100%3/3
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
!ll&&!rl&&r
1576417125
MC/DC100%2/2
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
$at < @lines $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
Truth table100%3/3
A and B
A= $at < @linesB= $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
ABresult
0X0
100
111
205 17125 $at++;
206 17125 return $1;
207 5756 };
208  
209 5756 my $variant = $header->('variant', '[a-z0-9_= ]+');
210 5756 ▶ return $fail->($at + 1, 'variant') unless defined $variant;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $variant 41 5715 5756
211 5715 $record{variant} = $variant_of->($variant);
212 5715 ▶ return $fail->($at, 'variant') unless $record{variant};
Branch: 1 branch
BranchTrueFalseTotal
unless $record{"variant"} 3 5712 5715
213  
214 5712 $record{first} = $header->('first', 'light|dark');
215 5712 ▶ return $fail->($at + 1, 'first') unless defined $record{first};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"first"} 1 5711 5712
216  
217 5711 my $position = $header->('position', '[ld./ 1-7]+');
218 5711 ▶ if (defined $position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $position) 1 5710 5711
219 1 ▶ return $fail->($at, 'position') if validate_position($position);
Branch: 1 branch
BranchTrueFalseTotal
if validate_position($position) 0 1 1
220 1 my ($side, $pieces) = $position =~ / ([ld]) (\d)\z/;
221 return $fail->($at, 'position')
222 1 ▶ unless $pieces == $record{variant}{pieces} && $side eq substr($record{first}, 0, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $pieces == $record{"variant"}{"pieces"} and $side eq substr($record{"first"}, 0, 1) 0 1 1
Condition33%1/3
$pieces == $record{"variant"}{"pieces"} and $side eq substr($record{"first"}, 0, 1)
!ll&&!rl&&r
001
MC/DC0%0/2
$pieces == $record{"variant"}{"pieces"} and $side eq substr($record{"first"}, 0, 1)
$pieces == $record{"variant"}{"pieces"} $side eq substr($record{"first"}, 0, 1)
Truth table33%1/3
A and B
A= $pieces == $record{"variant"}{"pieces"}B= $side eq substr($record{"first"}, 0, 1)
ABresult
0X0
100
111
223 1 $record{position} = $position;
224 }
225  
226 5711 my $seed = $header->('seed', '(?:[0-9a-f]{2})+');
227 5711 ▶ $record{seed} = $seed if defined $seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seed 5698 13 5711
228 5711 ▶ my $bytes = defined $seed ? pack('H*', $seed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seed ? : 5698 13 5711
229  
230 5711 my $expect = $record{first};
231 5711 my $bind = $record{variant}{throw_on_26};
232 5711 ▶ for (; $at < @lines; $at++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @lines) 543467 5701 549168
233 543467 my $line = $lines[$at];
234 543467 my $number = $at + 1;
235 543467 ▶ return $fail->($number, 'after_result') if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 543466 543467
236  
237 543466 ▶ if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) 517 542949 543466
238 517 ▶ return $fail->($number, 'result') unless $RESULT_OK{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $RESULT_OK{$1} 0 517 517
239 517 my ($winner, $how) = split / /, $1;
240 517 $record{result} = { winner => $winner, how => $how };
241 517 $done = 1;
242 517 next;
243 }
244  
245 542949 ▶ my ($n, $letter, $roll, $sticks, $move) =
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ /\A([1-9][0-9]*)\. ([ld]) ([1-5])(?: ([01]{4}))?: (\S+)\z/ or return &$fail($number, "ply") 542949 0 542949
246 $line =~ /\A([1-9][0-9]*)\. ([ld]) ([1-5])(?: ([01]{4}))?: (\S+)\z/
247 or return $fail->($number, 'ply');
248 542949 my $throw = scalar @{ $record{plies} };
249 542949 ▶ return $fail->($number, 'number') unless $n == $throw + 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $n == $throw + 1 0 542949 542949
250  
251 542949 my $side = $SIDE_OF{$letter};
252 542949 ▶ return $fail->($number, 'side') unless $side eq $expect;
Branch: 1 branch
BranchTrueFalseTotal
unless $side eq $expect 4 542945 542949
253  
254 542945 ▶ if (defined $sticks) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sticks) 542926 19 542945
255 542926 my $light = ($sticks =~ tr/1//);
256 542926 ▶ return $fail->($number, 'sticks') unless Game::Senet::Sticks::roll_of($light) == $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Sticks::roll_of($light) == $roll 1 542925 542926
257 }
258 542944 ▶ if (defined $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bytes) 542921 23 542944
259 542921 my $thrown = Game::Senet::Sticks::throw_for($bytes, $throw);
260 542921 ▶ return $fail->($number, 'roll')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::Senet::Sticks::roll_of(Game::Senet::Sticks::light_of($thrown)) == $roll 3 542918 542921
261 unless Game::Senet::Sticks::roll_of(Game::Senet::Sticks::light_of($thrown)) == $roll;
262 542918 ▶ return $fail->($number, 'sticks') if defined $sticks && $sticks ne join('', @$thrown);
Branch: 1 branch
BranchTrueFalseTotal
if defined $sticks and $sticks ne join("", @$thrown) 0 542918 542918
Condition33%1/3
defined $sticks and $sticks ne join("", @$thrown)
!ll&&!rl&&r
05429180
MC/DC0%0/2
defined $sticks and $sticks ne join("", @$thrown)
defined $sticks $sticks ne join("", @$thrown)
Truth table33%1/3
A and B
A= defined $sticksB= $sticks ne join("", @$thrown)
ABresult
0X0
100
111
263 }
264  
265 542941 my %ply = (side => $side, roll => $roll + 0);
266 542941 ▶ $ply{sticks} = $sticks if defined $sticks;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sticks 542925 16 542941
267 542941 ▶ my $other = $side eq 'light' ? 'dark' : 'light';
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'light' ? : 274244 268697 542941
268 542941 my $again = Game::Senet::Sticks::extra_throw($roll);
269 542941 ▶ if ($move eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move eq '-') { } 3811 539130 542941
270 3811 $ply{move} = undef;
271 }
272 else {
273 539130 my ($parsed) = parse_move($move);
274 539130 ▶ return $fail->($number, 'move') unless $parsed && $move eq format_move($parsed);
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed and $move eq format_move($parsed) 1 539129 539130
Condition66%2/3
$parsed and $move eq format_move($parsed)
!ll&&!rl&&r
10539129
MC/DC50%1/2
$parsed and $move eq format_move($parsed)
$parsed $move eq format_move($parsed)
Truth table66%2/3
A and B
A= $parsedB= $move eq format_move($parsed)
ABresult
0X0
100
111
275 539129 $ply{move} = $move;
276 539129 ▶ $again ||= $bind && $parsed->{to} ne 'off' && $parsed->{from} < 26 && $parsed->{to} == 26;
Condition100%12/12
$again ||= $bind && $parsed->{"to"} ne "off" && $parsed->{"from"} < 26 && $parsed->{"to"} == 26
l!l&&r!l&&!r
20515712181321791
$bind && $parsed->{'to'} ne 'off' && $parsed->{'from'} < 26 && $parsed->{'to'} == 26
!ll&&!rl&&r
18537113642012181
$bind and $parsed->{"to"} ne "off" and $parsed->{"from"} < 26
!ll&&!rl&&r
16990115470148601
$bind and $parsed->{"to"} ne "off"
!ll&&!rl&&r
1633216580164071
MC/DC0%0/5
$again ||= $bind && $parsed->{"to"} ne "off" && $parsed->{"from"} < 26 && $parsed->{"to"} == 26
$again $bind $parsed->{"to"} ne "off" $parsed->{"from"} < 26 $parsed->{'to'} == 26
Truth table0%0/6
A ||= B and C and D && E
A= $againB= $bindC= $parsed->{"to"} ne "off"D= $parsed->{"from"} < 26E= $parsed->{'to'} == 26
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
277 }
278 542940 ▶ $expect = $again ? $side : $other;
Branch: 1 branch
BranchTrueFalseTotal
$again ? : 218566 324374 542940
279 542940 push @{ $record{plies} }, \%ply;
280 }
281 5701 return (\%record, undef);
282 }
283  
284 85 1;
285  
286 __END__
↑ Summary blib/lib/Game/Senet.pm »