Plisco/EPD/Record.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 75.0% 15 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 75.0% 3 / 4 totaltotal 85.5% 77 / 90 CC 14 SCAR 20.0
CC
14
Cov
87%
new
12.2
operation
4.0
BEGIN
1.0
CRAP 7.4
« Plisco/Macro.pm ↑ Summary Plisco/Engine/Position.pm »
1 #! /bin/false
2  
3 # Copyright (C) 2021-2026 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software. It comes without any warranty, to
7 # the extent permitted by applicable law. You can redistribute it
8 # and/or modify it under the terms of the Do What the Fuck You Want
9 # to Public License, Version 2, as published by Sam Hocevar. See
10 # http://www.wtfpl.net/ for more details.
11  
12 package Chess::Plisco::EPD::Record;
13 8 $Chess::Plisco::EPD::Record::VERSION = 'v1.0.3';
14 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 ▶use Locale::TextDomain qw('Chess-Plisco');
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 8 ▶use Chess::Plisco qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 70240 ▶sub new {
Subroutine new: called CC=11 SCAR=25.0
Pod undocumented
22 70240 my ($class, $line, $pseudo_legal) = @_;
23  
24 70240 my $ws = "[ \011-\015]";
25 70240 $line =~ s/^$ws+//;
26 70240 $line =~ s/ws+$//;
27 70240 my ($pieces, $to_move, $castling, $ep_shift, $ops) = split /$ws+/, $line, 5;
28 70240 ▶ if (!defined $ep_shift) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ep_shift) 0 70240 70240
29 0 die __"Incomplete EPD string.\n";
30 }
31  
32 70240 my %operations;
33 70240 ▶ while (length $ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ops) 280720 70240 350960
34 280720 ▶ if ($ops !~ s/^$ws*([_a-zA_Z0-9]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ops =~ s/^$ws*([_a-zA_Z0-9]+)//) 0 280720 280720
35 0 die "Invalid EPD.\n";
36 }
37  
38 280720 my $operation = $1;
39 die __x("Duplicate operation '{operation}'.", operation => $operation)
40 280720 ▶ if exists $operations{$operation};
Branch: 1 branch
BranchTrueFalseTotal
if exists $operations{$operation} 0 280720 280720
41
42 280720 my @operands;
43 280720 ▶ while (length $ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ops) 561479 0 561479
44 561479 ▶ if ($ops =~ s/^$ws*"(.*?)"//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ops =~ s/^$ws*"(.*?)"//) { } 70080 491399 561479
elsif ($ops =~ s/^$ws*([^ \t;]+)//) { } 210679 280720 491399
elsif ($ops =~ s/^$ws*;$ws*//) { } 280720 0 280720
45 70080 push @operands, $1;
46 } elsif ($ops =~ s/^$ws*([^ \t;]+)//) {
47 210679 push @operands, $1;
48 } elsif ($ops =~ s/^$ws*;$ws*//) {
49 280720 last;
50 } else {
51 0 die __"Invalid EPD.\n";
52 }
53 }
54  
55 280720 $operations{$operation} = [@operands];
56 }
57  
58 70240 my $position = Chess::Plisco->new("$pieces $to_move $castling $ep_shift", $pseudo_legal);
59 70240 ▶ my $hmc = $operations{hmvc} || 0;
Condition50%1/2
$operations{'hmvc'} || 0
l!l
070240
MC/DC0%0/1
$operations{'hmvc'} || 0
$operations{'hmvc'}
Truth table50%1/2
A
A= $operations{'hmvc'}
Aresult
11
00
60 70240 ▶ my $fmc = $operations{fmvc} || 1;
Condition50%1/2
$operations{'fmvc'} || 1
l!l
070240
MC/DC0%0/1
$operations{'fmvc'} || 1
$operations{'fmvc'}
Truth table50%1/2
A
A= $operations{'fmvc'}
Aresult
11
00
61 70240 my $fen = "$pieces $to_move $castling $ep_shift $hmc $fmc";
62 70240 my $position = Chess::Plisco->new($fen, $pseudo_legal);
63  
64 70240 bless {
65 __position => $position,
66 __operations => \%operations,
67 }, $class;
68 }
69  
70 546 ▶sub position {
Subroutine position: called CC=1 SCAR=0.0
Pod documented
71 546 shift->{__position};
72 }
73  
74 3235 ▶sub operations {
Subroutine operations: called CC=1 SCAR=0.0
Pod documented
75 3235 shift->{__operations};
76 }
77  
78 1984 ▶sub operation {
Subroutine operation: called CC=4 SCAR=13.9
Pod documented
79 1984 my ($self, $opcode) = @_;
80  
81 1984 ▶ if (wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 692 1292 1984
elsif (exists $self->operations->{$opcode}) { } 1251 41 1292
82 692 ▶ return @{$self->operations->{$opcode} || []};
Condition100%2/2
$self->operations->{$opcode} || []
l!l
347345
MC/DC100%1/1
$self->operations->{$opcode} || []
$self->operations->{$opcode}
Truth table100%2/2
A
A= $self->operations->{$opcode}
Aresult
11
00
83 } elsif (exists $self->operations->{$opcode}) {
84 1251 return $self->operations->{$opcode}->[0];
85 } else {
86 41 return;
87 }
88 }
89  
90 8 1;
« Plisco/Macro.pm ↑ Summary Plisco/Engine/Position.pm »