| 1 | package Game::Brandubh::Notation; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 46 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 46 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 46 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 46 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 46 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 46 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 12 | SETUP | ||||||||||||||||||||||||||||
| 13 | square_name square_parse | ||||||||||||||||||||||||||||
| 14 | move_wire move_split move_parse move_display | ||||||||||||||||||||||||||||
| 15 | position_ok position_cells | ||||||||||||||||||||||||||||
| 16 | game_string game_parse | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | 46 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 46 | ▶ | use constant SETUP => '3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 46 | my $SQUARE = qr/[a-g][1-7]/; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1013740 | ▶ | sub _plain { | ||||||||||||||||||||||||||
|
Subroutine
_plain: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 25 | 1013740 | my ($text) = @_; | |||||||||||||||||||||||||||
| 26 | 1013740 | ▶ | return undef if !defined $text || ref $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $text or ref $text
MC/DC100%2/2
not defined $text or ref $text
not defined $text
ref $text
Truth table100%3/3
not(A) or B
A= not defined $textB= ref $text
| |||||||||||||||||||||||||||||
| 27 | 1013695 | return "$text"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3033080 | ▶ | sub square_name { | ||||||||||||||||||||||||||
|
Subroutine
square_name: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 3033080 | my ($file, $rank) = @_; | |||||||||||||||||||||||||||
| 32 | 3033080 | ▶ | return undef unless defined $file && defined $rank; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $file and defined $rank
MC/DC100%2/2
defined $file and defined $rank
defined $file
defined $rank
Truth table100%3/3
A and B
A= defined $fileB= defined $rank
| |||||||||||||||||||||||||||||
| 33 | 3033078 | ▶ | return undef unless $file =~ /\A[0-6]\z/ && $rank =~ /\A[0-6]\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$file =~ /\A[0-6]\z/ and $rank =~ /\A[0-6]\z/
MC/DC100%2/2
$file =~ /\A[0-6]\z/ and $rank =~ /\A[0-6]\z/
$file =~ /\A[0-6]\z/
$rank =~ /\A[0-6]\z/
Truth table100%3/3
A and B
A= $file =~ /\A[0-6]\z/B= $rank =~ /\A[0-6]\z/
| |||||||||||||||||||||||||||||
| 34 | 3033071 | return chr(ord('a') + $file) . ($rank + 1); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 361982 | ▶ | sub square_parse { | ||||||||||||||||||||||||||
|
Subroutine
square_parse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 361982 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 39 | 361982 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 361977 | ▶ | my ($f, $r) = lc($text) =~ /\A([a-g])([1-7])\z/ or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 361954 | return (ord($f) - ord('a'), $r - 1); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2425 | ▶ | sub move_wire { | ||||||||||||||||||||||||||
|
Subroutine
move_wire: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 2425 | my $from = _plain($_[0]); | |||||||||||||||||||||||||||
| 46 | 2425 | my $to = _plain($_[1]); | |||||||||||||||||||||||||||
| 47 | 2425 | ▶ | return undef unless defined $from && defined $to; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $from and defined $to
MC/DC50%1/2
defined $from and defined $to
defined $from
defined $to
Truth table66%2/3
A and B
A= defined $fromB= defined $to
| |||||||||||||||||||||||||||||
| 48 | 2424 | ($from, $to) = (lc $from, lc $to); | |||||||||||||||||||||||||||
| 49 | 2424 | ▶ | return undef unless $from =~ /\A$SQUARE\z/ && $to =~ /\A$SQUARE\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$from =~ /\A$SQUARE\z/ and $to =~ /\A$SQUARE\z/
MC/DC100%2/2
$from =~ /\A$SQUARE\z/ and $to =~ /\A$SQUARE\z/
$from =~ /\A$SQUARE\z/
$to =~ /\A$SQUARE\z/
Truth table100%3/3
A and B
A= $from =~ /\A$SQUARE\z/B= $to =~ /\A$SQUARE\z/
| |||||||||||||||||||||||||||||
| 50 | 2407 | return $from . $to; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 416021 | ▶ | sub move_split { | ||||||||||||||||||||||||||
|
Subroutine
move_split: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 416021 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 55 | 416021 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 416018 | ▶ | my ($from, $to) = $text =~ /\A($SQUARE)($SQUARE)\z/ or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 415962 | return ($from, $to); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 224793 | ▶ | sub move_parse { | ||||||||||||||||||||||||||
|
Subroutine
move_parse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 224793 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 62 | 224793 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 224788 | $text = lc $text; | |||||||||||||||||||||||||||
| 64 | 224788 | $text =~ s/\A\s+//; | |||||||||||||||||||||||||||
| 65 | 224788 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||
| 66 | 224788 | ▶ | my ($from, $to) = $text =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | k? | ||||||||||||||||||||||||||||
| 68 | ($SQUARE) -? ($SQUARE) | ||||||||||||||||||||||||||||
| 69 | (?: x $SQUARE (?: , $SQUARE )* )? | ||||||||||||||||||||||||||||
| 70 | (?: \# | \+\+ )? | ||||||||||||||||||||||||||||
| 71 | \z/x or return undef; | ||||||||||||||||||||||||||||
| 72 | 224725 | return $from . $to; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 219885 | ▶ | sub move_display { | ||||||||||||||||||||||||||
|
Subroutine
move_display: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 219885 | my ($wire, $about) = @_; | |||||||||||||||||||||||||||
| 77 | 219885 | ▶ | my ($from, $to) = move_split($wire) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 219875 | ▶ | $about = {} unless ref $about eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 9469 | ▶ | my @captures = sort grep { /\A$SQUARE\z/ } map { lc } grep { defined && !ref } | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $_ && !ref($_)
MC/DC100%2/2
defined $_ && !ref($_)
defined $_
!ref($_)
Truth table100%3/3
A && not(B)
A= defined $_B= !ref($_)
| |||||||||||||||||||||||||||||
| 81 | 219875 | ▶ | @{ ref $about->{captures} eq 'ARRAY' ? $about->{captures} : [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 219875 | ▶ | my $text = ($about->{king} ? 'K' : '') . $from . '-' . $to; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 219875 | ▶ | $text .= 'x' . join(',', @captures) if @captures; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 219875 | ▶ | if ($about->{king_home}) { $text .= '++' } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 86 | 643 | elsif ($about->{king_taken}) { $text .= '#' } | |||||||||||||||||||||||||||
| 87 | 219875 | return $text; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 4872 | ▶ | sub position_ok { | ||||||||||||||||||||||||||
|
Subroutine
position_ok: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 4872 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 92 | 4872 | ▶ | return 0 unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 4870 | ▶ | return 0 unless $text =~ m{\A ([adk1-7]+ (?: / [adk1-7]+ ){6}) [ ] [ad] \z}x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 4230 | for my $row (split m{/}, $1) { | |||||||||||||||||||||||||||
| 95 | 28562 | my $width = 0; | |||||||||||||||||||||||||||
| 96 | 28562 | ▶ | $width += /[1-7]/ ? $_ : 1 for split //, $row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 28562 | ▶ | return 0 unless $width == 7; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 3897 | return 1; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | ▶ | sub position_cells { | ||||||||||||||||||||||||||
|
Subroutine
position_cells: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 4 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 104 | 4 | ▶ | return unless position_ok($text); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 3 | my ($rows, $side) = split / /, $text; | |||||||||||||||||||||||||||
| 106 | 3 | my @board; | |||||||||||||||||||||||||||
| 107 | 3 | for my $row (split m{/}, $rows) { | |||||||||||||||||||||||||||
| 108 | 21 | my @cells; | |||||||||||||||||||||||||||
| 109 | 21 | for my $ch (split //, $row) { | |||||||||||||||||||||||||||
| 110 | 59 | ▶ | if ($ch =~ /[1-7]/) { push @cells, ('') x $ch } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 28 | else { push @cells, $ch } | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 21 | push @board, \@cells; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 3 | return (\@board, $side); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 470 | ▶ | sub game_string { | ||||||||||||||||||||||||||
|
Subroutine
game_string: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 470 | my ($game) = @_; | |||||||||||||||||||||||||||
| 120 | 470 | ▶ | return undef unless ref $game eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 469 | my $variant = _plain($game->{variant}); | |||||||||||||||||||||||||||
| 123 | 469 | ▶ | $variant = 'brandubh' unless defined $variant && length $variant; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $variant and length $variant
MC/DC50%1/2
defined $variant and length $variant
defined $variant
length $variant
Truth table66%2/3
A and B
A= defined $variantB= length $variant
| |||||||||||||||||||||||||||||
| 124 | 469 | ▶ | return undef if $variant =~ /[\r\n]/ || $variant !~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$variant =~ /[\r\n]/ or not $variant =~ /\S/
MC/DC50%1/2
$variant =~ /[\r\n]/ or not $variant =~ /\S/
$variant =~ /[\r\n]/
not $variant =~ /\S/
Truth table66%2/3
A or not(B)
A= $variant =~ /[\r\n]/B= not $variant =~ /\S/
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 468 | my @moves; | |||||||||||||||||||||||||||
| 127 | 468 | ▶ | for my $move (@{ $game->{moves} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$game->{'moves'} || []
MC/DC0%0/1
$game->{'moves'} || []
$game->{'moves'}
Truth table50%1/2
A
A= $game->{'moves'}
| |||||||||||||||||||||||||||||
| 128 | 8585 | ▶ | my ($from, $to) = move_split($move) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 8576 | push @moves, $from . $to; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 459 | my @lines = ("variant $variant"); | |||||||||||||||||||||||||||
| 133 | 459 | my $start = _plain($game->{start}); | |||||||||||||||||||||||||||
| 134 | 459 | ▶ | if (defined $start && $start ne SETUP) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $start and $start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
MC/DC100%2/2
defined $start and $start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
defined $start
$start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
Truth table100%3/3
A and B
A= defined $startB= $start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
| |||||||||||||||||||||||||||||
| 135 | 202 | ▶ | return undef unless position_ok($start); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 201 | push @lines, "start $start"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 458 | push @lines, join(' ', 'moves', @moves); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 458 | my $result = $game->{result}; | |||||||||||||||||||||||||||
| 141 | 458 | ▶ | if (defined $result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 105 | my $line = _result_line($result); | |||||||||||||||||||||||||||
| 143 | 105 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 102 | push @lines, "result $line"; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 455 | return join("\n", @lines) . "\n"; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 105 | ▶ | sub _result_line { | ||||||||||||||||||||||||||
|
Subroutine
_result_line: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 150 | 105 | my ($result) = @_; | |||||||||||||||||||||||||||
| 151 | 105 | ▶ | return undef unless ref $result eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 104 | ▶ | my $how = $result->{how} // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"how"} // ""
MC/DC0%0/1
$result->{"how"} // ""
$result->{"how"}
Truth table50%1/2
A
A= $result->{"how"}
| |||||||||||||||||||||||||||||
| 153 | 104 | ▶ | return 'agreed' if $how eq 'agreed'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 71 | ▶ | if ($how eq 'resign') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 70 | ▶ | my $by = $result->{by} // ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$result->{"by"} // ""
MC/DC100%1/1
$result->{"by"} // ""
$result->{"by"}
Truth table100%2/2
A
A= $result->{"by"}
| |||||||||||||||||||||||||||||
| 156 | 70 | ▶ | return "resign $by" if $by eq 'attackers' || $by eq 'defenders'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$by eq "attackers" or $by eq "defenders"
MC/DC100%2/2
$by eq "attackers" or $by eq "defenders"
$by eq "attackers"
$by eq "defenders"
Truth table100%3/3
A or B
A= $by eq "attackers"B= $by eq "defenders"
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 2 | return undef; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 290 | ▶ | sub game_parse { | ||||||||||||||||||||||||||
|
Subroutine
game_parse: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 290 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||
| 163 | 290 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 288 | my @lines = grep { /\S/ } split /\r?\n/, $text; | |||||||||||||||||||||||||||
| 166 | 288 | my %game = (start => SETUP, moves => [], result => undef); | |||||||||||||||||||||||||||
| 167 | 288 | my %seen; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 288 | for my $line (@lines) { | |||||||||||||||||||||||||||
| 170 | 720 | ▶ | my ($word, $rest) = $line =~ /\A(\w+)(?:[ ](.*))?\z/ or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 720 | ▶ | $rest = '' unless defined $rest; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 720 | ▶ | return undef if $seen{$word}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 719 | ▶ | if ($word eq 'variant') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 175 | 281 | ▶ | return undef unless $rest =~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 280 | $game{variant} = $rest; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | elsif ($word eq 'start') { | ||||||||||||||||||||||||||||
| 179 | 102 | ▶ | return undef unless position_ok($rest); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 101 | $game{start} = $rest; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | elsif ($word eq 'moves') { | ||||||||||||||||||||||||||||
| 183 | 277 | for my $move (split ' ', $rest) { | |||||||||||||||||||||||||||
| 184 | 5486 | ▶ | my ($from, $to) = move_split($move) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 5474 | push @{ $game{moves} }, $from . $to; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | elsif ($word eq 'result') { | ||||||||||||||||||||||||||||
| 189 | 55 | ▶ | if ($rest eq 'agreed') { $game{result} = { how => 'agreed' } } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 190 | 36 | elsif ($rest =~ /\Aresign (attackers|defenders)\z/) { $game{result} = { how => 'resign', by => $1 } } | |||||||||||||||||||||||||||
| 191 | 2 | else { return undef } | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||
| 194 | 4 | return undef; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 267 | ▶ | return undef unless $seen{variant} && $seen{moves}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seen{"variant"} and $seen{"moves"}
MC/DC100%2/2
$seen{"variant"} and $seen{"moves"}
$seen{"variant"}
$seen{"moves"}
Truth table100%3/3
A and B
A= $seen{"variant"}B= $seen{"moves"}
| |||||||||||||||||||||||||||||
| 198 | 260 | return \%game; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 46 | 1; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | __END__ | ||||||||||||||||||||||||||||