| 1 | package Game::Checkers::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use Game::Checkers::Squares; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 31 | our (@TAG_ORDER, %STANDARD, %RESULT); | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 31 | @TAG_ORDER = qw/Event Site Date Round White Black Result/; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 31 | %STANDARD = map { $_ => 1 } @TAG_ORDER, qw/FEN SetUp/; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 31 | %RESULT = map { $_ => 1 } '1-0', '0-1', '1/2-1/2', '*'; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2762 | ▶ | sub parse_move { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_move: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2762 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2762 | ▶ | return undef unless defined $string; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2762 | (my $clean = $string) =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2762 | my ($jump, @token); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2762 | ▶ | if ($clean =~ m/^([^-x]+)-([^-x]+)$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2391 | ($jump, @token) = (0, $1, $2); | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } elsif ($clean =~ m/^[^-x]+(?:[xX][^-x]+)+$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 366 | $jump = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 366 | @token = split m/[xX]/, $clean; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # the two spellings of a square do not mix in one move: '12-a5' is a typo, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # not half a move | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2757 | my ($numeric, @squares) = (0); | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2757 | for my $token (@token) { | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5544 | ▶ | if ($token =~ m/^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5512 | ▶ | return undef if @squares && !$numeric; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@squares and not $numeric
MC/DC100%2/2
@squares and not $numeric
@squares
not $numeric
Truth table100%3/3
A and not(B)
A= @squaresB= not $numeric
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5511 | ▶ | return undef if $token < 1 || $token > 32; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token < 1 or $token > 32
MC/DC50%1/2
$token < 1 or $token > 32
$token < 1
$token > 32
Truth table66%2/3
A or B
A= $token < 1B= $token > 32
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5509 | $numeric = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5509 | push @squares, $token + 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5509 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 32 | ▶ | return undef if $numeric; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 31 | ▶ | my $square = Game::Checkers::Squares::coord_square($token) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 28 | push @squares, $square; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # a slide to the square it started on is not a move, but a jump that comes | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # back to it is: a king can capture its way round a loop | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2750 | ▶ | return undef if !$jump && $squares[0] == $squares[1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $jump and $squares[0] == $squares[1]
MC/DC100%2/2
not $jump and $squares[0] == $squares[1]
not $jump
$squares[0] == $squares[1]
Truth table100%3/3
not(A) and B
A= not $jumpB= $squares[0] == $squares[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2748 | from => $squares[0], | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | to => $squares[-1], | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | squares => \@squares, | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | jump => $jump | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10758 | ▶ | sub format_move { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_move: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10758 | my ($move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10758 | ▶ | return $move->notation if ref $move && ref $move ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $move and ref $move ne "HASH"
MC/DC0%0/2
ref $move and ref $move ne "HASH"
ref $move
ref $move ne "HASH"
Truth table33%1/3
A and B
A= ref $moveB= ref $move ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10758 | my @squares = @{$move->{squares}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | return $move->{jump} | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 10758 | ▶ | ? join 'x', @squares | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | : sprintf '%d-%d', $squares[0], $squares[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub format_coord_move { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_coord_move: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my ($move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | return $move->coord_notation if ref $move && ref $move ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $move and ref $move ne "HASH"
MC/DC50%1/2
ref $move and ref $move ne "HASH"
ref $move
ref $move ne "HASH"
Truth table66%2/3
A and B
A= ref $moveB= ref $move ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my @squares = map { Game::Checkers::Squares::coord_name($_) } | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | @{$move->{squares}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | return $move->{jump} | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | ? join 'x', @squares | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | : sprintf '%s-%s', $squares[0], $squares[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3862 | ▶ | sub fen_from_position { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fen_from_position: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3862 | my ($position, $turn) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3862 | ▶ | die "turn must be black or white, got " . (defined $turn ? "'$turn'" : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
defined $turn and $turn eq "black" || $turn eq "white"
$turn eq "black" or $turn eq "white"
MC/DC0%0/3
defined $turn and $turn eq "black" || $turn eq "white"
defined $turn
$turn eq "black"
$turn eq "white"
Truth table50%2/4
A and B or C
A= defined $turnB= $turn eq "black"C= $turn eq "white"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | unless defined $turn && ($turn eq 'black' || $turn eq 'white'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3862 | my (@black, @white); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3862 | for my $square (1 .. 32) { | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 123584 | ▶ | my $value = $position->[$square] or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 54574 | ▶ | my $entry = (abs($value) == 2 ? 'K' : '') . $square; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 54574 | ▶ | push @{$value > 0 ? \@black : \@white}, $entry; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3862 | ▶ | return sprintf '%s:W%s:B%s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ($turn eq 'black' ? 'B' : 'W'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | join(',', @white), | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | join(',', @black); | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1649 | ▶ | sub position_from_fen { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position_from_fen: called CC=25 SCAR=32.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1649 | my ($fen, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1649 | ▶ | die 'a FEN string is required' unless defined $fen && length $fen; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $fen and length $fen
MC/DC0%0/2
defined $fen and length $fen
defined $fen
length $fen
Truth table33%1/3
A and B
A= defined $fenB= length $fen
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1649 | (my $clean = uc $fen) =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1649 | my @parts = split m/:/, $clean, -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1649 | ▶ | die "malformed FEN '$fen': expected a colour and two piece lists" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | unless @parts == 3; | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1648 | my $letter = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1648 | ▶ | die "malformed FEN '$fen': the side to move must be B or W" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$letter eq "B" or $letter eq "W"
MC/DC100%2/2
$letter eq "B" or $letter eq "W"
$letter eq "B"
$letter eq "W"
Truth table100%3/3
A or B
A= $letter eq "B"B= $letter eq "W"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | unless $letter eq 'B' || $letter eq 'W'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1647 | my @position = (0) x 33; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1647 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | my %colour; | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1647 | for my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3291 | my $side = substr $part, 0, 1, ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3291 | ▶ | die "malformed FEN '$fen': a piece list must start with B or W" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$side eq "B" or $side eq "W"
MC/DC0%0/2
$side eq "B" or $side eq "W"
$side eq "B"
$side eq "W"
Truth table66%2/3
A or B
A= $side eq "B"B= $side eq "W"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | unless $side eq 'B' || $side eq 'W'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3291 | ▶ | die "malformed FEN '$fen': two $side piece lists" if $colour{$side}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3291 | ▶ | next unless length $part; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3288 | for my $entry (split m/,/, $part) { | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 37311 | ▶ | my ($king, $square) = $entry =~ m/^(K?)([0-9]+)$/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | or die "malformed FEN '$fen': '$entry' is not a square"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 37310 | ▶ | die "malformed FEN '$fen': square $square is not 1 .. 32" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$square < 1 or $square > 32
MC/DC100%2/2
$square < 1 or $square > 32
$square < 1
$square > 32
Truth table100%3/3
A or B
A= $square < 1B= $square > 32
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | if $square < 1 || $square > 32; | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 37308 | ▶ | die "malformed FEN '$fen': square $square twice" if $seen{$square}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 37307 | ▶ | my $value = $king ? 2 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 37307 | ▶ | $position[$square] = $side eq 'B' ? $value : -$value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1643 | ▶ | if ($opt{strict}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | for my $side ('B', 'W') { | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | my $wanted = $side eq 'B' ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | my $count = grep { $_ && ($_ > 0 ? 1 : -1) == $wanted } @position; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ && ($_ > 0 ? 1 : -1) == $wanted
MC/DC100%2/2
$_ && ($_ > 0 ? 1 : -1) == $wanted
$_
($_ > 0 ? 1 : -1) == $wanted
Truth table100%3/3
A && B
A= $_B= ($_ > 0 ? 1 : -1) == $wanted
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | die "malformed FEN '$fen': $count $side pieces, the game has 12" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | if $count > 12; | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1642 | ▶ | return (\@position, $letter eq 'B' ? 'black' : 'white'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 54 | ▶ | sub parse_pdn { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_pdn: called CC=13 SCAR=26.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 54 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 54 | ▶ | die 'PDN text is required' unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 54 | my (%tag, @movetext); | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 54 | for my $line (split m/\n/, $text) { | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 611 | ▶ | if ($line =~ m/^\s*\[\s*(\w+)\s+"([^"]*)"\s*\]\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 380 | $tag{$1} = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 380 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # a semicolon comment runs to the end of ITS line, so it goes before | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # the lines are joined, while a brace comment may span lines and goes | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # after | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 231 | $line =~ s/;.*$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 231 | push @movetext, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 54 | my $movetext = join ' ', @movetext; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 54 | $movetext =~ s/\{[^}]*\}/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 54 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 54 | ▶ | if ($movetext =~ s{(1-0|0-1|1/2-1/2|\*)\s*$}{}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 52 | $result = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 54 | my @moves; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 54 | for my $token (split ' ', $movetext) { | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2191 | ▶ | next if $token =~ m/^[0-9]+\.+$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1454 | $token =~ s/^[0-9]+\.+//; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1454 | ▶ | next unless length $token; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1454 | ▶ | my $parsed = parse_move($token) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | or die "malformed PDN: '$token' is not a move"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1452 | push @moves, format_move($parsed); | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 52 | ▶ | $result = $tag{Result} if !defined $result && defined $tag{Result}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $result and defined $tag{"Result"}
MC/DC0%0/2
not defined $result and defined $tag{"Result"}
not defined $result
defined $tag{"Result"}
Truth table33%1/3
not(A) and B
A= not defined $resultB= defined $tag{"Result"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 52 | ▶ | $result = '*' unless defined $result && $RESULT{$result}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $result and $Game::Checkers::Notation::RESULT{$result}
MC/DC0%0/2
defined $result and $Game::Checkers::Notation::RESULT{$result}
defined $result
$Game::Checkers::Notation::RESULT{$result}
Truth table33%1/3
A and B
A= defined $resultB= $Game::Checkers::Notation::RESULT{$result}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 52 | return { tags => \%tag, moves => \@moves, result => $result }; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 212 | ▶ | sub format_pdn { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_pdn: called CC=15 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 212 | my ($game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 212 | ▶ | my %tag = %{$game->{tags} || {}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$game->{'tags'} || {}
MC/DC0%0/1
$game->{'tags'} || {}
$game->{'tags'}
Truth table50%1/2
A
A= $game->{'tags'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 212 | ▶ | my $result = $game->{result} || $tag{Result} || '*'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$game->{'result'} || $tag{'Result'} || '*'
$game->{"result"} or $tag{"Result"}
MC/DC0%0/2
$game->{'result'} || $tag{'Result'} || '*'
$game->{"result"}
$tag{"Result"}
Truth table33%1/3
A or B
A= $game->{"result"}B= $tag{"Result"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 212 | ▶ | die "'$result' is not a PDN result" unless $RESULT{$result}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 212 | $tag{Result} = $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 212 | $tag{$_} = '?' for grep { !defined $tag{$_} } @TAG_ORDER; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | 212 | my $pdn = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 212 | $pdn .= sprintf qq{[%s "%s"]\n}, $_, $tag{$_} for @TAG_ORDER; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | $pdn .= sprintf qq{[%s "%s"]\n}, $_, $tag{$_} | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 212 | for grep { defined $tag{$_} } 'FEN', 'SetUp'; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | $pdn .= sprintf qq{[%s "%s"]\n}, $_, $tag{$_} | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 212 | for sort grep { !$STANDARD{$_} } keys %tag; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 212 | $pdn .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 212 | ▶ | my @moves = @{$game->{moves} || []}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$game->{'moves'} || []
MC/DC0%0/1
$game->{'moves'} || []
$game->{'moves'}
Truth table50%1/2
A
A= $game->{'moves'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 212 | my ($line, @lines) = (''); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 212 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 212 | ▶ | while (@moves) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 902 | $number++; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 902 | my $pair = join ' ', $number . '.', grep { defined } splice @moves, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 902 | ▶ | if (length($line) + length($pair) + 1 > 79) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 141 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 141 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 902 | ▶ | $line .= (length $line ? ' ' : '') . $pair; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 212 | ▶ | if (length($line) + length($result) + 1 > 79) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 212 | ▶ | $line .= (length $line ? ' ' : '') . $result; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 212 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 212 | $pdn .= join "\n", @lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 212 | return $pdn . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||