| 1 | package Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | my %WAY = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | up => [ 0, -1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | down => [ 0, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | left => [ -1, 0 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | right => [ 1, 0 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | sub way { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
way: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | return () unless defined $key && $WAY{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $key and $WAY{$key}
MC/DC100%2/2
defined $key and $WAY{$key}
defined $key
$WAY{$key}
Truth table100%3/3
A and B
A= defined $keyB= $WAY{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | return @{ $WAY{$key} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 113 | ▶ | sub ring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ring: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 113 | my ($count, $at, $delta, $skip) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 113 | ▶ | return $at unless $count && $delta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count and $delta
MC/DC100%2/2
$count and $delta
$count
$delta
Truth table100%3/3
A and B
A= $countB= $delta
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 111 | ▶ | my $step = $delta > 0 ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 111 | my $next = ($at + $delta) % $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 111 | for (1 .. $count) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 130 | ▶ | return $next unless $skip && $skip->($next); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip and &$skip($next)
MC/DC100%2/2
$skip and &$skip($next)
$skip
&$skip($next)
Truth table100%3/3
A and B
A= $skipB= &$skip($next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 21 | $next = ($next + $step) % $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | return $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | ▶ | sub clamp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clamp: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 11 | my ($count, $at, $delta, $skip) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | return $at unless $count && $delta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count and $delta
MC/DC50%1/2
$count and $delta
$count
$delta
Truth table66%2/3
A and B
A= $countB= $delta
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ▶ | my $step = $delta > 0 ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | my $next = $at + $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | $next = 0 if $next < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | ▶ | $next = $count - 1 if $next > $count - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | while ($next >= 0 && $next < $count) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next >= 0 and $next < $count
MC/DC100%2/2
$next >= 0 and $next < $count
$next >= 0
$next < $count
Truth table100%3/3
A and B
A= $next >= 0B= $next < $count
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | return $next unless $skip && $skip->($next); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip and &$skip($next)
MC/DC100%2/2
$skip and &$skip($next)
$skip
&$skip($next)
Truth table100%3/3
A and B
A= $skipB= &$skip($next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | $next += $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | return $at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 27 | ▶ | sub nearest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nearest: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 27 | my ($points, $at, $dx, $dy, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 27 | ▶ | return undef unless $dx || $dy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dx or $dy
MC/DC100%2/2
$dx or $dy
$dx
$dy
Truth table100%3/3
A or B
A= $dxB= $dy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 26 | ▶ | my $from = $points->[$at] or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | my $skip = $option{skip}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | my ($best, $best_cost, $best_across); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 25 | for my $index (0 .. $#{$points}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 160 | ▶ | next if $index == $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 135 | ▶ | next if $skip && $skip->($index); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip and &$skip($index)
MC/DC100%2/2
$skip and &$skip($index)
$skip
&$skip($index)
Truth table100%3/3
A and B
A= $skipB= &$skip($index)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 134 | my $x = $points->[$index][0] - $from->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 134 | my $y = $points->[$index][1] - $from->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 134 | my $along = $x * $dx + $y * $dy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 134 | my $across = abs($x * $dy - $y * $dx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 134 | ▶ | next if $along <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 51 | ▶ | next if $option{cone} && $across > $along; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$option{"cone"} and $across > $along
MC/DC100%2/2
$option{"cone"} and $across > $along
$option{"cone"}
$across > $along
Truth table100%3/3
A and B
A= $option{"cone"}B= $across > $along
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 50 | my $cost = $along + 2 * $across; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 50 | ▶ | next if defined $best | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $best and $cost > $best_cost || $cost == $best_cost && $across >= $best_across
$cost > $best_cost or $cost == $best_cost and $across >= $best_across
$cost == $best_cost and $across >= $best_across
MC/DC100%4/4
defined $best and $cost > $best_cost || $cost == $best_cost && $across >= $best_across
defined $best
$cost > $best_cost
$cost == $best_cost
$across >= $best_across
Truth table100%5/5
A and B or C and D
A= defined $bestB= $cost > $best_costC= $cost == $best_costD= $across >= $best_across
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | && ($cost > $best_cost || ($cost == $best_cost && $across >= $best_across)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 32 | ($best, $best_cost, $best_across) = ($index, $cost, $across); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 25 | return $best; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | sub axis { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
axis: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | my ($points, $at, $dx, $dy) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | ▶ | return $at unless $dx || $dy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dx or $dy
MC/DC100%2/2
$dx or $dy
$dx
$dy
Truth table100%3/3
A or B
A= $dxB= $dy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | ▶ | my ($first, $second) = $dx ? (0, 1) : (1, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | my @order = sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 48 | ▶ | $points->[$a][$first] <=> $points->[$b][$first] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$points->[$a][$first] <=> $points->[$b][$first] || $points->[$a][$second] <=> $points->[$b][$second] || $a <=> $b
$points->[$a][$first] <=> $points->[$b][$first] or $points->[$a][$second] <=> $points->[$b][$second]
MC/DC0%0/3
$points->[$a][$first] <=> $points->[$b][$first] || $points->[$a][$second] <=> $points->[$b][$second] || $a <=> $b
$points->[$a][$first] <=> $points->[$b][$first]
$points->[$a][$second] <=> $points->[$b][$second]
$a <=> $b
Truth table50%2/4
A or B || C
A= $points->[$a][$first] <=> $points->[$b][$first]B= $points->[$a][$second] <=> $points->[$b][$second]C= $a <=> $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | || $points->[$a][$second] <=> $points->[$b][$second] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | || $a <=> $b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | } 0 .. $#{$points}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | my ($where) = grep { $order[$_] == $at } 0 .. $#order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | ▶ | return $at unless defined $where; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | ▶ | $where += ($dx || $dy) > 0 ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dx || $dy
MC/DC0%0/2
$dx || $dy
$dx
$dy
Truth table66%2/3
A || B
A= $dxB= $dy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | return $where >= 0 && $where <= $#order ? $order[$where] : $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$where >= 0 and $where <= $#order
MC/DC100%2/2
$where >= 0 and $where <= $#order
$where >= 0
$where <= $#order
Truth table100%3/3
A and B
A= $where >= 0B= $where <= $#order
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 74 | ▶ | sub rest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 74 | my ($items, $prefer) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 74 | ▶ | my @open = grep { !(ref $items->[$_] eq 'HASH' && $items->[$_]{skip}) } 0 .. $#{$items}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $items->[$_] eq 'HASH' && $items->[$_]{'skip'}
MC/DC100%2/2
ref $items->[$_] eq 'HASH' && $items->[$_]{'skip'}
ref $items->[$_] eq 'HASH'
$items->[$_]{'skip'}
Truth table100%3/3
A && B
A= ref $items->[$_] eq 'HASH'B= $items->[$_]{'skip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 74 | ▶ | return 0 unless @open; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 68 | ▶ | if ($prefer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | for my $index (@open) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 14 | ▶ | return $index if $prefer->($items->[$index], $index); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 65 | return $open[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||