| 1 | package Game::Brandubh::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | 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 | 3 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use constant SETUP => '3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my $SQUARE = qr/[a-g][1-7]/; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 18 | ▶ | sub _plain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 18 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 18 | ▶ | return undef if !defined $text || ref $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $text or ref $text
MC/DC50%1/2
not defined $text or ref $text
not defined $text
ref $text
Truth table66%2/3
not(A) or B
A= not defined $textB= ref $text
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | return "$text"; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | sub square_name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
square_name: called CC=5 SCAR=19.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my ($file, $rank) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | return undef unless defined $file && defined $rank; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $file and defined $rank
MC/DC0%0/2
defined $file and defined $rank
defined $file
defined $rank
Truth table33%1/3
A and B
A= defined $fileB= defined $rank
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | return undef unless $file =~ /\A[0-6]\z/ && $rank =~ /\A[0-6]\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file =~ /\A[0-6]\z/ and $rank =~ /\A[0-6]\z/
MC/DC0%0/2
$file =~ /\A[0-6]\z/ and $rank =~ /\A[0-6]\z/
$file =~ /\A[0-6]\z/
$rank =~ /\A[0-6]\z/
Truth table33%1/3
A and B
A= $file =~ /\A[0-6]\z/B= $rank =~ /\A[0-6]\z/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | return chr(ord('a') + $file) . ($rank + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub square_parse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
square_parse: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | my ($f, $r) = lc($text) =~ /\A([a-g])([1-7])\z/ or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | return (ord($f) - ord('a'), $r - 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub move_wire { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_wire: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my $from = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $to = _plain($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | return undef unless defined $from && defined $to; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $from and defined $to
MC/DC0%0/2
defined $from and defined $to
defined $from
defined $to
Truth table33%1/3
A and B
A= defined $fromB= defined $to
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ($from, $to) = (lc $from, lc $to); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | return undef unless $from =~ /\A$SQUARE\z/ && $to =~ /\A$SQUARE\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$from =~ /\A$SQUARE\z/ and $to =~ /\A$SQUARE\z/
MC/DC0%0/2
$from =~ /\A$SQUARE\z/ and $to =~ /\A$SQUARE\z/
$from =~ /\A$SQUARE\z/
$to =~ /\A$SQUARE\z/
Truth table33%1/3
A and B
A= $from =~ /\A$SQUARE\z/B= $to =~ /\A$SQUARE\z/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return $from . $to; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | sub move_split { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_split: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | my ($from, $to) = $text =~ /\A($SQUARE)($SQUARE)\z/ or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | return ($from, $to); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub move_parse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_parse: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $text = lc $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $text =~ s/\A\s+//; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | 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 | 1 | return $from . $to; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub move_display { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move_display: called CC=9 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my ($wire, $about) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | my ($from, $to) = move_split($wire) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $about = {} unless ref $about eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | my @captures = sort grep { /\A$SQUARE\z/ } map { lc } grep { defined && !ref } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && !ref($_)
MC/DC0%0/2
defined $_ && !ref($_)
defined $_
!ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | @{ ref $about->{captures} eq 'ARRAY' ? $about->{captures} : [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | my $text = ($about->{king} ? 'K' : '') . $from . '-' . $to; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | $text .= 'x' . join(',', @captures) if @captures; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($about->{king_home}) { $text .= '++' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | elsif ($about->{king_taken}) { $text .= '#' } | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | sub position_ok { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position_ok: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | return 0 unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | return 0 unless $text =~ m{\A ([adk1-7]+ (?: / [adk1-7]+ ){6}) [ ] [ad] \z}x; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | for my $row (split m{/}, $1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 14 | ▶ | $width += /[1-7]/ ? $_ : 1 for split //, $row; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 14 | ▶ | return 0 unless $width == 7; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | sub position_cells { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position_cells: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | return unless position_ok($text); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my ($rows, $side) = split / /, $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my @board; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | for my $row (split m{/}, $rows) { | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | my @cells; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | for my $ch (split //, $row) { | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | ▶ | if ($ch =~ /[1-7]/) { push @cells, ('') x $ch } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 13 | else { push @cells, $ch } | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | push @board, \@cells; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | return (\@board, $side); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | sub game_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
game_string: called CC=21 SCAR=45.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | my ($game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | return undef unless ref $game eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $variant = _plain($game->{variant}); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | $variant = 'brandubh' unless defined $variant && length $variant; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $variant and length $variant
MC/DC0%0/2
defined $variant and length $variant
defined $variant
length $variant
Truth table33%1/3
A and B
A= defined $variantB= length $variant
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | return undef if $variant =~ /[\r\n]/ || $variant !~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$variant =~ /[\r\n]/ or not $variant =~ /\S/
MC/DC0%0/2
$variant =~ /[\r\n]/ or not $variant =~ /\S/
$variant =~ /[\r\n]/
not $variant =~ /\S/
Truth table33%1/3
A or not(B)
A= $variant =~ /[\r\n]/B= not $variant =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my @moves; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | 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 | 2 | ▶ | my ($from, $to) = move_split($move) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | push @moves, $from . $to; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my @lines = ("variant $variant"); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my $attackers = _plain($game->{attackers}); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | if (defined $attackers && $attackers ne 'p1') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $attackers and $attackers ne "p1"
MC/DC0%0/2
defined $attackers and $attackers ne "p1"
defined $attackers
$attackers ne "p1"
Truth table33%1/3
A and B
A= defined $attackersB= $attackers ne "p1"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return undef unless $attackers eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | push @lines, "attackers $attackers"; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | my $start = _plain($game->{start}); | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if (defined $start && $start ne SETUP) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $start and $start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
MC/DC0%0/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 table33%1/3
A and B
A= defined $startB= $start ne "3a3/3a3/3d3/aadkdaa/3d3/3a3/3a3 a"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return undef unless position_ok($start); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | push @lines, "start $start"; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | push @lines, join(' ', 'moves', @moves); | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | my $result = $game->{result}; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if (defined $result) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $line = _result_line($result); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return undef unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | push @lines, "result $line"; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my $offer = _plain($game->{offer}); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | if (defined $offer) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | return undef unless ($offer eq 'p1' || $offer eq 'p2') && !defined $result; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$offer eq "p1" || $offer eq "p2" and not defined $result
$offer eq "p1" or $offer eq "p2"
MC/DC0%0/3
$offer eq "p1" || $offer eq "p2" and not defined $result
$offer eq "p1"
$offer eq "p2"
not defined $result
Truth table0%0/5
A or B and not(C)
A= $offer eq "p1"B= $offer eq "p2"C= not defined $result
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | push @lines, "offer $offer"; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | return join("\n", @lines) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _result_line { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_line: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my ($result) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return undef unless ref $result eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $how = $result->{how} // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{"how"} // ""
MC/DC0%0/1
$result->{"how"} // ""
$result->{"how"}
Truth table0%0/2
A
A= $result->{"how"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return 'agreed' if $how eq 'agreed'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ($how eq 'resign') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $by = $result->{by} // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{"by"} // ""
MC/DC0%0/1
$result->{"by"} // ""
$result->{"by"}
Truth table0%0/2
A
A= $result->{"by"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | return "resign $by" if $by eq 'attackers' || $by eq 'defenders'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$by eq "attackers" or $by eq "defenders"
MC/DC0%0/2
$by eq "attackers" or $by eq "defenders"
$by eq "attackers"
$by eq "defenders"
Truth table0%0/3
A or B
A= $by eq "attackers"B= $by eq "defenders"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | sub game_parse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
game_parse: called CC=26 SCAR=49.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my $text = _plain($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | my @lines = grep { /\S/ } split /\r?\n/, $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my %game = (start => SETUP, moves => [], result => undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | my ($word, $rest) = $line =~ /\A(\w+)(?:[ ](.*))?\z/ or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | $rest = '' unless defined $rest; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | return undef if $seen{$word}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | if ($word eq 'variant') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | return undef unless $rest =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | $game{variant} = $rest; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | elsif ($word eq 'attackers') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return undef unless $rest eq 'p1' || $rest eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rest eq "p1" or $rest eq "p2"
MC/DC0%0/2
$rest eq "p1" or $rest eq "p2"
$rest eq "p1"
$rest eq "p2"
Truth table0%0/3
A or B
A= $rest eq "p1"B= $rest eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $game{attackers} = $rest; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif ($word eq 'offer') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | return undef unless $rest eq 'p1' || $rest eq 'p2'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rest eq "p1" or $rest eq "p2"
MC/DC0%0/2
$rest eq "p1" or $rest eq "p2"
$rest eq "p1"
$rest eq "p2"
Truth table0%0/3
A or B
A= $rest eq "p1"B= $rest eq "p2"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $game{offer} = $rest; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | elsif ($word eq 'start') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | return undef unless position_ok($rest); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $game{start} = $rest; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif ($word eq 'moves') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | for my $move (split ' ', $rest) { | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | my ($from, $to) = move_split($move) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | push @{ $game{moves} }, $from . $to; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | elsif ($word eq 'result') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($rest eq 'agreed') { $game{result} = { how => 'agreed' } } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | elsif ($rest =~ /\Aresign (attackers|defenders)\z/) { $game{result} = { how => 'resign', by => $1 } } | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | else { return undef } | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | return undef unless $seen{variant} && $seen{moves}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$seen{"variant"} and $seen{"moves"}
MC/DC0%0/2
$seen{"variant"} and $seen{"moves"}
$seen{"variant"}
$seen{"moves"}
Truth table33%1/3
A and B
A= $seen{"variant"}B= $seen{"moves"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | return undef if defined $game{offer} && defined $game{result}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $game{"offer"} and defined $game{"result"}
MC/DC0%0/2
defined $game{"offer"} and defined $game{"result"}
defined $game{"offer"}
defined $game{"result"}
Truth table33%1/3
A and B
A= defined $game{"offer"}B= defined $game{"result"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | return \%game; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||