| 1 | package Game::Sternhalma::Notation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 55 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 55 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 55 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 55 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 55 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | HOLES SETUP_TWO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | name_of hole_of row_len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | parse_move format_move | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | parse_position format_position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | format_game parse_game | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 55 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 55 | ▶ | use constant HOLES => 121; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 55 | ▶ | use constant SETUP_TWO => '0/00/000/0000/[13]/[12]/[11]/[10]/[9]/[10]/[11]/[12]/[13]/1111/111/11/1 0 2 10'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 55 | my @ROW_LEN = (1, 2, 3, 4, 13, 12, 11, 10, 9, 10, 11, 12, 13, 4, 3, 2, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 55 | my @LETTER = ('a' .. 'q'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 55 | my (@ROW_START, @NAME, %HOLE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 55 | my $h = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 55 | for my $r (0 .. $#ROW_LEN) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 935 | $ROW_START[$r] = $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 935 | for my $c (1 .. $ROW_LEN[$r]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6655 | $NAME[$h] = $LETTER[$r] . $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 6655 | $HOLE{ $NAME[$h] } = $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6655 | $h++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 55 | my %LAYOUT = (1 => 1, 2 => 1, 3 => 1, 4 => 1, 6 => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 333973 | ▶ | sub _is_int { defined $_[0] && $_[0] =~ /\A[0-9]+\z/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_int: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 18 | ▶ | sub row_len { _is_int($_[0]) && $_[0] < @ROW_LEN ? $ROW_LEN[ $_[0] ] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row_len: called CC=3 SCAR=14.2
Pod
documented
Branch: 1 branch
Condition33%1/3
_is_int($_[0]) and $_[0] < @ROW_LEN
MC/DC0%0/2
_is_int($_[0]) and $_[0] < @ROW_LEN
_is_int($_[0])
$_[0] < @ROW_LEN
Truth table33%1/3
A and B
A= _is_int($_[0])B= $_[0] < @ROW_LEN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 333954 | ▶ | sub name_of { _is_int($_[0]) && $_[0] < HOLES ? $NAME[ $_[0] ] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_of: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
_is_int($_[0]) and $_[0] < 121
MC/DC100%2/2
_is_int($_[0]) and $_[0] < 121
_is_int($_[0])
$_[0] < 121
Truth table100%3/3
A and B
A= _is_int($_[0])B= $_[0] < 121
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 308683 | ▶ | sub hole_of { defined $_[0] ? $HOLE{ $_[0] } : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hole_of: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # ---- moves -------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 106992 | ▶ | sub parse_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_move: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 106992 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 106992 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 106992 | ▶ | return { kind => 'pass' } if $text eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 106987 | ▶ | return { kind => 'resign', seat => $1 + 0 } if $text =~ /\Aresign ([0-5])\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 106596 | ▶ | if ($text =~ /\A([a-q][0-9]{1,2})-([a-q][0-9]{1,2})\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 63696 | my ($f, $t) = (hole_of($1), hole_of($2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 63696 | ▶ | return undef unless defined $f && defined $t && $f != $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $f and defined $t and $f != $t
defined $f and defined $t
MC/DC66%2/3
defined $f and defined $t and $f != $t
defined $f
defined $t
$f != $t
Truth table75%3/4
A and B and C
A= defined $fB= defined $tC= $f != $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 63694 | return { kind => 'step', holes => [ $f, $t ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 42900 | my @names = split /:/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 42900 | ▶ | return undef unless @names >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 42882 | my @holes = map { hole_of($_) } @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 42882 | ▶ | return undef if grep { !defined } @holes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 42881 | ▶ | return undef if $holes[0] == $holes[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 42880 | return { kind => 'chain', holes => \@holes }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 137446 | ▶ | sub format_move { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_move: called CC=12 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 137446 | my ($m) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 137446 | ▶ | return undef unless ref $m eq 'HASH' && defined $m->{kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $m eq "HASH" and defined $m->{"kind"}
MC/DC0%0/2
ref $m eq "HASH" and defined $m->{"kind"}
ref $m eq "HASH"
defined $m->{"kind"}
Truth table33%1/3
A and B
A= ref $m eq "HASH"B= defined $m->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 137446 | ▶ | return 'pass' if $m->{kind} eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 137445 | ▶ | return "resign $m->{seat}" if $m->{kind} eq 'resign' && _is_int($m->{seat}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$m->{"kind"} eq "resign" and _is_int($m->{"seat"})
MC/DC50%1/2
$m->{"kind"} eq "resign" and _is_int($m->{"seat"})
$m->{"kind"} eq "resign"
_is_int($m->{"seat"})
Truth table66%2/3
A and B
A= $m->{"kind"} eq "resign"B= _is_int($m->{"seat"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 137444 | ▶ | my @names = map { name_of($_) } @{ $m->{holes} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$m->{'holes'} || []
MC/DC0%0/1
$m->{'holes'} || []
$m->{'holes'}
Truth table50%1/2
A
A= $m->{'holes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 137444 | ▶ | return undef if @names < 2 || grep { !defined } @names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@names < 2 or grep {not defined $_;} @names
MC/DC0%0/2
@names < 2 or grep {not defined $_;} @names
@names < 2
grep {not defined $_;} @names
Truth table33%1/3
A or B
A= @names < 2B= grep {not defined $_;} @names
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 137444 | ▶ | return join '-', @names if $m->{kind} eq 'step' && @names == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$m->{"kind"} eq "step" and @names == 2
MC/DC50%1/2
$m->{"kind"} eq "step" and @names == 2
$m->{"kind"} eq "step"
@names == 2
Truth table66%2/3
A and B
A= $m->{"kind"} eq "step"B= @names == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 58080 | ▶ | return join ':', @names if $m->{kind} eq 'chain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # ---- the position string ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # The same grammar and the same refusal codes as the engine, written apart from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # it: t/22-notation-no-xs.t holds the two to agreeing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 55 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 55 | POS_OK => 0, POS_NULL => 1, POS_LONG => 2, POS_LETTER => 3, POS_ROWS => 4, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | POS_WIDTH => 5, POS_FIELDS => 6, POS_SEAT => 7, POS_COUNT => 8, POS_GAME => 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 25099 | ▶ | sub _race_over { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_race_over: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 25099 | my ($p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 25099 | my $n = _active_count($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 25099 | ▶ | return $n == 0 || ($p->{seats} > 1 && $n == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$n == 0 || $p->{'seats'} > 1 && $n == 1
$p->{"seats"} > 1 and $n == 1
MC/DC33%1/3
$n == 0 || $p->{'seats'} > 1 && $n == 1
$n == 0
$p->{"seats"} > 1
$n == 1
Truth table50%2/4
A || B and C
A= $n == 0B= $p->{"seats"} > 1C= $n == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 215147 | ▶ | sub _active { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_active: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 215147 | my ($p, $s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 215147 | return !grep { $_ == $s } @{ $p->{finished} }, @{ $p->{resigned} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 50031 | ▶ | sub _active_count { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_active_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 50031 | my ($p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 50031 | return scalar grep { _active($p, $_) } 0 .. $p->{seats} - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 27118 | ▶ | sub parse_position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_position: called CC=27 SCAR=33.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 27118 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 27118 | ▶ | return (undef, POS_NULL) unless defined $str && length $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $str and length $str
MC/DC0%0/2
defined $str and length $str
defined $str
length $str
Truth table33%1/3
A and B
A= defined $strB= length $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 27118 | ▶ | return (undef, POS_LONG) if length($str) >= 512; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 27118 | my ($rows, $fields) = $str =~ /\A([^ ]*)(.*)\z/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 27118 | my $tmp = $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 27118 | ▶ | while (length $tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2124222 | ▶ | next if $tmp =~ s/\A[\/0-5]//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 694044 | ▶ | next if $tmp =~ s/\A\[([1-9][0-9]?)\]// && $1 <= 13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tmp =~ s/\A\[([1-9][0-9]?)\]//u and $1 <= 13
MC/DC100%2/2
$tmp =~ s/\A\[([1-9][0-9]?)\]//u and $1 <= 13
$tmp =~ s/\A\[([1-9][0-9]?)\]//u
$1 <= 13
Truth table100%3/3
A and B
A= $tmp =~ s/\A\[([1-9][0-9]?)\]//uB= $1 <= 13
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1186 | return (undef, POS_LETTER); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 25932 | my @rows = split /\//, $rows, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 25932 | ▶ | return (undef, POS_ROWS) unless @rows == 17; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 25665 | my (@cells, %count, $seat_max); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 25665 | $seat_max = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 25665 | for my $r (0 .. 16) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 434178 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 434178 | my @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 434178 | for my $tok ($rows[$r] =~ /(\[\d+\]|[0-5])/g) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1654589 | ▶ | if ($tok =~ /\[(\d+)\]/) { push @row, (undef) x $1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 970649 | ▶ | else { push @row, $tok + 0; $seat_max = $tok if $tok > $seat_max } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 434178 | ▶ | return (undef, POS_WIDTH) unless @row == $ROW_LEN[$r]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 433894 | push @cells, @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 25381 | ▶ | my ($to_move, $seats, $pieces, $game) = $fields =~ /\A ([0-5]) ([1-6]) ([1-9][0-9]?)(?:;(.*))?\z/s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | or return (undef, POS_FIELDS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | return (undef, POS_FIELDS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 25258 | ▶ | unless $LAYOUT{$seats} && ($pieces == 10 || ($pieces == 15 && $seats <= 3)) && $to_move < $seats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition58%7/12
$LAYOUT{$seats} and $pieces == 10 || $pieces == 15 && $seats <= 3 and $to_move < $seats
$LAYOUT{$seats} and $pieces == 10 || $pieces == 15 && $seats <= 3
$pieces == 10 or $pieces == 15 and $seats <= 3
$pieces == 15 and $seats <= 3
MC/DC20%1/5
$LAYOUT{$seats} and $pieces == 10 || $pieces == 15 && $seats <= 3 and $to_move < $seats
$LAYOUT{$seats}
$pieces == 10
$pieces == 15
$seats <= 3
$to_move < $seats
Truth table28%2/7
A and B or C and D and E
A= $LAYOUT{$seats}B= $pieces == 10C= $pieces == 15D= $seats <= 3E= $to_move < $seats
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 25250 | ▶ | return (undef, POS_SEAT) if $seat_max >= $seats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 25236 | $count{$_}++ for grep { defined } @cells; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 25236 | for my $s (0 .. $seats - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 95850 | ▶ | return (undef, POS_COUNT) unless ($count{$s} || 0) == $pieces; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$count{$s} || 0
MC/DC0%0/1
$count{$s} || 0
$count{$s}
Truth table50%1/2
A
A= $count{$s}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 25196 | my %p = (cells => \@cells, to_move => $to_move + 0, seats => $seats + 0, pieces => $pieces + 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | finished => [], resigned => [], ply => 0, pass_run => 0, cap => 1000 * $seats, how => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 25196 | ▶ | if (defined $game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 25110 | ▶ | _read_game(\%p, $game) or return (undef, POS_GAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 25179 | return (\%p, POS_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 25110 | ▶ | sub _read_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_game: called CC=30 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 25110 | my ($p, $game) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 25110 | ▶ | return 0 unless length $game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 25109 | my $at = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 25109 | my $order = 'frpkco'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 25109 | my $num = qr/(?:0|[1-9][0-9]{0,8})/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 25109 | for my $field (split / /, $game, -1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 59449 | ▶ | my ($k, $v) = $field =~ /\A([a-z])=(.*)\z/ or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 59448 | my $i = index($order, $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 59448 | ▶ | return 0 if $i < $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 59445 | $at = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 59445 | ▶ | if ($k eq 'f' || $k eq 'r') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$k eq "f" or $k eq "r"
MC/DC100%2/2
$k eq "f" or $k eq "r"
$k eq "f"
$k eq "r"
Truth table100%3/3
A or B
A= $k eq "f"B= $k eq "r"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 9247 | ▶ | return 0 unless $v =~ /\A[0-5](?:,[0-5])*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 9247 | my @s = split /,/, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 9247 | my %seen = map { $_ => 1 } @{ $p->{finished} }, @{ $p->{resigned} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 9247 | ▶ | for (@s) { return 0 if $_ >= $p->{seats} || $seen{$_}++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ >= $p->{"seats"} or $seen{$_}++
MC/DC100%2/2
$_ >= $p->{"seats"} or $seen{$_}++
$_ >= $p->{"seats"}
$seen{$_}++
Truth table100%3/3
A or B
A= $_ >= $p->{"seats"}B= $seen{$_}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 9244 | ▶ | $p->{ $k eq 'f' ? 'finished' : 'resigned' } = [ map { $_ + 0 } @s ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif ($k eq 'o') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 169 | ▶ | return 0 unless $v =~ /\A[1-4]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 168 | $p->{how} = $v + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 50029 | ▶ | return 0 unless $v =~ /\A$num\z/ && $v > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v =~ /\A$num\z/u and $v > 0
MC/DC100%2/2
$v =~ /\A$num\z/u and $v > 0
$v =~ /\A$num\z/u
$v > 0
Truth table100%3/3
A and B
A= $v =~ /\A$num\z/uB= $v > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 50027 | $p->{ { p => 'ply', k => 'pass_run', c => 'cap' }->{$k} } = $v + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 25099 | my $how = $p->{how}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 25099 | ▶ | if ($how == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 24931 | ▶ | return 0 if _race_over($p) || $p->{pass_run} >= _active_count($p) || $p->{ply} >= $p->{cap}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
_race_over($p) or $p->{"pass_run"} >= _active_count($p) or $p->{"ply"} >= $p->{"cap"}
_race_over($p) or $p->{"pass_run"} >= _active_count($p)
MC/DC66%2/3
_race_over($p) or $p->{"pass_run"} >= _active_count($p) or $p->{"ply"} >= $p->{"cap"}
_race_over($p)
$p->{"pass_run"} >= _active_count($p)
$p->{"ply"} >= $p->{"cap"}
Truth table75%3/4
A or B or C
A= _race_over($p)B= $p->{"pass_run"} >= _active_count($p)C= $p->{"ply"} >= $p->{"cap"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 24929 | ▶ | return 0 unless _active($p, $p->{to_move}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 25 | ▶ | elsif ($how == 1 || $how == 4) { return 0 unless _race_over($p) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$how == 1 or $how == 4
MC/DC100%2/2
$how == 1 or $how == 4
$how == 1
$how == 4
Truth table100%3/3
A or B
A= $how == 1B= $how == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 141 | ▶ | elsif ($how == 2) { return 0 if _race_over($p) || $p->{ply} < $p->{cap} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_race_over($p) or $p->{"ply"} < $p->{"cap"}
MC/DC50%1/2
_race_over($p) or $p->{"ply"} < $p->{"cap"}
_race_over($p)
$p->{"ply"} < $p->{"cap"}
Truth table66%2/3
A or B
A= _race_over($p)B= $p->{"ply"} < $p->{"cap"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | elsif ($how == 3) { return 0 if _race_over($p) || $p->{pass_run} < _active_count($p) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_race_over($p) or $p->{"pass_run"} < _active_count($p)
MC/DC50%1/2
_race_over($p) or $p->{"pass_run"} < _active_count($p)
_race_over($p)
$p->{"pass_run"} < _active_count($p)
Truth table66%2/3
A or B
A= _race_over($p)B= $p->{"pass_run"} < _active_count($p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 25093 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 25091 | ▶ | sub format_position { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_position: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 25091 | my ($p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 25091 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 25091 | for my $r (0 .. 16) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 426547 | my ($s, $run) = ('', 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 426547 | for my $h ($ROW_START[$r] .. $ROW_START[$r] + $ROW_LEN[$r] - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3036011 | my $c = $p->{cells}[$h]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3036011 | ▶ | if (!defined $c) { $run++; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 953990 | ▶ | $s .= "[$run]" if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 953990 | $run = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 953990 | $s .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 426547 | ▶ | $s .= "[$run]" if $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 426547 | push @rows, $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 25091 | my $str = join('/', @rows) . " $p->{to_move} $p->{seats} $p->{pieces}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 25091 | my @game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 25091 | ▶ | push @game, 'f=' . join(',', @{ $p->{finished} }) if @{ $p->{finished} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$p->{'finished'} || []
MC/DC0%0/1
$p->{'finished'} || []
$p->{'finished'}
Truth table50%1/2
A
A= $p->{'finished'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 25091 | ▶ | push @game, 'r=' . join(',', @{ $p->{resigned} }) if @{ $p->{resigned} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$p->{'resigned'} || []
MC/DC0%0/1
$p->{'resigned'} || []
$p->{'resigned'}
Truth table50%1/2
A
A= $p->{'resigned'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 25091 | ▶ | push @game, "p=$p->{ply}" if $p->{ply}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 25091 | ▶ | push @game, "k=$p->{pass_run}" if $p->{pass_run}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 25091 | ▶ | push @game, "c=$p->{cap}" if defined $p->{cap} && $p->{cap} != 1000 * $p->{seats}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $p->{"cap"} and $p->{"cap"} != 1000 * $p->{"seats"}
MC/DC50%1/2
defined $p->{"cap"} and $p->{"cap"} != 1000 * $p->{"seats"}
defined $p->{"cap"}
$p->{"cap"} != 1000 * $p->{"seats"}
Truth table66%2/3
A and B
A= defined $p->{"cap"}B= $p->{"cap"} != 1000 * $p->{"seats"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 25091 | ▶ | push @game, "o=$p->{how}" if $p->{how}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 25091 | ▶ | $str .= ';' . join(' ', @game) if @game; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 25091 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # ---- a game as text ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 754 | ▶ | sub format_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_game: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 754 | my ($g) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 754 | ▶ | my $seats = $g->{seats} // 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$g->{"seats"} // 2
MC/DC0%0/1
$g->{"seats"} // 2
$g->{"seats"}
Truth table50%1/2
A
A= $g->{"seats"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 754 | ▶ | my $pieces = $g->{pieces} // 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$g->{"pieces"} // 10
MC/DC0%0/1
$g->{"pieces"} // 10
$g->{"pieces"}
Truth table50%1/2
A
A= $g->{"pieces"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 754 | ▶ | my $cap = $g->{cap} // 1000 * $seats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$g->{"cap"} // 1000 * $seats
MC/DC100%1/1
$g->{"cap"} // 1000 * $seats
$g->{"cap"}
Truth table100%2/2
A
A= $g->{"cap"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 754 | ▶ | my $first = $g->{first} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$g->{"first"} // 0
MC/DC100%1/1
$g->{"first"} // 0
$g->{"first"}
Truth table100%2/2
A
A= $g->{"first"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | return join '', "sternhalma 1\n", "seats $seats\n", "pieces $pieces\n", "cap $cap\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ($first ? "first $first\n" : ()), (defined $g->{start} ? "start $g->{start}\n" : ()), "moves\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 754 | ▶ | map { "$_\n" } @{ $g->{moves} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$g->{'moves'} || []
MC/DC0%0/1
$g->{'moves'} || []
$g->{'moves'}
Truth table50%1/2
A
A= $g->{'moves'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 543 | ▶ | sub parse_game { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_game: called CC=24 SCAR=34.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 543 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 543 | ▶ | return (undef, 'no text') unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 543 | my @lines = split /\n/, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 543 | ▶ | return (undef, 'not a sternhalma game') unless @lines && $lines[0] eq 'sternhalma 1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@lines and $lines[0] eq "sternhalma 1"
MC/DC50%1/2
@lines and $lines[0] eq "sternhalma 1"
@lines
$lines[0] eq "sternhalma 1"
Truth table66%2/3
A and B
A= @linesB= $lines[0] eq "sternhalma 1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 541 | my %g = (moves => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 541 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 541 | for my $key (qw(seats pieces cap)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1623 | ▶ | my ($k, $v) = ($lines[$i] // '') =~ /\A(\w+) ([0-9]+)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$lines[$i] // ""
MC/DC0%0/1
$lines[$i] // ""
$lines[$i]
Truth table50%1/2
A
A= $lines[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1623 | ▶ | return (undef, "line " . ($i + 1) . " should be $key") unless defined $k && $k eq $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $k and $k eq $key
MC/DC0%0/2
defined $k and $k eq $key
defined $k
$k eq $key
Truth table33%1/3
A and B
A= defined $kB= $k eq $key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1623 | $g{$key} = $v + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1623 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 541 | $g{first} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 541 | ▶ | if (($lines[$i] // '') =~ /\Afirst ([1-5])\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$lines[$i] // ""
MC/DC0%0/1
$lines[$i] // ""
$lines[$i]
Truth table50%1/2
A
A= $lines[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | $g{first} = $1 + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 541 | ▶ | return (undef, "first is seat $g{first}, and there are $g{seats} seats") if $g{first} >= $g{seats}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 541 | ▶ | if (($lines[$i] // '') =~ /\Astart (.+)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$lines[$i] // ""
MC/DC0%0/1
$lines[$i] // ""
$lines[$i]
Truth table50%1/2
A
A= $lines[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my ($p, $code) = parse_position($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | return (undef, 'line ' . ($i + 1) . " is not a position (code $code)") unless $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | return (undef, 'the start position is not of the seats and pieces the header says') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | unless $p->{seats} == $g{seats} && $p->{pieces} == $g{pieces}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p->{"seats"} == $g{"seats"} and $p->{"pieces"} == $g{"pieces"}
MC/DC0%0/2
$p->{"seats"} == $g{"seats"} and $p->{"pieces"} == $g{"pieces"}
$p->{"seats"} == $g{"seats"}
$p->{"pieces"} == $g{"pieces"}
Truth table33%1/3
A and B
A= $p->{"seats"} == $g{"seats"}B= $p->{"pieces"} == $g{"pieces"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | $g{start} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | return (undef, 'no game is ' . "$g{seats} seats of $g{pieces} pieces") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 541 | ▶ | unless $LAYOUT{ $g{seats} } && ($g{pieces} == 10 || ($g{pieces} == 15 && $g{seats} <= 3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$LAYOUT{$g{"seats"}} and $g{"pieces"} == 10 || $g{"pieces"} == 15 && $g{"seats"} <= 3
$g{"pieces"} == 10 or $g{"pieces"} == 15 and $g{"seats"} <= 3
$g{"pieces"} == 15 and $g{"seats"} <= 3
MC/DC25%1/4
$LAYOUT{$g{"seats"}} and $g{"pieces"} == 10 || $g{"pieces"} == 15 && $g{"seats"} <= 3
$LAYOUT{$g{"seats"}}
$g{"pieces"} == 10
$g{"pieces"} == 15
$g{"seats"} <= 3
Truth table60%3/5
A and B or C and D
A= $LAYOUT{$g{"seats"}}B= $g{"pieces"} == 10C= $g{"pieces"} == 15D= $g{"seats"} <= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 540 | ▶ | return (undef, 'line ' . ($i + 1) . ' should be moves') unless ($lines[$i] // '') eq 'moves'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$lines[$i] // ""
MC/DC0%0/1
$lines[$i] // ""
$lines[$i]
Truth table50%1/2
A
A= $lines[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 540 | for my $n ($i + 1 .. $#lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 52882 | ▶ | return (undef, 'line ' . ($n + 1) . " is not a move: $lines[$n]") unless parse_move($lines[$n]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 52881 | push @{ $g{moves} }, $lines[$n]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 539 | return (\%g, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 55 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||