| 1 | package Game::Fanorona::Notation; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 29 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 29 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 29 | PAIKA => 0, | |||||||||||||||||||||||||||||||||||||||||
| 13 | APPROACH => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | WITHDRAWAL => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 29 | ▶ | use constant SETUP => 'bbbbbbbbb/bbbbbbbbb/bwbw1bwbw/wwwwwwwww/wwwwwwwww w'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 29 | ▶ | use constant CHAIN_MAX => 44; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 29 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 22 | SETUP | ||||||||||||||||||||||||||||||||||||||||||
| 23 | parse_point format_point square_of name_of | ||||||||||||||||||||||||||||||||||||||||||
| 24 | parse_move format_move move_points mirror_move | ||||||||||||||||||||||||||||||||||||||||||
| 25 | parse_position format_position mirror_position | ||||||||||||||||||||||||||||||||||||||||||
| 26 | parse_game format_game | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 29 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 29 | my %BOARD = ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | sivy => [ 9, 5 ], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | dimy => [ 5, 5 ], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | telo => [ 3, 3 ], | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | my %DIR = ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | '0,1' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | '1,1' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | '1,0' => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | '1,-1' => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | '0,-1' => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | '-1,-1' => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | '-1,0' => 6, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | '-1,1' => 7, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | my %LETTER = (APPROACH, 'A', WITHDRAWAL, 'W'); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 29 | my %KIND = (A => APPROACH, W => WITHDRAWAL); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | my %HEADER = map { $_ => 1 } qw(variant start quiet_limit repeat ply_cap white black result); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 29 | my @HEADER = qw(variant start quiet_limit repeat ply_cap white black result); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 332913 | ▶ | my $size_ok = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 332913 | my ($cols, $rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 332913 | ▶ | return 0 unless defined $cols && defined $rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $cols and defined $rows
MC/DC0%0/2
defined $cols and defined $rows
defined $cols
defined $rows
Truth table33%1/3
A and B
A= defined $colsB= defined $rows
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 332913 | ▶ | return 0 unless $cols =~ /\A[3579]\z/ && $rows =~ /\A[35]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cols =~ /\A[3579]\z/u and $rows =~ /\A[35]\z/u
MC/DC50%1/2
$cols =~ /\A[3579]\z/u and $rows =~ /\A[35]\z/u
$cols =~ /\A[3579]\z/u
$rows =~ /\A[35]\z/u
Truth table66%2/3
A and B
A= $cols =~ /\A[3579]\z/uB= $rows =~ /\A[35]\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 332909 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 316870 | ▶ | my $size_of = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 316870 | my (%arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 316870 | my ($cols, $rows) = ($arg{cols}, $arg{rows}); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 316870 | ▶ | ($cols, $rows) = (9, 5) unless defined $cols || defined $rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cols or defined $rows
MC/DC50%1/2
defined $cols or defined $rows
defined $cols
defined $rows
Truth table66%2/3
A or B
A= defined $colsB= defined $rows
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 316870 | ▶ | return $size_ok->($cols, $rows) ? ($cols, $rows) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 3802 | ▶ | my $fail = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3802 | my ($reason, @more) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 3802 | ▶ | return wantarray ? (undef, $reason, @more) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 271550 | ▶ | sub parse_point { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_point: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 271550 | my ($name, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 271550 | ▶ | my ($cols, $rows) = $size_of->(%arg) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 271549 | ▶ | return unless defined $name && $name =~ /\A([a-i])([1-5])\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $name and $name =~ /\A([a-i])([1-5])\z/u
MC/DC100%2/2
defined $name and $name =~ /\A([a-i])([1-5])\z/u
defined $name
$name =~ /\A([a-i])([1-5])\z/u
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /\A([a-i])([1-5])\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 271523 | my ($file, $rank) = (ord($1) - ord('a'), $2 - 1); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 271523 | ▶ | return if $file >= $cols || $rank >= $rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$file >= $cols or $rank >= $rows
MC/DC100%2/2
$file >= $cols or $rank >= $rows
$file >= $cols
$rank >= $rows
Truth table100%3/3
A or B
A= $file >= $colsB= $rank >= $rows
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 271517 | return ($file, $rank); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2955186 | ▶ | sub format_point { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_point: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2955186 | my ($file, $rank) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 2955186 | ▶ | return undef unless defined $file && defined $rank; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and defined $rank
MC/DC50%1/2
defined $file and defined $rank
defined $file
defined $rank
Truth table66%2/3
A and B
A= defined $fileB= defined $rank
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2955185 | ▶ | return undef unless $file =~ /\A[0-8]\z/ && $rank =~ /\A[0-4]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$file =~ /\A[0-8]\z/u and $rank =~ /\A[0-4]\z/u
MC/DC100%2/2
$file =~ /\A[0-8]\z/u and $rank =~ /\A[0-4]\z/u
$file =~ /\A[0-8]\z/u
$rank =~ /\A[0-4]\z/u
Truth table100%3/3
A and B
A= $file =~ /\A[0-8]\z/uB= $rank =~ /\A[0-4]\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2955179 | return chr(ord('a') + $file) . ($rank + 1); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 150315 | ▶ | sub square_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
square_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 150315 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 150315 | ▶ | my ($file, $rank) = parse_point($name) or return -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 150314 | return ($rank + 1) * 11 + $file + 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2045595 | ▶ | sub name_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2045595 | my ($square) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 2045595 | ▶ | return undef unless defined $square && $square =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $square and $square =~ /\A[0-9]+\z/u
MC/DC50%1/2
defined $square and $square =~ /\A[0-9]+\z/u
defined $square
$square =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $squareB= $square =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2045594 | return format_point(($square % 11) - 1, int($square / 11) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 45234 | ▶ | sub parse_move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_move: called CC=27 SCAR=33.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 45234 | my ($string, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 45234 | ▶ | my ($cols, $rows) = $size_of->(%arg) or return $fail->('bad_size'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 45233 | ▶ | return $fail->('empty') unless defined $string && length $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $string and length $string
MC/DC100%2/2
defined $string and length $string
defined $string
length $string
Truth table100%3/3
A and B
A= defined $stringB= length $string
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 45229 | ▶ | return $fail->('bad_shape') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$string =~ /[^A-Za-z0-9-]/u or $string =~ /\A-|-\z|--/u or not $string =~ /-/u
$string =~ /[^A-Za-z0-9-]/u or $string =~ /\A-|-\z|--/u
MC/DC100%3/3
$string =~ /[^A-Za-z0-9-]/u or $string =~ /\A-|-\z|--/u or not $string =~ /-/u
$string =~ /[^A-Za-z0-9-]/u
$string =~ /\A-|-\z|--/u
not $string =~ /-/u
Truth table100%4/4
A or B or not(C)
A= $string =~ /[^A-Za-z0-9-]/uB= $string =~ /\A-|-\z|--/uC= not $string =~ /-/u
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | if $string =~ /[^A-Za-z0-9-]/ || $string =~ /\A-|-\z|--/ || $string !~ /-/; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 45218 | my ($first, @rest) = split /-/, $string; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 45218 | ▶ | return $fail->('kind_on_start') if $first =~ /\A[a-z][0-9][A-Za-z]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 45217 | ▶ | return $fail->('bad_point') unless $first =~ /\A[a-z][0-9]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 45215 | ▶ | return $fail->('too_long') if @rest > CHAIN_MAX; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 45213 | my @tokens; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 45213 | for my $token (@rest) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 75089 | ▶ | return $fail->('bad_point') unless $token =~ /\A([a-z][0-9])(.*)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 75086 | my ($point, $letter) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 75086 | ▶ | return $fail->('bad_kind') unless $letter eq '' || exists $KIND{$letter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$letter eq "" or exists $KIND{$letter}
MC/DC100%2/2
$letter eq "" or exists $KIND{$letter}
$letter eq ""
exists $KIND{$letter}
Truth table100%3/3
A or B
A= $letter eq ""B= exists $KIND{$letter}
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 75081 | push @tokens, [ $point, $letter ]; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 45205 | ▶ | my @at = parse_point($first, cols => $cols, rows => $rows) or return $fail->('off_board'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 45203 | my @steps; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 45203 | my $from_name = $first; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 45203 | for my $token (@tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 124 | 75079 | my ($point, $letter) = @$token; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 75079 | ▶ | my @to = parse_point($point, cols => $cols, rows => $rows) or return $fail->('off_board'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 75072 | my ($df, $dr) = ($to[0] - $at[0], $to[1] - $at[1]); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 75072 | ▶ | return $fail->('same_point') if !$df && !$dr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$df or $dr
MC/DC100%2/2
$df or $dr
$df
$dr
Truth table100%3/3
A or B
A= $dfB= $dr
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 75071 | ▶ | return $fail->('not_adjacent') if abs($df) > 1 || abs($dr) > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
abs $df > 1 or abs $dr > 1
MC/DC100%2/2
abs $df > 1 or abs $dr > 1
abs $df > 1
abs $dr > 1
Truth table100%3/3
A or B
A= abs $df > 1B= abs $dr > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 75059 | ▶ | return $fail->('no_line') if $df && $dr && ($at[0] + $at[1]) % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$df and $dr and ($at[0] + $at[1]) % 2
$df and $dr
MC/DC100%3/3
$df and $dr and ($at[0] + $at[1]) % 2
$df
$dr
($at[0] + $at[1]) % 2
Truth table100%4/4
A and B and C
A= $dfB= $drC= ($at[0] + $at[1]) % 2
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | push @steps, { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | from => square_of($from_name), | ||||||||||||||||||||||||||||||||||||||||||
| 132 | to => square_of($point), | ||||||||||||||||||||||||||||||||||||||||||
| 133 | dir => $DIR{"$df,$dr"}, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 75056 | ▶ | kind => $letter eq '' ? PAIKA : $KIND{$letter}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 75056 | @at = @to; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 75056 | $from_name = $point; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 45180 | ▶ | return $fail->('paika_in_chain') if @steps > 1 && grep { $_->{kind} == PAIKA } @steps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@steps > 1 and grep {$_->{"kind"} == 0;} @steps
MC/DC100%2/2
@steps > 1 and grep {$_->{"kind"} == 0;} @steps
@steps > 1
grep {$_->{"kind"} == 0;} @steps
Truth table100%3/3
A and B
A= @steps > 1B= grep {$_->{"kind"} == 0;} @steps
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | from => $steps[0]{from}, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | to => $steps[-1]{to}, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | steps => \@steps, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 45172 | points => [ $first, map { $_->[0] } @tokens ], | |||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 958593 | ▶ | sub format_move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_move: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 958593 | my ($move) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 958593 | ▶ | return undef unless ref $move; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | my ($from, $steps) = ref $move eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ? ($move->{from}, $move->{steps}) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 958591 | ▶ | : ($move->from, $move->steps); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 958591 | ▶ | return undef unless ref $steps eq 'ARRAY' && @$steps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $steps eq "ARRAY" and @$steps
MC/DC50%1/2
ref $steps eq "ARRAY" and @$steps
ref $steps eq "ARRAY"
@$steps
Truth table66%2/3
A and B
A= ref $steps eq "ARRAY"B= @$steps
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 958590 | ▶ | my $text = name_of($from) // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
name_of($from) // (return undef)
MC/DC100%1/1
name_of($from) // (return undef)
name_of($from)
Truth table100%2/2
A
A= name_of($from)
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 958589 | for my $s (@$steps) { | |||||||||||||||||||||||||||||||||||||||||
| 158 | 995008 | ▶ | my $to = name_of($s->{to}) // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
name_of($s->{"to"}) // (return undef)
MC/DC0%0/1
name_of($s->{"to"}) // (return undef)
name_of($s->{"to"})
Truth table50%1/2
A
A= name_of($s->{"to"})
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 995008 | ▶ | my $kind = $s->{kind} // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s->{"kind"} // (return undef)
MC/DC0%0/1
$s->{"kind"} // (return undef)
$s->{"kind"}
Truth table50%1/2
A
A= $s->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 995008 | ▶ | return undef unless $kind == PAIKA || exists $LETTER{$kind}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind == 0 or exists $LETTER{$kind}
MC/DC100%2/2
$kind == 0 or exists $LETTER{$kind}
$kind == 0
exists $LETTER{$kind}
Truth table100%3/3
A or B
A= $kind == 0B= exists $LETTER{$kind}
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 995007 | ▶ | $text .= "-$to" . ($kind == PAIKA ? '' : $LETTER{$kind}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 958588 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 88 | ▶ | sub move_points { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_points: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 88 | my ($string, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 88 | ▶ | my $move = parse_move($string, %arg) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 87 | return @{ $move->{points} }; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 832 | ▶ | my $mirror = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 832 | my ($how, $cols, $rows, $file, $rank) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 832 | ▶ | return ($cols - 1 - $file, $rank) if $how eq 'files'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 502 | ▶ | return ($file, $rows - 1 - $rank) if $how eq 'ranks'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 252 | ▶ | return ($cols - 1 - $file, $rows - 1 - $rank) if $how eq 'turn'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 86 | ▶ | sub mirror_move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mirror_move: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 86 | my ($string, $how, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 86 | ▶ | my ($cols, $rows) = $size_of->(%arg) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 86 | ▶ | my $move = parse_move($string, cols => $cols, rows => $rows) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 85 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 85 | for my $name (@{ $move->{points} }) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 232 | ▶ | my @to = $mirror->($how // '', $cols, $rows, parse_point($name, cols => $cols, rows => $rows)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$how // ""
MC/DC0%0/1
$how // ""
$how
Truth table50%1/2
A
A= $how
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 231 | push @names, format_point(@to); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 84 | my $text = shift @names; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 84 | for my $s (@{ $move->{steps} }) { | |||||||||||||||||||||||||||||||||||||||||
| 192 | 147 | ▶ | $text .= '-' . shift(@names) . ($s->{kind} == PAIKA ? '' : $LETTER{ $s->{kind} }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 84 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 15784 | ▶ | my $write_board = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 15784 | my ($cols, $rows, $stones, $side) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 15784 | my @ranks; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 15784 | for my $rank (reverse 0 .. $rows - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 201 | 78102 | my ($out, $run) = ('', 0); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 78102 | for my $file (0 .. $cols - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 696236 | my $stone = $stones->{ format_point($file, $rank) }; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 696236 | ▶ | if (!defined $stone) { $run++; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 213119 | ▶ | $out .= $run if $run; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 213119 | $run = 0; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 213119 | $out .= $stone; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 78102 | ▶ | $out .= $run if $run; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 78102 | push @ranks, $out; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 15784 | return join('/', @ranks) . " $side"; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 19469 | ▶ | sub parse_position { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_position: called CC=24 SCAR=31.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 19469 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 19469 | ▶ | return $fail->('empty') unless defined $string && length $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $string and length $string
MC/DC100%2/2
defined $string and length $string
defined $string
length $string
Truth table100%3/3
A and B
A= defined $stringB= length $string
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 19467 | ▶ | return $fail->('too_long') if length $string > 80; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 19466 | my @field = split / /, $string, -1; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 19466 | ▶ | return $fail->('bad_shape') unless @field == 2 || @field == 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@field == 2 or @field == 4
MC/DC100%2/2
@field == 2 or @field == 4
@field == 2
@field == 4
Truth table100%3/3
A or B
A= @field == 2B= @field == 4
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 18887 | my ($board, $side, $quiet, $number) = @field; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 18887 | ▶ | return $fail->('bad_letter') if $board =~ m{[^wb1-9/]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 17769 | my @ranks = split m{/}, $board, -1; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 17769 | ▶ | return $fail->('rows') unless @ranks == 3 || @ranks == 5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@ranks == 3 or @ranks == 5
MC/DC100%2/2
@ranks == 3 or @ranks == 5
@ranks == 3
@ranks == 5
Truth table100%3/3
A or B
A= @ranks == 3B= @ranks == 5
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 17290 | ▶ | my @width = map { my $n = 0; $n += /[1-9]/ ? $_ : 1 for split //, $_; $n } @ranks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 17290 | my $cols = $width[0]; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 17290 | ▶ | return $fail->('width') if grep { $_ != $cols } @width; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 16041 | ▶ | return $fail->('width') unless $size_ok->($cols, scalar @ranks); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 16040 | ▶ | return $fail->('side') unless $side eq 'w' || $side eq 'b'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$side eq "w" or $side eq "b"
MC/DC100%2/2
$side eq "w" or $side eq "b"
$side eq "w"
$side eq "b"
Truth table100%3/3
A or B
A= $side eq "w"B= $side eq "b"
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 15755 | ▶ | my $counted = @field == 4 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 15755 | ▶ | if ($counted) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 4647 | ▶ | return $fail->('bad_count') unless $quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 4644 | ▶ | return $fail->('bad_count') unless $number =~ /\A[1-9][0-9]{0,5}\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 15750 | my $rows = @ranks; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 15750 | my %stones; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 15750 | for my $i (0 .. $#ranks) { | |||||||||||||||||||||||||||||||||||||||||
| 241 | 77938 | my $rank = $rows - 1 - $i; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 77938 | my $file = 0; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 77938 | for my $c (split //, $ranks[$i]) { | |||||||||||||||||||||||||||||||||||||||||
| 244 | 345335 | ▶ | if ($c =~ /[1-9]/) { $file += $c; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 212520 | $stones{ format_point($file, $rank) } = $c; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 212520 | $file++; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 15750 | ▶ | cols => $cols, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | rows => $rows, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | side => $side, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | stones => \%stones, | ||||||||||||||||||||||||||||||||||||||||||
| 254 | board => $write_board->($cols, $rows, \%stones, $side), | ||||||||||||||||||||||||||||||||||||||||||
| 255 | counted => $counted, | ||||||||||||||||||||||||||||||||||||||||||
| 256 | quiet => $counted ? $quiet + 0 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 257 | move => $counted ? $number + 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 4649 | ▶ | sub format_position { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_position: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 4649 | my ($board, $quiet, $number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 4649 | ▶ | $quiet = 0 unless defined $quiet; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4649 | ▶ | $number = 1 unless defined $number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 4649 | ▶ | my $position = parse_position($board) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4648 | ▶ | return undef if $position->{counted}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 4647 | ▶ | return undef unless $quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/ && $number =~ /\A[1-9][0-9]{0,5}\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/u and $number =~ /\A[1-9][0-9]{0,5}\z/u
MC/DC100%2/2
$quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/u and $number =~ /\A[1-9][0-9]{0,5}\z/u
$quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/u
$number =~ /\A[1-9][0-9]{0,5}\z/u
Truth table100%3/3
A and B
A= $quiet =~ /\A(?:0|[1-9][0-9]{0,5})\z/uB= $number =~ /\A[1-9][0-9]{0,5}\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 4645 | return "$position->{board} $quiet $number"; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 36 | ▶ | sub mirror_position { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mirror_position: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 36 | my ($string, $how) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 36 | ▶ | my $position = parse_position($string) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 35 | my ($cols, $rows) = @{$position}{qw(cols rows)}; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 35 | my %stones; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 35 | for my $name (keys %{ $position->{stones} }) { | |||||||||||||||||||||||||||||||||||||||||
| 277 | 600 | ▶ | my @to = $mirror->($how // '', $cols, $rows, parse_point($name, cols => $cols, rows => $rows)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$how // ""
MC/DC0%0/1
$how // ""
$how
Truth table50%1/2
A
A= $how
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 599 | $stones{ format_point(@to) } = $position->{stones}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 34 | my $text = $write_board->($cols, $rows, \%stones, $position->{side}); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 34 | ▶ | return $position->{counted} ? "$text $position->{quiet} $position->{move}" : $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 144 | ▶ | my $variant_size = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 144 | my ($variant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 144 | ▶ | return @{ $BOARD{$variant} } if exists $BOARD{$variant}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | return ($1, $2) if $variant =~ /\A([0-9])x([0-9])\z/ && $size_ok->($1, $2); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$variant =~ /\A([0-9])x([0-9])\z/u and &$size_ok($1, $2)
MC/DC100%2/2
$variant =~ /\A([0-9])x([0-9])\z/u and &$size_ok($1, $2)
$variant =~ /\A([0-9])x([0-9])\z/u
&$size_ok($1, $2)
Truth table100%3/3
A and B
A= $variant =~ /\A([0-9])x([0-9])\z/uB= &$size_ok($1, $2)
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 74 | ▶ | sub format_game { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_game: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 74 | my ($game) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 74 | ▶ | return undef unless ref $game eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 73 | my %header = (variant => 'sivy', map { $_ => $game->{$_} } grep { defined $game->{$_} } @HEADER); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 73 | ▶ | return undef if grep { !$HEADER{$_} && $_ ne 'moves' } keys %$game; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
!$HEADER{$_} && $_ ne 'moves'
MC/DC100%2/2
!$HEADER{$_} && $_ ne 'moves'
!$HEADER{$_}
$_ ne 'moves'
Truth table100%3/3
not(A) && B
A= !$HEADER{$_}B= $_ ne 'moves'
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 72 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 72 | ▶ | return undef unless ref $moves eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 71 | my $text = "fanorona 1\n"; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 71 | for my $key (@HEADER) { | |||||||||||||||||||||||||||||||||||||||||
| 301 | 562 | ▶ | next unless defined $header{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 203 | ▶ | return undef if $header{$key} =~ /[^\x20-\x7e]/ || $header{$key} !~ /\S/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$header{$key} =~ /[^\x20-\x7e]/u or not $header{$key} =~ /\S/u
MC/DC100%2/2
$header{$key} =~ /[^\x20-\x7e]/u or not $header{$key} =~ /\S/u
$header{$key} =~ /[^\x20-\x7e]/u
not $header{$key} =~ /\S/u
Truth table100%3/3
A or not(B)
A= $header{$key} =~ /[^\x20-\x7e]/uB= not $header{$key} =~ /\S/u
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 200 | $text .= "$key $header{$key}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 68 | $text .= "moves\n"; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 68 | $text .= "$_\n" for @$moves; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 68 | ▶ | return undef unless parse_game($text); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 67 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 156 | ▶ | sub parse_game { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_game: called CC=22 SCAR=30.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 156 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 156 | ▶ | return $fail->('empty', 0) unless defined $text && length $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and length $text
MC/DC50%1/2
defined $text and length $text
defined $text
length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 155 | my @lines = split /\n/, $text; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 155 | ▶ | return $fail->('not_a_game', 1) unless @lines && $lines[0] eq 'fanorona 1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@lines and $lines[0] eq "fanorona 1"
MC/DC50%1/2
@lines and $lines[0] eq "fanorona 1"
@lines
$lines[0] eq "fanorona 1"
Truth table66%2/3
A and B
A= @linesB= $lines[0] eq "fanorona 1"
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 150 | my (%game, $n); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 150 | ▶ | for ($n = 1; $n < @lines; $n++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 550 | my $line = $lines[$n]; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 550 | ▶ | last if $line eq 'moves'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 406 | ▶ | return $fail->('bad_header', $n + 1) unless $line =~ /\A([a-z_]+) (\S.*)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 404 | my ($key, $value) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 404 | ▶ | return $fail->('unknown_header', $n + 1) unless $HEADER{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 403 | ▶ | return $fail->('repeated_header', $n + 1) if exists $game{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 402 | ▶ | return $fail->('bad_header', $n + 1) if $value =~ /[^\x20-\x7e]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 402 | ▶ | return $fail->('bad_number', $n + 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key =~ /\A(?:quiet_limit|repeat|ply_cap)\z/u and not $value =~ /\A(?:0|[1-9][0-9]{0,5})\z/u
MC/DC100%2/2
$key =~ /\A(?:quiet_limit|repeat|ply_cap)\z/u and not $value =~ /\A(?:0|[1-9][0-9]{0,5})\z/u
$key =~ /\A(?:quiet_limit|repeat|ply_cap)\z/u
not $value =~ /\A(?:0|[1-9][0-9]{0,5})\z/u
Truth table100%3/3
A and not(B)
A= $key =~ /\A(?:quiet_limit|repeat|ply_cap)\z/uB= not $value =~ /\A(?:0|[1-9][0-9]{0,5})\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | if $key =~ /\A(?:quiet_limit|repeat|ply_cap)\z/ && $value !~ /\A(?:0|[1-9][0-9]{0,5})\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 401 | $game{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 145 | ▶ | return $fail->('no_moves_line', scalar @lines) unless $n < @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 144 | my $moves_at = $n; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 144 | ▶ | $game{variant} = 'sivy' unless defined $game{variant}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | my ($cols, $rows) = $variant_size->($game{variant}) | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 144 | ▶ | or return $fail->('bad_variant', 2); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 142 | ▶ | if (defined $game{start}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 5 | ▶ | my $start = parse_position($game{start}) or return $fail->('bad_start', 2); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 4 | ▶ | return $fail->('bad_start', 2) unless $start->{cols} == $cols && $start->{rows} == $rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$start->{"cols"} == $cols and $start->{"rows"} == $rows
MC/DC50%1/2
$start->{"cols"} == $cols and $start->{"rows"} == $rows
$start->{"cols"} == $cols
$start->{"rows"} == $rows
Truth table66%2/3
A and B
A= $start->{"cols"} == $colsB= $start->{"rows"} == $rows
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 140 | my @moves; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 140 | for my $i ($moves_at + 1 .. $#lines) { | |||||||||||||||||||||||||||||||||||||||||
| 343 | 4974 | my $move = $lines[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 4974 | my ($parsed, $reason) = parse_move($move, cols => $cols, rows => $rows); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 4974 | ▶ | return $fail->($reason, $i + 1) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 4969 | push @moves, $move; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 135 | $game{moves} = \@moves; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 135 | $game{moves_at} = $moves_at + 2; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 135 | $game{cols} = $cols; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 135 | $game{rows} = $rows; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 135 | return \%game; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | __END__ | ||||||||||||||||||||||||||||||||||||||||||