| 1 | package Game::Merrills::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 84 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 84 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 84 | ▶ | use Game::Merrills::Points; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 84 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 84 | our (%CELL, %GLYPH, %TURN, %LETTER); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 84 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 84 | %CELL = ('.' => 0, W => 1, B => -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 84 | %GLYPH = (0 => '.', 1 => 'W', -1 => 'B'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 84 | %TURN = (w => 'white', b => 'black'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 84 | %LETTER = (white => 'w', black => 'b'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 15781 | ▶ | sub parse_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_move: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 15781 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15781 | ▶ | return undef unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and not ref $text
MC/DC100%2/2
defined $text and not ref $text
defined $text
not ref $text
Truth table100%3/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 15776 | ▶ | my ($from, $to, $remove) = $text =~ m/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ^\s* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ([a-g][1-7]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | (?:\s*-\s*([a-g][1-7]))? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | (?:\s*x\s*([a-g][1-7]))? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | \s*$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | /xi or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 15744 | ▶ | ($from, $to) = (undef, $from) unless defined $to; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 15744 | my %move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15744 | for my $part ([from => $from], [to => $to], [remove => $remove]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 47224 | my ($key, $name) = @{$part}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 47224 | ▶ | next unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 42676 | my $point = Game::Merrills::Points::point($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 42676 | ▶ | return undef unless defined $point; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 42668 | $move{$key} = $point; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 15736 | ▶ | return undef if defined $move{from} && $move{from} == $move{to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $move{"from"} and $move{"from"} == $move{"to"}
MC/DC100%2/2
defined $move{"from"} and $move{"from"} == $move{"to"}
defined $move{"from"}
$move{"from"} == $move{"to"}
Truth table100%3/3
A and B
A= defined $move{"from"}B= $move{"from"} == $move{"to"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | return undef if defined $move{remove} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | && ($move{remove} == $move{to} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 15734 | ▶ | || (defined $move{from} && $move{remove} == $move{from})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $move{"remove"} and $move{"remove"} == $move{"to"} || defined $move{"from"} && $move{"remove"} == $move{"from"}
$move{"remove"} == $move{"to"} or defined $move{"from"} and $move{"remove"} == $move{"from"}
defined $move{"from"} and $move{"remove"} == $move{"from"}
MC/DC100%4/4
defined $move{"remove"} and $move{"remove"} == $move{"to"} || defined $move{"from"} && $move{"remove"} == $move{"from"}
defined $move{"remove"}
$move{"remove"} == $move{"to"}
defined $move{"from"}
$move{"remove"} == $move{"from"}
Truth table100%5/5
A and B or C and D
A= defined $move{"remove"}B= $move{"remove"} == $move{"to"}C= defined $move{"from"}D= $move{"remove"} == $move{"from"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 15731 | return \%move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 213357 | ▶ | sub format_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_move: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 213357 | my ($move) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 213357 | ▶ | die 'a move needs a point to go to' unless ref $move eq 'HASH' && defined $move->{to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $move eq "HASH" and defined $move->{"to"}
MC/DC100%2/2
ref $move eq "HASH" and defined $move->{"to"}
ref $move eq "HASH"
defined $move->{"to"}
Truth table100%3/3
A and B
A= ref $move eq "HASH"B= defined $move->{"to"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 213355 | my $text = Game::Merrills::Points::name($move->{to}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $text = Game::Merrills::Points::name($move->{from}) . '-' . $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 213354 | ▶ | if defined $move->{from}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $text .= 'x' . Game::Merrills::Points::name($move->{remove}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 213354 | ▶ | if defined $move->{remove}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 213354 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 45801 | ▶ | sub format_position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_position: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 45801 | my ($position) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 45801 | ▶ | die 'position: not a hashref' unless ref $position eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 45800 | my $cells = $position->{cells}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | die 'position: cells must be an arrayref of 24 values' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 45800 | ▶ | unless ref $cells eq 'ARRAY' && @{$cells} == Game::Merrills::Points::POINTS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $cells eq "ARRAY" and @{$cells;} == 24
MC/DC50%1/2
ref $cells eq "ARRAY" and @{$cells;} == 24
ref $cells eq "ARRAY"
@{$cells;} == 24
Truth table66%2/3
A and B
A= ref $cells eq "ARRAY"B= @{$cells;} == 24
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 45799 | my $board = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 45799 | for my $point (Game::Merrills::Points::all_points()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1099153 | my $value = $cells->[$point]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | die 'position: cell ' . Game::Merrills::Points::name($point) . ' must be -1, 0 or 1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1099153 | ▶ | unless defined $value && exists $GLYPH{$value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and exists $Game::Merrills::Notation::GLYPH{$value}
MC/DC50%1/2
defined $value and exists $Game::Merrills::Notation::GLYPH{$value}
defined $value
exists $Game::Merrills::Notation::GLYPH{$value}
Truth table66%2/3
A and B
A= defined $valueB= exists $Game::Merrills::Notation::GLYPH{$value}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1099152 | $board .= $GLYPH{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 45798 | my $turn = $position->{turn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | die 'position: turn must be white or black' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 45798 | ▶ | unless defined $turn && exists $LETTER{$turn}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $turn and exists $Game::Merrills::Notation::LETTER{$turn}
MC/DC100%2/2
defined $turn and exists $Game::Merrills::Notation::LETTER{$turn}
defined $turn
exists $Game::Merrills::Notation::LETTER{$turn}
Truth table100%3/3
A and B
A= defined $turnB= exists $Game::Merrills::Notation::LETTER{$turn}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 45796 | ▶ | my $hand = $position->{hand} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$position->{'hand'} || {}
MC/DC100%1/1
$position->{'hand'} || {}
$position->{'hand'}
Truth table100%2/2
A
A= $position->{'hand'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $text = join ' ', $board, $LETTER{$turn}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 91592 | ▶ | map({ defined $hand->{$_} ? $hand->{$_} : 0 } qw/white black/), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$position->{'no_mill'} || 0
$position->{'ply'} || 0
MC/DC100%1/1
$position->{'no_mill'} || 0
$position->{'no_mill'}
MC/DC100%1/1
$position->{'ply'} || 0
$position->{'ply'}
Truth table100%2/2
A
A= $position->{'no_mill'}
Truth table100%2/2
A
A= $position->{'ply'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 45796 | $position->{no_mill} || 0, $position->{ply} || 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 45796 | parse_position($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 45795 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 65957 | ▶ | sub parse_position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_position: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 65957 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 65957 | ▶ | die 'position: nothing to read' unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and not ref $text
MC/DC50%1/2
defined $text and not ref $text
defined $text
not ref $text
Truth table66%2/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 65956 | my @field = split ' ', $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 65956 | ▶ | die 'position: six fields are needed, got ' . scalar @field unless @field == 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 65949 | my ($board, $turn, $white, $black, $no_mill, $ply) = @field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 65949 | ▶ | die 'position: the board must be 24 of W, B and .' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | unless $board =~ m/^[WB.]{24}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | die "position: the side to move must be w or b, got '$turn'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 65945 | ▶ | unless exists $TURN{$turn}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 65943 | for my $count ([white => $white], [black => $black]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 131884 | ▶ | die "position: men in hand for $count->[0] must be 0 .. 9, got '$count->[1]'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | unless $count->[1] =~ m/^[0-9]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 65940 | ▶ | die "position: plies since a mill must be a number, got '$no_mill'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | unless $no_mill =~ m/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 65939 | ▶ | die "position: the ply must be a number, got '$ply'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | unless $ply =~ m/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 65938 | my @cells = map { $CELL{$_} } split //, $board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 65938 | my %on = (white => scalar(grep { $_ == 1 } @cells), black => scalar(grep { $_ == -1 } @cells)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 65938 | ▶ | die 'position: white has more than nine men' if $on{white} + $white > 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 65937 | ▶ | die 'position: black has more than nine men' if $on{black} + $black > 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | cells => \@cells, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 65936 | turn => $TURN{$turn}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | hand => { white => $white + 0, black => $black + 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | no_mill => $no_mill + 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ply => $ply + 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 57 | ▶ | sub format_record { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_record: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 57 | my ($moves, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 57 | ▶ | die 'record: moves must be an arrayref' unless ref $moves eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 56 | my $header = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 56 | ▶ | if (defined $option{position}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | $header = 'position ' . format_position(parse_position($option{position})) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 55 | my @text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 55 | for my $i (0 .. $#{$moves}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 840 | my $move = $moves->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 840 | ▶ | my $written = !ref $move ? $move | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | : ref $move eq 'HASH' ? format_move($move) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | : $move->notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 840 | ▶ | die 'record: move ' . ($i + 1) . ', ' . (defined $written ? "'$written'" : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | . ' is not a move' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | unless parse_move($written); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 838 | push @text, format_move(parse_move($written)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 53 | my @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 53 | ▶ | for (my $i = 0; $i < @text; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 429 | push @line, join ' ', (($i / 2) + 1) . '.', grep { defined } @text[ $i, $i + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 53 | return join '', $header, map { "$_\n" } @line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 33 | ▶ | sub parse_record { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_record: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 33 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 33 | ▶ | die 'record: nothing to read' unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and not ref $text
MC/DC50%1/2
defined $text and not ref $text
defined $text
not ref $text
Truth table66%2/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 32 | $text =~ s/^[ \t]*#[^\n]*$//mg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 32 | $text =~ s/^[ \t]*position[ \t]+[^\n]*$//m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 32 | my @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 32 | for my $token (split ' ', $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 816 | ▶ | next if $token =~ m/^[0-9]+\.$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 541 | my $move = parse_move($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 541 | ▶ | die 'record: move ' . (@moves + 1) . ", '$token' is not a move" unless $move; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 536 | push @moves, $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 27 | return \@moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | sub record_position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
record_position: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 24 | ▶ | die 'record: nothing to read' unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and not ref $text
MC/DC50%1/2
defined $text and not ref $text
defined $text
not ref $text
Truth table66%2/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 23 | ▶ | my ($position) = $text =~ m/^[ \t]*position[ \t]+([^\n]*)$/m or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | return format_position(parse_position($position)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 84 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||