blib/lib/Chess/PGN/EPD.pm

filter: Statementstmt 56.9% 326 / 572 Branchbran 45.0% 191 / 424 Conditioncond 62.6% 47 / 75 MC/DCmcdc 47.6% 20 / 42 Subroutinesub 79.1% 19 / 24 Podpod 100% 9 / 9 totaltotal 53.4% 612 / 1146 CC 273 SCAR 68.7
CC
273
Cov
53%
epdfromto
3906.0
epdlist
416.3
epdstr
249.1
CRAP 962.8
↑ Summary
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 package Chess::PGN::EPD;
5
6 11 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Chess::PGN::Moves;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use File::ShareDir qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use File::Slurper qw(read_text);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Cpanel::JSON::XS qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 11 require Exporter;
13
14 11 my ( $hECO, $hNIC, $hOpening );
15 11 my %hash = (
16 ECO => \$hECO,
17 NIC => \$hNIC,
18 Opening => \$hOpening
19 );
20
21 11 my ( $ECO_path, $NIC_path, $Opening_path ) = _GetPaths('Chess-PGN-EPD');
22
23 11 $hECO = decode_json read_text($ECO_path);
24 11 $hNIC = decode_json read_text($NIC_path);
25 11 $hOpening = decode_json read_text($Opening_path);
26
27 11 ▶sub _GetPaths {
Subroutine _GetPaths: called CC=1 SCAR=0.0
28 11 my $dist = shift;
29 11 my $dbECO = dist_file( $dist, 'ECO.db' );
30 11 my $dbNIC = dist_file( $dist, 'NIC.db' );
31 11 my $dbOpening = dist_file( $dist, 'Opening.db' );
32
33 11 return ( $dbECO, $dbNIC, $dbOpening );
34 }
35
36 11 our @ISA = qw(Exporter);
37 11 our @EXPORT = qw(
38 epdcode
39 epdset
40 epdfromto
41 epdstr
42 epdlist
43 epdgetboard
44 epdTaxonomy
45 psquares
46 %font2map
47 );
48 11 our $VERSION = '0.34';
49
50 11 our %font2map = (
51 'Chess Cases' => 'leschemelle',
52 'Chess Adventurer' => 'marroquin',
53 'Chess Alfonso-X' => 'marroquin',
54 'Chess Alpha' => 'bentzen1',
55 'Chess Berlin' => 'bentzen2',
56 'Chess Condal' => 'marroquin',
57 'Chess Harlequin' => 'marroquin',
58 'Chess Kingdom' => 'marroquin',
59 'Chess Leipzig' => 'marroquin',
60 'Chess Line' => 'marroquin',
61 'Chess Lucena' => 'marroquin',
62 'Chess Magnetic' => 'marroquin',
63 'Chess Mark' => 'marroquin',
64 'Chess Marroquin' => 'marroquin',
65 'Chess Maya' => 'marroquin',
66 'Chess Mediaeval' => 'marroquin',
67 'Chess Merida' => 'marroquin',
68 'Chess Millennia' => 'marroquin',
69 'Chess Miscel' => 'marroquin',
70 'Chess Montreal' => 'katch',
71 'Chess Motif' => 'marroquin',
72 'Chess Plain' => 'hickey',
73 'Chess Regular' => 'scott1',
74 'Chess Usual' => 'scott2',
75 'Chess Utrecht' => 'bodlaender',
76 'Tilburg' => 'tilburg',
77 'Traveller Standard V3' => 'cowderoy',
78 );
79
80 11 my %board = qw(
81 a1 R a2 P a7 p a8 r
82 b1 N b2 P b7 p b8 n
83 c1 B c2 P c7 p c8 b
84 d1 Q d2 P d7 p d8 q
85 e1 K e2 P e7 p e8 k
86 f1 B f2 P f7 p f8 b
87 g1 N g2 P g7 p g8 n
88 h1 R h2 P h7 p h8 r
89 );
90 11 my $Kc = 1;
91 11 my $Qc = 1;
92 11 my $kc = 1;
93 11 my $qc = 1;
94 11 my $w = 1;
95
96 11 my @onwhite = (
97 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0,
98 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1,
99 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
100 );
101
102 11 my %FontMap = (
103 hicky => {
104 OnBlack => 'OMASTLPNBRQK@',
105 OnWhite => 'omastlpnbrqk:',
106 SingleBox => '12345678',
107 DoubleBox => '!"#$%&\'(',
108 SingleRounded => '[]\^',
109 DoubleRounded => '<>;=/',
110 SingleLeftLegend => 'cdefghij',
111 DoubleLeftLegend => 'CDEFGHIJ',
112 SingleBottomLegend => 'wxyz{|}~',
113 DoubleBottomLegend => ')*+,-./0',
114 },
115 marroquin => {
116 OnBlack => 'OMVTWLPNBRQK+',
117 OnWhite => 'omvtwlpnbrqk ',
118 SingleBox => '12345789',
119 DoubleBox => '!"#$%/()',
120 SingleRounded => 'asdf',
121 DoubleRounded => 'ASDF',
122 SingleLeftLegend => "\300\301\302\303\034\305\306\307",
123 DoubleLeftLegend => "\340\341\342\343\344\345\346\347",
124 SingleBottomLegend => "\310\311\312\313\314\315\316\317",
125 DoubleBottomLegend => "\350\351\352\353\354\355\356\357",
126 },
127 leschemelle => {
128 OnBlack => 'OMVTWLPNBRQK+',
129 OnWhite => 'omvtwlpnbrqk ',
130 SingleBox => '12345789',
131 DoubleBox => '!"#$%/()',
132 SingleRounded => 'asdf',
133 DoubleRounded => 'ASDF',
134 SingleLeftLegend => "\300\301\302\303\034\305\306\307",
135 DoubleLeftLegend => "\340\341\342\343\344\345\346\347",
136 SingleBottomLegend => "\310\311\312\313\314\315\316\317",
137 DoubleBottomLegend => "\350\351\352\353\354\355\356\357",
138 },
139 linares => {
140 OnBlack => '0hg41i)HG$!Id',
141 OnWhite => 'pnbrqkPNBRQKw',
142 SingleBox => 'W_W[]W-W',
143 DoubleBox => 'cuC{}vlV',
144 SingleRounded => 'WWWW',
145 DoubleRounded => 'cCvV',
146 SingleLeftLegend => "\332\333\334\335\336\337\340\341",
147 DoubleLeftLegend => '(765&32%',
148 SingleBottomLegend => "\301\302\303\304\305\306\307\310",
149 DoubleBottomLegend => ',./9EFJM',
150 },
151 linares1 => {
152 OnBlack => '0hg41i)HG$!Id',
153 OnWhite => 'pnbrqkPNBRQKw',
154 SingleBox => '>;?:<A=@',
155 DoubleBox => '>;?:<A=@',
156 SingleRounded => '>?A@',
157 DoubleRounded => '>?A@',
158 SingleLeftLegend => '::::::::',
159 DoubleLeftLegend => '::::::::',
160 SingleBottomLegend => '========',
161 DoubleBottomLegend => '========',
162 },
163 linares2 => {
164 OnBlack => '0hg41i)HG$!Id',
165 OnWhite => 'pnbrqkPNBRQKw',
166 SingleBox => '^xY|yUz\\',
167 DoubleBox => '^xY|yUz\\',
168 SingleRounded => '^YU\\',
169 DoubleRounded => '^YU\\',
170 SingleLeftLegend => '||||||||',
171 DoubleLeftLegend => '||||||||',
172 SingleBottomLegend => 'zzzzzzzz',
173 DoubleBottomLegend => 'zzzzzzzz',
174 },
175 cowderoy => {
176 OnBlack => '$#!&%"*)\',+(0',
177 OnWhite => 'pnbrqkPNBRQK ',
178 SingleBox => '78946123',
179 DoubleBox => '78946123',
180 SingleRounded => '7913',
181 DoubleRounded => '7913',
182 SingleLeftLegend => '44444444',
183 DoubleLeftLegend => '44444444',
184 SingleBottomLegend => '22222222',
185 DoubleBottomLegend => '22222222',
186 },
187 bentzen1 => {
188 OnBlack => 'OJNTWLPHBRQK+',
189 OnWhite => 'ojntwlphbrqk ',
190 SingleBox => '!"#$%&\'(',
191 DoubleBox => '12345789',
192 SingleRounded => '!#&(',
193 DoubleRounded => '1379',
194 SingleLeftLegend => "\340\341\342\343\344\345\346\347",
195 DoubleLeftLegend => "\300\301\302\303\304\305\306\307",
196 SingleBottomLegend => "\350\351\352\353\354\355\356\357",
197 DoubleBottomLegend => "\310\311\312\313\314\315\316\317",
198 },
199 bentzen2 => {
200 OnBlack => 'OJNTWLPHBRQK+',
201 OnWhite => 'ojntwlphbrqk ',
202 SingleBox => '12345789',
203 DoubleBox => '12345789',
204 SingleRounded => '1379',
205 DoubleRounded => '1379',
206 SingleLeftLegend => '44444444',
207 DoubleLeftLegend => '44444444',
208 SingleBottomLegend => '88888888',
209 DoubleBottomLegend => '88888888',
210 },
211 scott1 => {
212 OnBlack => 'OJNTWLPHBRQK+',
213 OnWhite => 'ojntwlphbrqk*',
214 SingleBox => '(-)/\[_]',
215 DoubleBox => '(-)/\[_]',
216 SingleRounded => '(-)/\[_]',
217 DoubleRounded => '(-)/\[_]',
218 SingleLeftLegend => '////////',
219 DoubleLeftLegend => '////////',
220 SingleBottomLegend => '________',
221 DoubleBottomLegend => '________',
222 },
223 scott2 => {
224 OnBlack => 'OMVTWLPNBRQK+',
225 OnWhite => 'omvtwlpnbrqk ',
226 SingleBox => '12345789',
227 DoubleBox => '!"#$%/()',
228 SingleRounded => 'asdf',
229 DoubleRounded => 'ASDF',
230 SingleLeftLegend => '44444444',
231 DoubleLeftLegend => '$$$$$$$$',
232 SingleBottomLegend => '44444444',
233 DoubleBottomLegend => '$$$$$$$$',
234 },
235 bodlaender => {
236 OnBlack => 'OMVTWLomvtwl/',
237 OnWhite => 'PNBRQKpnbrqk ',
238 SingleBox => '51632748',
239 DoubleBox => '51632748',
240 SingleRounded => '51632748',
241 DoubleRounded => '51632748',
242 SingleLeftLegend => '33333333',
243 DoubleLeftLegend => '33333333',
244 SingleBottomLegend => '44444444',
245 DoubleBottomLegend => '44444444',
246 },
247 katch => {
248 OnBlack => 'OMVTWLPNBRQK/',
249 OnWhite => 'omvtwlpnbrqk ',
250 SingleBox => '12345789',
251 DoubleBox => '12345789',
252 SingleRounded => '12345789',
253 DoubleRounded => '12345789',
254 SingleLeftLegend => '44444444',
255 DoubleLeftLegend => '44444444',
256 SingleBottomLegend => '88888888',
257 DoubleBottomLegend => '88888888',
258 },
259 dummy => {
260 OnBlack => '',
261 OnWhite => '',
262 SingleBox => '',
263 DoubleBox => '',
264 SingleRounded => '',
265 DoubleRounded => '',
266 SingleLeftLegend => '',
267 DoubleLeftLegend => '',
268 SingleBottomLegend => '',
269 DoubleBottomLegend => '',
270 },
271 );
272
273 11 my %convertPalView = (
274 'r',
275 '<IMG SRC="jpc/br.gif">',
276 'n',
277 '<IMG SRC="jpc/bn.gif">',
278 'b',
279 '<IMG SRC="jpc/bb.gif">',
280 'q',
281 '<IMG SRC="jpc/bq.gif">',
282 'k',
283 '<IMG SRC="jpc/bk.gif">',
284 'p',
285 '<IMG SRC="jpc/bp.gif">',
286 'R',
287 '<IMG SRC="jpc/wr.gif">',
288 'N',
289 '<IMG SRC="jpc/wn.gif">',
290 'B',
291 '<IMG SRC="jpc/wb.gif">',
292 'Q',
293 '<IMG SRC="jpc/wq.gif">',
294 'K',
295 '<IMG SRC="jpc/wk.gif">',
296 'P',
297 '<IMG SRC="jpc/wp.gif">',
298 ' ',
299 '<IMG SRC="jpc/i.gif">',
300 '-',
301 '<IMG SRC="jpc/i.gif">',
302 );
303
304 63 ▶sub epdcode {
Subroutine epdcode: called CC=4 SCAR=13.9
Pod documented
305 63 my $key = shift;
306 63 my $epd = shift;
307 63 my $code;
308 63 my $h = ${ $hash{$key} };
309
310 63 for ( @{$epd} ) {
311 4649 $code = $h->{$_}; ## no critic
312 4649 ▶ last if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 54 4595 4649
313 }
314 63 ▶ return ( $code or 'Unknown' );
Condition100%2/2
$code || 'Unknown'
l!l
549
MC/DC100%1/1
$code || 'Unknown'
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
315 }
316
317 37 ▶sub epdset {
Subroutine epdset: called CC=10 SCAR=23.0
Pod documented
318 37 ▶ if ( my $epd = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $epd = shift()) { } 12 25 37
319 12 my @array = split( /\/|\s/, $epd );
320 12 my $file = '8';
321
322 12 %board = ();
323 12 $Kc = 0;
324 12 $Qc = 0;
325 12 $kc = 0;
326 12 $qc = 0;
327 12 for ( 0 .. 7 ) {
328 96 $array[$_] =~ s/(\d+)/'_' x $1/ge;
329 96 my @row = split( '', $array[$_] );
330 96 my $rank = 'a';
331 96 for my $piece (@row) {
332 768 ▶ $board{"$rank$file"} = $piece if $piece ne '_';
Branch: 1 branch
BranchTrueFalseTotal
if $piece ne "_" 384 384 768
333 768 $rank++;
334 }
335 96 $file--;
336 }
337 12 $w = ( $array[8] eq 'w' );
338 12 for ( split( '', $array[9] ) ) {
339 48 ▶ if ( $_ eq 'K' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($_ eq 'K') { } 12 36 48
elsif ($_ eq 'Q') { } 12 24 36
elsif ($_ eq 'k') { } 12 12 24
elsif ($_ eq 'q') { } 12 0 12
340 12 $Kc = 1;
341 }
342 elsif ( $_ eq 'Q' ) {
343 12 $Qc = 1;
344 }
345 elsif ( $_ eq 'k' ) {
346 12 $kc = 1;
347 }
348 elsif ( $_ eq 'q' ) {
349 12 $qc = 1;
350 }
351 }
352 }
353 else {
354 25 %board = qw(
355 a1 R a2 P a7 p a8 r
356 b1 N b2 P b7 p b8 n
357 c1 B c2 P c7 p c8 b
358 d1 Q d2 P d7 p d8 q
359 e1 K e2 P e7 p e8 k
360 f1 B f2 P f7 p f8 b
361 g1 N g2 P g7 p g8 n
362 h1 R h2 P h7 p h8 r
363 );
364 25 $w = 1;
365 25 $Kc = 1;
366 25 $Qc = 1;
367 25 $kc = 1;
368 25 $qc = 1;
369 }
370 37 return;
371 }
372
373 1 ▶sub epdstr {
Subroutine epdstr: called CC=27 SCAR=55.2
Pod documented
374 1 my %parameters = @_;
375 1 ▶ if ( $parameters{'board'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameters{"board"}) 0 1 1
376 0 my %board;
377 0 my $hashref = $parameters{'board'};
378
379 0 for ( keys %$hashref ) {
380 0 $board{$_} = $$hashref{$_};
381 }
382 0 $parameters{'epd'} = epd( 0, 0, 0, 0, 0, 0, %board );
383 }
384 1 my $epd = $parameters{'epd'};
385 1 my $type = lc( $parameters{'type'} );
386 1 my ( $border, $corner, $legend ) = ( 'single', 'square', 'no' );
387
388 1 ▶ $border = lc( $parameters{'border'} ) if exists( $parameters{'border'} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $parameters{"border"} 0 1 1
389 1 ▶ $corner = lc( $parameters{'corner'} ) if exists( $parameters{'corner'} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $parameters{"corner"} 0 1 1
390 1 ▶ $legend = lc( $parameters{'legend'} ) if exists( $parameters{'legend'} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $parameters{"legend"} 0 1 1
391 1 my @array = split( /\/|\s/, $epd );
392 1 my @board;
393 1 ▶ if ( $type eq 'diagram' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'diagram') { } 0 1 1
elsif ($type eq 'text') { } 0 1 1
elsif ($type eq 'palview') { } 0 1 1
elsif ($type eq 'latex') { } 1 0 1
elsif ($type eq 'tilburg') { } 0 0 0
394 0 for ( 0 .. 7 ) {
395 0 $array[$_] =~ s/(\d+)/'_' x $1/ge;
396 0 $array[$_]
397 0 ▶ =~ s/_/(((pos $array[$_]) % 2) xor ($_ % 2)) ? '-' : ' '/ge;
Branch: 1 branch
BranchTrueFalseTotal
pos($array[$_]) % 2 ^^ $_ % 2 ? : 0 0 0
Condition0%0/4
pos($array[$_]) % 2 xor $_ % 2
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
pos($array[$_]) % 2 xor $_ % 2
pos($array[$_]) % 2 $_ % 2
Truth table0%0/4
A xor B
A= pos($array[$_]) % 2B= $_ % 2
ABresult
110
101
011
000
398 0 push( @board, 8 - $_ . " " . $array[$_] );
399 }
400 0 push( @board, ' abcdefgh' );
401 }
402 elsif ( $type eq 'text' ) {
403 0 for ( 0 .. 7 ) {
404 0 $array[$_] =~ s/(\d+)/'_' x $1/ge;
405 0 $array[$_]
406 0 ▶ =~ s/_/(((pos $array[$_]) % 2) xor ($_ % 2)) ? '-' : ' '/ge;
Branch: 1 branch
BranchTrueFalseTotal
pos($array[$_]) % 2 ^^ $_ % 2 ? : 0 0 0
Condition0%0/4
pos($array[$_]) % 2 xor $_ % 2
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
pos($array[$_]) % 2 xor $_ % 2
pos($array[$_]) % 2 $_ % 2
Truth table0%0/4
A xor B
A= pos($array[$_]) % 2B= $_ % 2
ABresult
110
101
011
000
407 0 push( @board, $array[$_] );
408 }
409 }
410 elsif ( $type eq 'palview' ) {
411 0 my @diagram;
412 my $table;
413
414 0 for ( 0 .. 7 ) {
415 0 $array[$_] =~ s/(\d+)/'_' x $1/ge;
416 0 $array[$_]
417 0 ▶ =~ s/_/(((pos $array[$_]) % 2) xor ($_ % 2)) ? '-' : ' '/ge;
Branch: 1 branch
BranchTrueFalseTotal
pos($array[$_]) % 2 ^^ $_ % 2 ? : 0 0 0
Condition0%0/4
pos($array[$_]) % 2 xor $_ % 2
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
pos($array[$_]) % 2 xor $_ % 2
pos($array[$_]) % 2 $_ % 2
Truth table0%0/4
A xor B
A= pos($array[$_]) % 2B= $_ % 2
ABresult
110
101
011
000
418 0 push( @diagram, $array[$_] );
419 }
420 0 for (@diagram) {
421 0 for ( split(//) ) {
422 0 $table .= $convertPalView{$_};
423 }
424 0 $table .= "<BR>";
425 0 push( @board, $table );
426 0 $table = '';
427 }
428 }
429 elsif ( $type eq 'latex' ) {
430 1 push( @board, '\\begin{diagram}' );
431 1 push( @board, '\\board' );
432 1 for ( 0 .. 7 ) {
433 8 $array[$_] =~ s/(\d+)/'_' x $1/ge;
434 8 $array[$_]
435 33 ▶ =~ s/_/(((pos $array[$_]) % 2) xor ($_ % 2)) ? '*' : ' '/ge;
Branch: 1 branch
BranchTrueFalseTotal
pos($array[$_]) % 2 ^^ $_ % 2 ? : 15 18 33
Condition100%4/4
pos($array[$_]) % 2 xor $_ % 2
l&&rl&&!r!l&&r!l&&!r
87810
MC/DC100%2/2
pos($array[$_]) % 2 xor $_ % 2
pos($array[$_]) % 2 $_ % 2
Truth table100%4/4
A xor B
A= pos($array[$_]) % 2B= $_ % 2
ABresult
110
101
011
000
436 8 push( @board, '{' . $array[$_] . '}' );
437 }
438 1 push( @board, '\\end{diagram}' );
439 }
440 elsif ( $type eq 'tilburg' ) {
441 0 for ( 0 .. 7 ) {
442 0 $array[$_] =~ s/(\d+)/'_' x $1/ge;
443 0 $array[$_]
444 0 =~ s/([pnbrqkPNBRQK_])/_mappiece(pos $array[$_],$_,$1,"\341\345\351\355\361\365\337\343\347\353\357\363
445 \335","\340\344\350\354\360\364\336\342\346\352\356\362\334")/ge;
446 0 push( @board, $array[$_] );
447 }
448 }
449 else {
450 0 @board = _configureboard( $type, $border, $corner, $legend );
451 0 for ( 0 .. 7 ) {
452 0 $array[$_] =~ s/(\d+)/'_' x $1/ge;
453 0 $array[$_]
454 =~ s/([pnbrqkPNBRQK_])/_mappiece(pos $array[$_],$_,$1,$FontMap{$type}{'OnBlack'},$FontMap{$type}
455 0 {'OnWhite'})/ge;
456 0 substr( $board[ $_ + 1 ], 1, 8 ) = $array[$_];
457 }
458 }
459 1 return @board;
460 }
461
462 0 ▶sub _configureboard {
Subroutine _configureboard: not called CC=9 SCAR=45.0
463 0 my $type = shift;
464 0 my $border = shift;
465 0 my $corner = shift;
466 0 my $legend = shift;
467 0 my $single = $border eq 'single';
468 0 ▶ my $box = $FontMap{$type}{ $single ? 'SingleBox' : 'DoubleBox' };
Branch: 1 branch
BranchTrueFalseTotal
$single ? : 0 0 0
469 0 my @board;
470
471 0 ▶ if ( $corner eq 'rounded' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($corner eq "rounded") 0 0 0
472 my $corners
473 0 ▶ = $FontMap{$type}{ $single ? 'SingleRounded' : 'DoubleRounded' };
Branch: 1 branch
BranchTrueFalseTotal
$single ? : 0 0 0
474
475 0 substr( $box, 0, 1 ) = substr( $corners, 0, 1 );
476 0 substr( $box, 2, 1 ) = substr( $corners, 1, 1 );
477 0 substr( $box, 5, 1 ) = substr( $corners, 2, 1 );
478 0 substr( $box, 7, 1 ) = substr( $corners, 3, 1 );
479 }
480 0 push( @board,
481 substr( $box, 0, 1 )
482 . substr( $box, 1, 1 ) x 8
483 . substr( $box, 2, 1 ) );
484 0 for ( 0 .. 7 ) {
485 0 push( @board, substr( $box, 3, 1 ) . ' ' x 8 . substr( $box, 4, 1 ) );
486 }
487 0 push( @board,
488 substr( $box, 5, 1 )
489 . substr( $box, 6, 1 ) x 8
490 . substr( $box, 7, 1 ) );
491 0 ▶ if ( $legend eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($legend eq "yes") 0 0 0
492 my $left = $FontMap{$type}{
493 0 ▶ $single
Branch: 1 branch
BranchTrueFalseTotal
$single ? : 0 0 0
494 ? 'SingleLeftLegend'
495 : 'DoubleLeftLegend'
496 };
497 my $bottom = $FontMap{$type}{
498 0 ▶ $single
Branch: 1 branch
BranchTrueFalseTotal
$single ? : 0 0 0
499 ? 'SingleBottomLegend'
500 : 'DoubleBottomLegend'
501 };
502
503 0 for ( 1 .. 8 ) {
504 0 substr( $board[$_], 0, 1 ) = substr( $left, $_ - 1, 1 );
505 }
506 0 substr( $board[-1], 1, 8 ) = $bottom;
507
508 }
509 0 return @board;
510 }
511
512 0 ▶sub _mappiece {
Subroutine _mappiece: not called CC=2 SCAR=17.9
513 0 my $x = shift;
514 0 my $y = shift;
515 0 my $piece = shift;
516 0 my $ifonblack = shift;
517 0 my $ifonwhite = shift;
518 0 my $onwhite = $onwhite[ ( $y * 8 ) + $x ];
519 0 my $which = index( 'pnbrqkPNBRQK_', $piece );
520
521 0 ▶ return substr( $onwhite ? $ifonwhite : $ifonblack, $which, 1 );
Branch: 1 branch
BranchTrueFalseTotal
$onwhite ? : 0 0 0
522 }
523
524 12 ▶sub epdgetboard {
Subroutine epdgetboard: called CC=2 SCAR=6.9
Pod documented
525 12 ▶ if ( my $epd = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $epd = shift()) 9 3 12
526 9 epdset($epd);
527 }
528 12 return $w, $Kc, $Qc, $kc, $qc, %board;
529 }
530
531 0 ▶sub epdfromto {
Subroutine epdfromto: not called CC=62 SCAR=82.7
Pod documented
532 0 my @moves = @_;
533 0 my @movelist;
534
535 0 epdset();
536 0 for (@moves) {
537 0 ▶ if ($_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 0 0 0
538 0 my ( $piece, $to, $from, $promotion ) = _movetype( $w, $_ );
539 0 my $enpassant;
540 0 my $ep = '-';
541 0 ▶ my $castles = /O/ ? $_ : '';
Branch: 1 branch
BranchTrueFalseTotal
/O/u ? : 0 0 0
542
543 0 ▶ $Kc = 0 if $to eq 'h1';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "h1" 0 0 0
544 0 ▶ $Qc = 0 if $to eq 'a1';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "a1" 0 0 0
545 0 ▶ $kc = 0 if $to eq 'h8';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "h8" 0 0 0
546 0 ▶ $qc = 0 if $to eq 'a8';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "a8" 0 0 0
547
548 0 ▶ if ( $piece eq "P" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($piece eq 'P') { } 0 0 0
elsif ($piece eq 'KR') { } 0 0 0
549 0 ▶ $piece = "p" if not $w;
Branch: 1 branch
BranchTrueFalseTotal
unless $w 0 0 0
550 0 ▶ $promotion = lc($promotion) if $promotion and not $w;
Branch: 1 branch
BranchTrueFalseTotal
if $promotion and not $w 0 0 0
Condition0%0/3
$promotion and not $w
!ll&&!rl&&r
000
MC/DC0%0/2
$promotion and not $w
$promotion not $w
Truth table0%0/3
A and not(B)
A= $promotionB= not $w
ABresult
0X0
100
111
551 0 ▶ if ($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) { } 0 0 0
552 0 $from .= substr( $to, 1, 1 );
553 0 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 0 0 0
554 0 substr( $from, 1, 1 ) -= 1;
555 }
556 else {
557 0 $from++;
558 }
559 }
560 else {
561 0 $from = $to;
562
563 0 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 0 0 0
564 0 substr( $from, 1, 1 ) -= 1;
565 0 ▶ unless ( $board{$from} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$from}) 0 0 0
566 0 $ep = $from;
567 0 substr( $from, 1, 1 ) -= 1;
568 }
569 }
570 else {
571 0 $from++;
572 0 ▶ unless ( $board{$from} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$from}) 0 0 0
573 0 $ep = $from;
574 0 $from++;
575 }
576 }
577 }
578
579 0 ▶ if ( substr( $from, 0, 1 ) ne substr( $to, 0, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($from, 0, 1) ne substr($to, 0, 1)) 0 0 0
580 0 ▶ if ( not $board{$to} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$to}) 0 0 0
581 0 $enpassant = $to;
582 0 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 0 0 0
583 0 substr( $enpassant, 1, 1 )
584 = chr(
585 ord( substr( $enpassant, 1, 1 ) ) - 1 );
586 }
587 else {
588 0 substr( $enpassant, 1, 1 )
589 = chr(
590 ord( substr( $enpassant, 1, 1 ) ) + 1 );
591 }
592 0 $board{$enpassant} = undef;
593 0 ▶ $enpassant = defined($enpassant) ? $enpassant : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $enpassant ? : 0 0 0
594 0 ▶ $from = defined($from) ? $from : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 0 0 0
595 0 ▶ $to = defined($to) ? $to : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $to ? : 0 0 0
596 }
597 }
598 ( $board{$to}, $board{$from} )
599 0 ▶ = ( $promotion ? $promotion : $board{$from}, undef );
Branch: 1 branch
BranchTrueFalseTotal
$promotion ? : 0 0 0
600 0 ▶ $piece = defined($piece) ? $piece : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $piece ? : 0 0 0
601 0 ▶ $from = defined($from) ? $from : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 0 0 0
602 0 ▶ $to = defined($to) ? $to : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $to ? : 0 0 0
603 0 ▶ $promotion = defined($promotion) ? $promotion : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $promotion ? : 0 0 0
604 }
605 elsif ( $piece eq "KR" ) {
606 0 my ( $k_from, $r_from ) = unpack( "A2A2", $from );
607 0 my ( $k_to, $r_to ) = unpack( "A2A2", $to );
608
609 ( $board{$k_to}, $board{$k_from} )
610 0 = ( $board{$k_from}, undef );
611 ( $board{$r_to}, $board{$r_from} )
612 0 = ( $board{$r_from}, undef );
613 0 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 0 0 0
614 0 $Kc = $Qc = 0;
615 }
616 else {
617 0 $kc = $qc = 0;
618 }
619 }
620 else {
621 0 my @piece_at;
622 my @fromlist;
623
624 0 ▶ $piece = lc($piece) if not $w;
Branch: 1 branch
BranchTrueFalseTotal
unless $w 0 0 0
625 0 @piece_at = psquares( $piece, %board );
626 0 ▶ if ($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) 0 0 0
627 0 my @tmp;
628
629 0 ▶ $from = defined($from) ? $from : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 0 0 0
630 0 ▶ if ( $from =~ /[a-h]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from =~ /[a-h]/u) { } 0 0 0
631 0 for (@piece_at) {
632 0 ▶ push( @tmp, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, 0, 1) eq $from 0 0 0
633 if ( substr( $_, 0, 1 ) eq $from );
634 }
635 }
636 else {
637
638 0 for (@piece_at) {
639 0 ▶ push( @tmp, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, 1, 1) eq $from 0 0 0
640 if ( substr( $_, 1, 1 ) eq $from );
641 }
642 }
643 0 @piece_at = @tmp;
644 }
645
646 0 for my $square (@piece_at) {
647 0 for ( @{ $move_table{ uc($piece) }{$square} } ) {
648 0 ▶ push( @fromlist, $square ) if $_ eq $to;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $to 0 0 0
649 }
650 }
651 0 ▶ if ( scalar(@fromlist) != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @fromlist != 1) { } 0 0 0
652 0 for (@fromlist) {
653 0 ▶ if ( _canmove( $piece, $to, $_, %board )
Branch: 1 branch
BranchTrueFalseTotal
if (_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)) 0 0 0
Condition0%0/3
_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)
!ll&&!rl&&r
000
MC/DC0%0/2
_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)
_canmove($piece, $to, $_, %board) _isLegal($w, $_, $to, %board)
Truth table0%0/3
A and B
A= _canmove($piece, $to, $_, %board)B= _isLegal($w, $_, $to, %board)
ABresult
0X0
100
111
654 and _isLegal( $w, $_, $to, %board ) )
655 {
656 0 $from = $_;
657 0 last;
658 }
659 }
660 }
661 else {
662 0 $from = $fromlist[0];
663 }
664 0 ▶ if ( $piece =~ /[RrKk]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($piece =~ /[RrKk]/u) 0 0 0
665 0 ▶ if ( $piece eq 'R' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($piece eq 'R') { } 0 0 0
elsif ($piece eq 'r') { } 0 0 0
elsif ($piece eq 'K') { } 0 0 0
666 0 ▶ $Kc = 0 if $from eq 'h1';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "h1" 0 0 0
667 0 ▶ $Qc = 0 if $from eq 'a1';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "a1" 0 0 0
668 }
669 elsif ( $piece eq 'r' ) {
670 0 ▶ $kc = 0 if $from eq 'h8';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "h8" 0 0 0
671 0 ▶ $qc = 0 if $from eq 'a8';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "a8" 0 0 0
672 }
673 elsif ( $piece eq 'K' ) {
674 0 $Kc = $Qc = 0;
675 }
676 else {
677 0 $kc = $qc = 0;
678 }
679 }
680 0 ( $board{$to}, $board{$from} ) = ( $board{$from}, undef );
681 0 ▶ $piece = defined($piece) ? $piece : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $piece ? : 0 0 0
682 0 ▶ $from = defined($from) ? $from : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 0 0 0
683 0 ▶ $to = defined($to) ? $to : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $to ? : 0 0 0
684 }
685 0 ▶ my $movehash = {
Branch: 6 branches
BranchTrueFalseTotal
defined $piece ? : 0 0 0
defined $from ? : 0 0 0
defined $to ? : 0 0 0
defined $promotion ? : 0 0 0
defined $enpassant ? : 0 0 0
defined $castles ? : 0 0 0
686 piece => defined($piece) ? $piece : '',
687 from => defined($from) ? $from : '',
688 to => defined($to) ? $to : '',
689 promotion => defined($promotion) ? $promotion : '',
690 enpassant => defined($enpassant) ? $enpassant : '',
691 castles => defined($castles) ? $castles : '',
692 };
693 0 push( @movelist, $movehash );
694 0 $w ^= 1;
695 }
696 }
697 0 %board = ();
698 0 return @movelist;
699 }
700
701 25 ▶sub epdlist {
Subroutine epdlist: called CC=80 SCAR=60.3
Pod documented
702 25 my @moves = @_;
703 25 my $debug = 0;
704 25 my @epdlist;
705 25 my $lineno = 1;
706
707 25 ▶ if ( scalar @moves and $moves[-1] eq '1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @moves and $moves[-1] eq 1) 0 25 25
Condition66%2/3
scalar @moves and $moves[-1] eq 1
!ll&&!rl&&r
3220
MC/DC0%0/2
scalar @moves and $moves[-1] eq 1
scalar @moves $moves[-1] eq 1
Truth table66%2/3
A and B
A= scalar @movesB= $moves[-1] eq 1
ABresult
0X0
100
111
708 0 $debug = 1;
709 0 pop @moves;
710 0 ▶ if (%board) {
Branch: 1 branch
BranchTrueFalseTotal
if (%board) { } 0 0 0
711 0 print "\%board initialized\n";
712 }
713 else {
714 0 print "\%board uninitialized\n";
715 }
716 }
717 25 epdset();
718 25 for (@moves) {
719 1645 ▶ _Print(%board) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1645 1645
720 1645 ▶ if ($_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 1645 0 1645
721 1645 my ( $piece, $to, $from, $promotion ) = _movetype( $w, $_ );
722 1645 my $enpassant;
723 1645 my $ep = '-';
724
725 1645 ▶ $Kc = 0 if $to eq 'h1';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "h1" 8 1637 1645
726 1645 ▶ $Qc = 0 if $to eq 'a1';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "a1" 1 1644 1645
727 1645 ▶ $kc = 0 if $to eq 'h8';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "h8" 7 1638 1645
728 1645 ▶ $qc = 0 if $to eq 'a8';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "a8" 10 1635 1645
729
730 1645 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1645 1645
731 0 print "Move[$lineno]='$_'";
732 0 $lineno++;
733 0 ▶ if ($piece) {
Branch: 1 branch
BranchTrueFalseTotal
if ($piece) 0 0 0
734 0 print ", piece='$piece'";
735 0 ▶ print ", to='$to'" if $to;
Branch: 1 branch
BranchTrueFalseTotal
if $to 0 0 0
736 0 ▶ print ", from='$from'" if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
737 0 ▶ print ", promotion='$promotion'" if $promotion;
Branch: 1 branch
BranchTrueFalseTotal
if $promotion 0 0 0
738 }
739 0 print "\n";
740 }
741
742 1645 ▶ if ( $piece eq "P" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($piece eq 'P') { } 435 1210 1645
elsif ($piece eq 'KR') { } 36 1174 1210
743 435 ▶ $piece = "p" if not $w;
Branch: 1 branch
BranchTrueFalseTotal
unless $w 181 254 435
744 435 ▶ $promotion = lc($promotion) if $promotion and not $w;
Branch: 1 branch
BranchTrueFalseTotal
if $promotion and not $w 0 435 435
Condition66%2/3
$promotion and not $w
!ll&&!rl&&r
42870
MC/DC0%0/2
$promotion and not $w
$promotion not $w
Truth table66%2/3
A and not(B)
A= $promotionB= not $w
ABresult
0X0
100
111
745 435 ▶ if ($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) { } 109 326 435
746 109 $from .= substr( $to, 1, 1 );
747 109 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 59 50 109
748 59 substr( $from, 1, 1 ) -= 1;
749 }
750 else {
751
752 50 $from++;
753 }
754 }
755 else {
756 326 $from = $to;
757
758 326 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 195 131 326
759 195 substr( $from, 1, 1 ) -= 1;
760 195 ▶ unless ( $board{$from} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$from}) 53 142 195
761 53 $ep = $from;
762 53 substr( $from, 1, 1 ) -= 1;
763 }
764 }
765 else {
766 131 $from++;
767 131 ▶ unless ( $board{$from} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$from}) 47 84 131
768 47 $ep = $from;
769 47 $from++;
770 }
771 }
772 }
773
774 435 ▶ if ( substr( $from, 0, 1 ) ne substr( $to, 0, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($from, 0, 1) ne substr($to, 0, 1)) 109 326 435
775 109 ▶ if ( not $board{$to} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($board{$to}) 0 109 109
776 0 $enpassant = $to;
777 0 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 0 0 0
778 0 substr( $enpassant, 1, 1 )
779 = chr(
780 ord( substr( $enpassant, 1, 1 ) ) - 1 );
781 }
782 else {
783 0 substr( $enpassant, 1, 1 )
784 = chr(
785 ord( substr( $enpassant, 1, 1 ) ) + 1 );
786 }
787 0 $board{$enpassant} = undef;
788 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
789 0 ▶ print "\$enpassant='$enpassant' " if $enpassant;
Branch: 1 branch
BranchTrueFalseTotal
if $enpassant 0 0 0
790 0 ▶ print "\$from='$from' " if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
791 0 ▶ print "\$to='$to'" if $to;
Branch: 1 branch
BranchTrueFalseTotal
if $to 0 0 0
792 0 print "\n";
793 }
794 }
795 }
796 ( $board{$to}, $board{$from} )
797 435 ▶ = ( $promotion ? $promotion : $board{$from}, undef );
Branch: 1 branch
BranchTrueFalseTotal
$promotion ? : 7 428 435
798 435 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 435 435
799 0 ▶ print "\$piece='$piece' " if $piece;
Branch: 1 branch
BranchTrueFalseTotal
if $piece 0 0 0
800 0 ▶ print "\$from='$from' " if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
801 0 ▶ print "\$to='$to' " if $to;
Branch: 1 branch
BranchTrueFalseTotal
if $to 0 0 0
802 0 ▶ print "\$promotion='$promotion' " if $promotion;
Branch: 1 branch
BranchTrueFalseTotal
if $promotion 0 0 0
803 }
804 435 push( @epdlist, epd( $w, $Kc, $Qc, $kc, $qc, $ep, %board ) );
805 435 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 435 435
806 0 print "$epdlist[-1]\n";
807 }
808 }
809 elsif ( $piece eq "KR" ) {
810 36 my ( $k_from, $r_from ) = unpack( "A2A2", $from );
811 36 my ( $k_to, $r_to ) = unpack( "A2A2", $to );
812
813 ( $board{$k_to}, $board{$k_from} )
814 36 = ( $board{$k_from}, undef );
815 ( $board{$r_to}, $board{$r_from} )
816 36 = ( $board{$r_from}, undef );
817 36 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 18 18 36
818 18 $Kc = $Qc = 0;
819 }
820 else {
821 18 $kc = $qc = 0;
822 }
823 36 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 36 36
824 0 ▶ print $w ? "White" : "Black",
Branch: 1 branch
BranchTrueFalseTotal
$w ? : 0 0 0
825 " castles from $k_from to $k_to\n";
826 }
827 36 push( @epdlist, epd( $w, $Kc, $Qc, $kc, $qc, $ep, %board ) );
828 36 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 36 36
829 0 print "$epdlist[-1]\n";
830 }
831 }
832 else {
833 1174 my @piece_at;
834 my @fromlist;
835
836 1174 ▶ $piece = lc($piece) if not $w;
Branch: 1 branch
BranchTrueFalseTotal
unless $w 620 554 1174
837 1174 @piece_at = psquares( $piece, %board );
838 1174 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1174 1174
839 0 ▶ print "\@piece_at=", join( ",", @piece_at ), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if @piece_at 0 0 0
840 if @piece_at;
841 }
842 1174 ▶ if ($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) 80 1094 1174
843 80 my @tmp;
844
845 80 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 80 80
846 0 ▶ print "\$from='$from'\n" if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
847 }
848 80 ▶ if ( $from =~ /[a-h]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from =~ /[a-h]/u) { } 77 3 80
849 77 for (@piece_at) {
850 238 ▶ push( @tmp, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, 0, 1) eq $from 83 155 238
851 if ( substr( $_, 0, 1 ) eq $from );
852 }
853 }
854 else {
855
856 3 for (@piece_at) {
857 12 ▶ push( @tmp, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, 1, 1) eq $from 3 9 12
858 if ( substr( $_, 1, 1 ) eq $from );
859 }
860 }
861 80 @piece_at = @tmp;
862 }
863
864 1174 for my $square (@piece_at) {
865 1763 for ( @{ $move_table{ uc($piece) }{$square} } ) {
866 18454 ▶ push( @fromlist, $square ) if $_ eq $to;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $to 1232 17222 18454
867 }
868 }
869 1174 ▶ print "scalar \@fromlist = ", scalar(@fromlist), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1174 1174
870 if $debug;
871 1174 ▶ if ( scalar(@fromlist) != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @fromlist != 1) { } 70 1104 1174
872 70 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 70 70
873 0 ▶ print "\@fromlist=", join( ",", @fromlist ), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if @fromlist 0 0 0
874 if @fromlist;
875 }
876 70 for (@fromlist) {
877 94 ▶ if ( _canmove( $piece, $to, $_, %board )
Branch: 1 branch
BranchTrueFalseTotal
if (_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)) 64 30 94
Condition100%3/3
_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)
!ll&&!rl&&r
22864
MC/DC100%2/2
_canmove($piece, $to, $_, %board) and _isLegal($w, $_, $to, %board)
_canmove($piece, $to, $_, %board) _isLegal($w, $_, $to, %board)
Truth table100%3/3
A and B
A= _canmove($piece, $to, $_, %board)B= _isLegal($w, $_, $to, %board)
ABresult
0X0
100
111
878 and _isLegal( $w, $_, $to, %board ) )
879 {
880 64 $from = $_;
881 64 last;
882 }
883 }
884 }
885 else {
886 1104 $from = $fromlist[0];
887 }
888 1174 ▶ if ( $piece =~ /[RrKk]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($piece =~ /[RrKk]/u) 537 637 1174
889 537 ▶ if ( $piece eq 'R' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($piece eq 'R') { } 200 337 537
elsif ($piece eq 'r') { } 95 242 337
elsif ($piece eq 'K') { } 32 210 242
890 200 ▶ $Kc = 0 if $from eq 'h1';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "h1" 3 197 200
891 200 ▶ $Qc = 0 if $from eq 'a1';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "a1" 15 185 200
892 }
893 elsif ( $piece eq 'r' ) {
894 95 ▶ $kc = 0 if $from eq 'h8';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "h8" 0 95 95
895 95 ▶ $qc = 0 if $from eq 'a8';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "a8" 18 77 95
896 }
897 elsif ( $piece eq 'K' ) {
898 32 $Kc = $Qc = 0;
899 }
900 else {
901 210 $kc = $qc = 0;
902 }
903 }
904 1174 ( $board{$to}, $board{$from} ) = ( $board{$from}, undef );
905 1174 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1174 1174
906 0 ▶ print "\@piece_at=", join( ",", @piece_at ), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if @piece_at 0 0 0
907 if @piece_at;
908 0 ▶ print "\$piece='$piece' " if $piece;
Branch: 1 branch
BranchTrueFalseTotal
if $piece 0 0 0
909 0 ▶ print "\$from='$from' " if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
910 0 ▶ print "\$to='$to' " if $to;
Branch: 1 branch
BranchTrueFalseTotal
if $to 0 0 0
911 }
912 1174 push( @epdlist, epd( $w, $Kc, $Qc, $kc, $qc, $ep, %board ) );
913 1174 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1174 1174
914 0 print "$epdlist[-1]\n";
915 }
916 1174 ▶ if ( not $from ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from) 0 1174 1174
917 0 _ShowPieces(%board);
918 0 _Print(%board);
919 0 print "From undefined\n";
920 0 exit;
921 }
922 }
923 1645 $w ^= 1;
924 }
925 }
926 25 %board = ();
927 25 return @epdlist;
928 }
929
930 72 ▶sub _isLegal {
Subroutine _isLegal: called CC=13 SCAR=25.6
931 72 my ( $w, $from, $to, %board ) = @_;
932 72 my %board_copy = %board;
933 72 my $kings_square;
934 my @attack_list;
935
936 72 ( $board_copy{$to}, $board_copy{$from} ) = ( $board_copy{$from}, undef );
937 72 ▶ my $findking = $w ? 'K' : 'k';
Branch: 1 branch
BranchTrueFalseTotal
$w ? : 58 14 72
938 72 for ( keys %board_copy ) {
939 1864 ▶ if ( $board_copy{$_} and ( $board_copy{$_} eq $findking ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($board_copy{$_} and $board_copy{$_} eq $findking) 72 1792 1864
Condition100%3/3
$board_copy{$_} and $board_copy{$_} eq $findking
!ll&&!rl&&r
113465872
MC/DC100%2/2
$board_copy{$_} and $board_copy{$_} eq $findking
$board_copy{$_} $board_copy{$_} eq $findking
Truth table100%3/3
A and B
A= $board_copy{$_}B= $board_copy{$_} eq $findking
ABresult
0X0
100
111
940 72 $kings_square = $_;
941 72 last;
942 }
943 }
944 72 ▶ my $mask = $w ? 'qrnbp' : 'QRNBP';
Branch: 1 branch
BranchTrueFalseTotal
$w ? : 58 14 72
945 72 for my $square ( keys %board_copy ) {
946 3806 ▶ if ( $board_copy{$square} and $mask =~ /$board_copy{$square}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($board_copy{$square} and $mask =~ /$board_copy{$square}/u) 546 3260 3806
Condition100%3/3
$board_copy{$square} and $mask =~ /$board_copy{$square}/u
!ll&&!rl&&r
2394866546
MC/DC100%2/2
$board_copy{$square} and $mask =~ /$board_copy{$square}/u
$board_copy{$square} $mask =~ /$board_copy{$square}/u
Truth table100%3/3
A and B
A= $board_copy{$square}B= $mask =~ /$board_copy{$square}/u
ABresult
0X0
100
111
947 546 for ( @{ $move_table{ uc( $board_copy{$square} ) }{$square} } ) {
948 3049 ▶ push( @attack_list, $square ) if $_ eq $kings_square;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $kings_square 16 3033 3049
949 }
950 }
951 }
952 72 for (@attack_list) {
953 16 ▶ if ( _canmove( $board_copy{$_}, $kings_square, $_, %board_copy ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_canmove($board_copy{$_}, $kings_square, $_, %board_copy)) 8 8 16
954 8 return 0;
955 }
956 }
957 64 return 1;
958 }
959
960 0 ▶sub _ShowPieces {
Subroutine _ShowPieces: not called CC=3 SCAR=24.8
961 0 my %board = @_;
962
963 0 for my $square ( keys %board ) {
964 0 my $piece = $board{$square};
965 0 ▶ next unless $piece;
Branch: 1 branch
BranchTrueFalseTotal
unless $piece 0 0 0
966 0 print "'$square' == ", $piece, "\n";
967 }
968 0 return;
969 }
970
971 0 ▶sub _Print {
Subroutine _Print: not called CC=5 SCAR=34.0
972 0 my (%board) = @_;
973 0 my $whitesquare = 1;
974 0 my @rows = (
975 [qw(a8 b8 c8 d8 e8 f8 g8 h8)], [qw(a7 b7 c7 d7 e7 f7 g7 h7)],
976 [qw(a6 b6 c6 d6 e6 f6 g6 h6)], [qw(a5 b5 c5 d5 e5 f5 g5 h5)],
977 [qw(a4 b4 c4 d4 e4 f4 g4 h4)], [qw(a3 b3 c3 d3 e3 f3 g3 h3)],
978 [qw(a2 b2 c2 d2 e2 f2 g2 h2)], [qw(a1 b1 c1 d1 e1 f1 g1 h1)]
979 );
980
981 0 for ( 0 .. 7 ) {
982 0 print "\n", 8 - $_, " ";
983 0 for ( @{ $rows[$_] } ) {
984 0 ▶ if ( $board{$_} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($board{$_}) { } 0 0 0
elsif ($whitesquare) { } 0 0 0
985 0 print $board{$_};
986 }
987 elsif ($whitesquare) {
988 0 print ' ';
989 }
990 else {
991 0 print '-';
992 }
993 0 $whitesquare ^= 1;
994 }
995 0 $whitesquare ^= 1;
996 }
997 0 print "\n abcdefgh\n\n";
998 0 return;
999 }
1000
1001 1645 ▶sub _movetype {
Subroutine _movetype: called CC=16 SCAR=29.8
1002 1645 my ( $w, $move ) = @_;
1003 1645 my @result = "'$move':Not yet handled";
1004 1645 my $from;
1005 my $to;
1006
1007 1645 ▶ if ( $move =~ /^O-O(?:\+|\#)?$/ ) {
Branch: 13 branches
BranchTrueFalseTotal
if ($move =~ /^O-O(?:\+|\#)?$/u) { } 33 1612 1645
elsif ($move =~ /^O-O-O(?:\+|\#)?$/u) { } 3 1609 1612
elsif ($move =~ /^([2-7])([a-h][1-8])(?:\+|\#)?$/u) { } 0 1609 1609
elsif ($move =~ /^([a-h][1-8])(?:\+|\#)?$/u) { } 319 1290 1609
elsif ($move =~ /^([a-h])x?([a-h][1-8])(?:\+|\#)?$/u) { } 109 1181 1290
elsif ($move =~ /^([a-h][18])=?([RNBQ])(?:\+|\#)?$/u) { } 7 1174 1181
elsif ($move =~ /^([a-h])x([a-h][18])=?([RNBQ])(?:\+|\#)?$/u) { } 0 1174 1174
elsif ($move =~ /^([RNBQK])([a-h][1-8])(?:\+|\#)?$/u) { } 946 228 1174
elsif ($move =~ /^([RNBQK])x([a-h][1-8])(?:\+|\#)?$/u) { } 148 80 228
elsif ($move =~ /^([RNBQK])([a-h]|[1-8])([a-h][1-8])(?:\+|\#)?$/u) { } 74 6 80
elsif ($move =~ /^([RNBQK])([a-h][1-8])([a-h][1-8])(?:\+|\#)?$/u) { } 6 0 6
elsif ($move =~ /^([RNBQK])([a-h]|[1-8])x([a-h][1-8])(?:\+|\#)?$/u) { } 0 0 0
elsif ($move =~ /^([RNBQK])([a-h][1-8])x([a-h][1-8])(?:\+|\#)?$/u) { } 0 0 0
1008 33 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 15 18 33
1009 15 $from = "e1h1";
1010 15 $to = "g1f1";
1011 }
1012 else {
1013 18 $from = "e8h8";
1014 18 $to = "g8f8";
1015 }
1016 33 @result = ( "KR", $to, $from );
1017 }
1018 elsif ( $move =~ /^O-O-O(?:\+|\#)?$/ ) {
1019
1020 3 ▶ if ($w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w) { } 3 0 3
1021 3 $from = "e1a1";
1022 3 $to = "c1d1";
1023 }
1024 else {
1025 0 $from = "e8a8";
1026 0 $to = "c8d8";
1027 }
1028 3 @result = ( "KR", $to, $from );
1029 }
1030 elsif ( $move =~ /^([2-7])([a-h][1-8])(?:\+|\#)?$/ ) {
1031 0 @result = ( "P", $2 );
1032 }
1033 elsif ( $move =~ /^([a-h][1-8])(?:\+|\#)?$/ ) {
1034 319 @result = ( "P", $1 );
1035 }
1036 elsif ( $move =~ /^([a-h])x?([a-h][1-8])(?:\+|\#)?$/ ) {
1037 109 @result = ( "P", $2, $1 );
1038 }
1039 elsif ( $move =~ /^([a-h][18])=?([RNBQ])(?:\+|\#)?$/ ) {
1040 7 @result = ( "P", $1, undef, $2 );
1041 }
1042 elsif ( $move =~ /^([a-h])x([a-h][18])=?([RNBQ])(?:\+|\#)?$/ ) {
1043 0 @result = ( "P", $2, $1, $3 );
1044 }
1045 elsif ( $move =~ /^([RNBQK])([a-h][1-8])(?:\+|\#)?$/ ) {
1046 946 @result = ( $1, $2 );
1047 }
1048 elsif ( $move =~ /^([RNBQK])x([a-h][1-8])(?:\+|\#)?$/ ) {
1049 148 @result = ( $1, $2 );
1050 }
1051 elsif ( $move =~ /^([RNBQK])([a-h]|[1-8])([a-h][1-8])(?:\+|\#)?$/ ) {
1052 74 @result = ( $1, $3, $2 );
1053 }
1054 elsif ( $move =~ /^([RNBQK])([a-h][1-8])([a-h][1-8])(?:\+|\#)?$/ ) {
1055 6 @result = ( $1, $3, $2 );
1056 }
1057 elsif ( $move =~ /^([RNBQK])([a-h]|[1-8])x([a-h][1-8])(?:\+|\#)?$/ ) {
1058 0 @result = ( $1, $3, $2 );
1059 }
1060 elsif ( $move =~ /^([RNBQK])([a-h][1-8])x([a-h][1-8])(?:\+|\#)?$/ ) {
1061 0 @result = ( $1, $3, $2 );
1062 }
1063 1645 return @result;
1064 }
1065
1066 1183 ▶sub psquares {
Subroutine psquares: called CC=3 SCAR=11.0
Pod documented
1067 1183 my ( $piece, %board ) = @_;
1068
1069 1183 ▶ return grep { $_ and $board{$_} and ( $board{$_} eq $piece ) }
Condition83%5/6
$_ && $board{$_} && $board{$_} eq $piece
!ll&&!rl&&r
40777209021945
$_ and $board{$_}
!ll&&!rl&&r
04077722847
MC/DC66%2/3
$_ && $board{$_} && $board{$_} eq $piece
$_ $board{$_} $board{$_} eq $piece
Truth table75%3/4
A and B && C
A= $_B= $board{$_}C= $board{$_} eq $piece
ABCresult
0XX0
10X0
1100
1111
1070 sort keys %board;
1071 }
1072
1073 1645 ▶sub epd {
Subroutine epd: called CC=17 SCAR=28.3
Pod documented
1074 1645 my ( $w, $Kc, $Qc, $kc, $qc, $ep, %board ) = @_;
1075 1645 my @key = qw(
1076 a8 b8 c8 d8 e8 f8 g8 h8
1077 a7 b7 c7 d7 e7 f7 g7 h7
1078 a6 b6 c6 d6 e6 f6 g6 h6
1079 a5 b5 c5 d5 e5 f5 g5 h5
1080 a4 b4 c4 d4 e4 f4 g4 h4
1081 a3 b3 c3 d3 e3 f3 g3 h3
1082 a2 b2 c2 d2 e2 f2 g2 h2
1083 a1 b1 c1 d1 e1 f1 g1 h1
1084 );
1085 1645 my $n;
1086 my $piece;
1087 1645 my $epd;
1088
1089 1645 for ( 0 .. 63 ) {
1090 105280 ▶ if ( $_ and ( $_ % 8 ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ and $_ % 8 == 0) 11515 93765 105280
Condition100%3/3
$_ and $_ % 8 == 0
!ll&&!rl&&r
16459212011515
MC/DC100%2/2
$_ and $_ % 8 == 0
$_ $_ % 8 == 0
Truth table100%3/3
A and B
A= $_B= $_ % 8 == 0
ABresult
0X0
100
111
1091 11515 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 8430 3085 11515
1092 8430 $epd .= "$n";
1093 8430 $n = 0;
1094 }
1095 11515 $epd .= "/";
1096 }
1097 105280 $piece = $board{ $key[$_] };
1098
1099 105280 ▶ if ($piece) {
Branch: 1 branch
BranchTrueFalseTotal
if ($piece) { } 35210 70070 105280
1100 35210 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 17308 17902 35210
1101 17308 $epd .= "$n";
1102 17308 $n = 0;
1103 }
1104 35210 $epd .= $piece;
1105 }
1106 else {
1107 70070 $n++;
1108 }
1109 }
1110
1111 1645 ▶ $epd .= "$n" if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 947 698 1645
1112 1645 ▶ $epd .= ( $w ? " b" : " w" );
Branch: 1 branch
BranchTrueFalseTotal
$w ? : 826 819 1645
1113
1114 1645 ▶ if ( $Kc or $Qc or $kc or $qc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Kc or $Qc or $kc or $qc) { } 340 1305 1645
Condition77%7/9
$Kc or $Qc or $kc or $qc
l!l&&r!l&&!r
34001305
$Kc or $Qc or $kc
l!l&&r!l&&!r
321191305
$Kc or $Qc
l!l&&r!l&&!r
32101324
MC/DC50%2/4
$Kc or $Qc or $kc or $qc
$Kc $Qc $kc $qc
Truth table60%3/5
A or B or C or D
A= $KcB= $QcC= $kcD= $qc
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1115 340 $epd .= " ";
1116 340 ▶ $epd .= "K" if $Kc;
Branch: 1 branch
BranchTrueFalseTotal
if $Kc 321 19 340
1117 340 ▶ $epd .= "Q" if $Qc;
Branch: 1 branch
BranchTrueFalseTotal
if $Qc 320 20 340
1118 340 ▶ $epd .= "k" if $kc;
Branch: 1 branch
BranchTrueFalseTotal
if $kc 285 55 340
1119 340 ▶ $epd .= "q" if $qc;
Branch: 1 branch
BranchTrueFalseTotal
if $qc 279 61 340
1120 }
1121 else {
1122 1305 $epd .= " -";
1123 }
1124 1645 $epd .= " $ep";
1125 1645 return $epd;
1126 }
1127
1128 110 ▶sub _canmove {
Subroutine _canmove: called CC=22 SCAR=32.3
1129 110 my ( $piece, $to, $from, %board ) = @_;
1130 110 my $lto;
1131 my $rto;
1132 110 my $lfrom;
1133 110 my $rfrom;
1134 110 my $result = 1;
1135 110 my $offset = 1;
1136 110 my $roffset = 1;
1137 110 my $loffset = 1;
1138 110 my $c = 0;
1139
1140 110 $to =~ /(.)(.)/;
1141 110 ( $lto, $rto ) = ( $1, $2 );
1142 110 $from =~ /(.)(.)/;
1143 110 ( $lfrom, $rfrom ) = ( $1, $2 );
1144
1145 110 ▶ if ( $board{$from} and $board{to} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($board{$from} and $board{'to'}) { } 0 110 110
elsif ($rto eq $rfrom or $lto eq $lfrom) { } 78 32 110
elsif ($piece =~ /[bq]/iu) { } 16 16 32
Condition33%1/3
$board{$from} and $board{"to"}
!ll&&!rl&&r
01100
MC/DC0%0/2
$board{$from} and $board{"to"}
$board{$from} $board{"to"}
Truth table33%1/3
A and B
A= $board{$from}B= $board{"to"}
ABresult
0X0
100
111
1146 0 ▶ if ( defined( $board{$from} ) and defined( $board{$to} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $board{$from} and defined $board{$to}) 0 0 0
Condition0%0/3
defined $board{$from} and defined $board{$to}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $board{$from} and defined $board{$to}
defined $board{$from} defined $board{$to}
Truth table0%0/3
A and B
A= defined $board{$from}B= defined $board{$to}
ABresult
0X0
100
111
1147 0 ▶ if ( $board{$from}->color() == $board{$to}->color() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($board{$from}->color == $board{$to}->color) 0 0 0
1148 0 $result = 0;
1149 }
1150 }
1151 }
1152 ▶ elsif ( ( $rto eq $rfrom ) or ( $lto eq $lfrom ) ) {
Condition100%3/3
$rto eq $rfrom or $lto eq $lfrom
l!l&&r!l&&!r
502832
MC/DC100%2/2
$rto eq $rfrom or $lto eq $lfrom
$rto eq $rfrom $lto eq $lfrom
Truth table100%3/3
A or B
A= $rto eq $rfromB= $lto eq $lfrom
ABresult
1X1
011
000
1153
1154 78 ▶ if ( ( $rto eq $rfrom and $lto lt $lfrom )
Branch: 1 branch
BranchTrueFalseTotal
if ($rto eq $rfrom and $lto lt $lfrom or $lto eq $lfrom and $rto lt $rfrom) 35 43 78
Condition100%9/9
$rto eq $rfrom and $lto lt $lfrom or $lto eq $lfrom and $rto lt $rfrom
l!l&&r!l&&!r
161943
$rto eq $rfrom and $lto lt $lfrom
!ll&&!rl&&r
283416
$lto eq $lfrom and $rto lt $rfrom
!ll&&!rl&&r
34919
MC/DC75%3/4
$rto eq $rfrom and $lto lt $lfrom or $lto eq $lfrom and $rto lt $rfrom
$rto eq $rfrom $lto lt $lfrom $lto eq $lfrom $rto lt $rfrom
Truth table57%4/7
A and B or C and D
A= $rto eq $rfromB= $lto lt $lfromC= $lto eq $lfromD= $rto lt $rfrom
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1155 or ( $lto eq $lfrom and $rto lt $rfrom ) )
1156 {
1157 35 $offset = -1;
1158 }
1159
1160 78 ▶ if ( $lto eq $lfrom ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lto eq $lfrom) 28 50 78
1161 28 $c = 1;
1162 }
1163 78 ▶ while ( $from ne $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from ne $to) 114 55 169
1164 114 substr( $from, $c, 1 )
1165 = chr( ord( substr( $from, $c, 1 ) ) + $offset );
1166 114 ▶ if ( defined( $board{$from} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $board{$from}) 23 91 114
1167 23 ▶ $result = 0 if ( $from ne $to );
Branch: 1 branch
BranchTrueFalseTotal
if $from ne $to 22 1 23
1168 23 last;
1169 }
1170 }
1171 }
1172 elsif ( $piece =~ /[bq]/i ) {
1173
1174 16 ▶ if ( $rto lt $rfrom ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rto lt $rfrom) 14 2 16
1175 14 $roffset = -1;
1176 }
1177 16 ▶ if ( $lto lt $lfrom ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lto lt $lfrom) 0 16 16
1178 0 $loffset = -1;
1179 }
1180 16 ▶ while ( $from ne $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from ne $to) 32 0 32
1181 32 substr( $from, 0, 1 )
1182 = chr( ord( substr( $from, 0, 1 ) ) + $loffset );
1183 32 substr( $from, 1, 1 )
1184 = chr( ord( substr( $from, 1, 1 ) ) + $roffset );
1185 32 ▶ if ( defined( $board{$from} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $board{$from}) 16 16 32
1186 16 ▶ $result = 0 if ( $from ne $to );
Branch: 1 branch
BranchTrueFalseTotal
if $from ne $to 8 8 16
1187 16 last;
1188 }
1189 }
1190 }
1191 110 return $result;
1192 }
1193
1194 18 ▶sub epdTaxonomy {
Subroutine epdTaxonomy: called CC=13 SCAR=31.7
Pod documented
1195 18 my (%options) = @_;
1196 18 my @moves = @{ $options{'moves'} };
1197 18 my @results;
1198 18 my ( $eco, $nic, $opening );
1199 18 my @epd = reverse( epdlist(@moves) );
1200
1201 18 ▶ if ( $options{'all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'all'}) { } 18 0 18
1202 18 $eco = epdcode( 'ECO', \@epd );
1203 18 $nic = epdcode( 'NIC', \@epd );
1204 18 $opening = epdcode( 'Opening', \@epd );
1205 }
1206 else {
1207 0 for ( lc( keys %options ) ) {
1208 0 ▶ if ( $_ eq 'eco' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq 'eco') { } 0 0 0
elsif ($_ eq 'nic') { } 0 0 0
elsif ($_ eq 'Opening') { } 0 0 0
1209 0 $eco = epdcode( 'ECO', \@epd );
1210 }
1211 elsif ( $_ eq 'nic' ) {
1212 0 $nic = epdcode( 'NIC', \@epd );
1213 }
1214 elsif ( $_ eq 'Opening' ) {
1215 0 $opening = epdcode( 'Opening', \@epd );
1216 }
1217 }
1218 }
1219 18 ▶ if ( $options{'astags'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'astags'}) { } 6 12 18
1220 6 ▶ push( @results, "[ECO \"$eco\"]" ) if $eco;
Branch: 1 branch
BranchTrueFalseTotal
if $eco 6 0 6
1221 6 ▶ push( @results, "[NIC \"$nic\"]" ) if $nic;
Branch: 1 branch
BranchTrueFalseTotal
if $nic 6 0 6
1222 6 ▶ push( @results, "[Opening \"$opening\"]" ) if $opening;
Branch: 1 branch
BranchTrueFalseTotal
if $opening 6 0 6
1223 }
1224 else {
1225 12 ▶ push( @results, $eco ) if $eco;
Branch: 1 branch
BranchTrueFalseTotal
if $eco 12 0 12
1226 12 ▶ push( @results, $nic ) if $nic;
Branch: 1 branch
BranchTrueFalseTotal
if $nic 12 0 12
1227 12 ▶ push( @results, $opening ) if $opening;
Branch: 1 branch
BranchTrueFalseTotal
if $opening 12 0 12
1228 }
1229 18 return @results;
1230 }
1231
1232 11 1;
1233 __END__
↑ Summary