| 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
| |||||||||||||||||||
| 29 | 0 | die __"Incomplete EPD string.\n"; | |||||||||||||||||
| 30 | } | ||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 70240 | my %operations; | |||||||||||||||||
| 33 | 70240 | ▶ | while (length $ops) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 34 | 280720 | ▶ | if ($ops !~ s/^$ws*([_a-zA_Z0-9]+)//) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | 280720 | my @operands; | |||||||||||||||||
| 43 | 280720 | ▶ | while (length $ops) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 44 | 561479 | ▶ | if ($ops =~ s/^$ws*"(.*?)"//) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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
MC/DC0%0/1
$operations{'hmvc'} || 0
$operations{'hmvc'}
Truth table50%1/2
A
A= $operations{'hmvc'}
| |||||||||||||||||||
| 60 | 70240 | ▶ | my $fmc = $operations{fmvc} || 1; | ||||||||||||||||
|
Condition50%1/2
$operations{'fmvc'} || 1
MC/DC0%0/1
$operations{'fmvc'} || 1
$operations{'fmvc'}
Truth table50%1/2
A
A= $operations{'fmvc'}
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 82 | 692 | ▶ | return @{$self->operations->{$opcode} || []}; | ||||||||||||||||
|
Condition100%2/2
$self->operations->{$opcode} || []
MC/DC100%1/1
$self->operations->{$opcode} || []
$self->operations->{$opcode}
Truth table100%2/2
A
A= $self->operations->{$opcode}
| |||||||||||||||||||
| 83 | } elsif (exists $self->operations->{$opcode}) { | ||||||||||||||||||
| 84 | 1251 | return $self->operations->{$opcode}->[0]; | |||||||||||||||||
| 85 | } else { | ||||||||||||||||||
| 86 | 41 | return; | |||||||||||||||||
| 87 | } | ||||||||||||||||||
| 88 | } | ||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | 8 | 1; | |||||||||||||||||