| 1 | package Games::LMSolve::Plank::Base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | $Games::LMSolve::Plank::Base::VERSION = '0.14.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Games::LMSolve::Base qw(%cell_dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | @ISA = qw(Games::LMSolve::Base); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Games::LMSolve::Input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub initialize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | $self->SUPER::initialize(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $self->{'dirs'} = [qw(E W S N)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | sub input_board | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_board: called CC=11 SCAR=29.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $spec = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'dims' => { 'type' => "xy(integer)", 'required' => 1, }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'planks' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'type' => "array(start_end(xy(integer)))", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'required' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'layout' => { 'type' => "layout", 'required' => 1, }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $input_obj = Games::LMSolve::Input->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $input_fields = $input_obj->input_board( $filename, $spec ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | my ( $width, $height ) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | @{ $input_fields->{'dims'}->{'value'} }{ 'x', 'y' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my ( $goal_x, $goal_y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( scalar( @{ $input_fields->{'layout'}->{'value'} } ) < $height ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | "Incorrect number of lines in board layout (does not match dimensions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | my @board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $lines = $input_fields->{'layout'}->{'value'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | for ( my $y = 0 ; $y < $height ; $y++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | my $l = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | if ( length( $lines->[$y] ) < $width ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | die "Too few characters in board layout in line No. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | . ( $input_fields->{'layout'}->{'line_num'} + $y + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | my $x = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | foreach my $c ( split( //, $lines->[$y] ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 35 | push @$l, ( $c ne " " ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 35 | ▶ | if ( $c eq "G" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | if ( defined($goal_x) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | die "Goal was defined twice!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ( $goal_x, $goal_y ) = ( $x, $y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 35 | $x++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | push @board, $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | if ( !defined($goal_x) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | die "The Goal was not defined in the layout"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | my $planks_in = $input_fields->{'planks'}->{'value'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | my @planks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | my $get_plank = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | my $p = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=19 SCAR=45.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | my ( $start_x, $start_y ) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | ( $p->{'start'}->{'x'}, $p->{'start'}->{'y'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my ( $end_x, $end_y ) = ( $p->{'end'}->{'x'}, $p->{'end'}->{'y'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | my $check_endpoints = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | if ( !$board[$start_y]->[$start_x] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | die "Plank cannot be placed at point ($start_x,$start_y)!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | if ( !$board[$end_y]->[$end_x] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | die "Plank cannot be placed at point ($end_x,$end_y)!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | my $plank_str = "Plank ($start_x,$start_y) ==> ($end_x,$end_y)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | ▶ | if ( ( $start_x >= $width ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$start_x >= $width or $end_x >= $width or $start_y >= $height or $end_y >= $height
$start_x >= $width or $end_x >= $width or $start_y >= $height
$start_x >= $width or $end_x >= $width
MC/DC0%0/4
$start_x >= $width or $end_x >= $width or $start_y >= $height or $end_y >= $height
$start_x >= $width
$end_x >= $width
$start_y >= $height
$end_y >= $height
Truth table20%1/5
A or B or C or D
A= $start_x >= $widthB= $end_x >= $widthC= $start_y >= $heightD= $end_y >= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | || ( $end_x >= $width ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | || ( $start_y >= $height ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | || ( $end_y >= $height ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | die "$plank_str is out of the boundaries of the board"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | if ( $start_x == $end_x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | if ( $start_y == $end_y ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | die "$plank_str has zero length!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | $check_endpoints->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | if ( $start_y > $end_y ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ( $start_y, $end_y ) = ( $end_y, $start_y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | foreach my $y ( ( $start_y + 1 ) .. ( $end_y - 1 ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ( $board[$y]->[$start_x] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | die "$plank_str crosses logs!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | 'len' => ( $end_y - $start_y ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 'start' => { 'x' => $start_x, 'y' => $start_y }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 'dir' => "S" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif ( $start_y == $end_y ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | $check_endpoints->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | if ( $start_x > $end_x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ( $start_x, $end_x ) = ( $end_x, $start_x ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | foreach my $x ( ( $start_x + 1 ) .. ( $end_x - 1 ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | if ( $board[$start_y]->[$x] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | die "$plank_str crosses logs!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | 'len' => ( $end_x - $start_x ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 'start' => { 'x' => $start_x, 'y' => $start_y }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 'dir' => "E" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | elsif ( ( $end_x - $start_x ) == ( $end_y - $start_y ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $check_endpoints->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $start_x > $end_x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ( $start_x, $end_x ) = ( $end_x, $start_x ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ( $start_y, $end_y ) = ( $end_y, $start_y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | foreach my $i ( 1 .. ( $end_x - $start_x - 1 ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ( $board[ $start_y + $i ]->[ $start_x + $i ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | die "$plank_str crosses logs!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( !grep { $_ eq "SE" } @{ $self->{'dirs'} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | die "$plank_str is not aligned horizontally or vertically."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | 'len' => ( $end_x - $start_x ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 'start' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 'x' => $start_x, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 'y' => $start_y, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 'dir' => "SE", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | die "$plank_str is not aligned horizontally or vertically."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | foreach my $p (@$planks_in) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | push @planks, $get_plank->($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $self->{'width'} = $width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $self->{'height'} = $height; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $self->{'goal_x'} = $goal_x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | $self->{'goal_y'} = $goal_y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | $self->{'board'} = \@board; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | $self->{'plank_lens'} = [ map { $_->{'len'} } @planks ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | my $state = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | $_->{'start'}->{'x'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $_->{'start'}->{'y'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ( $_->{'dir'} eq "E" ) ? 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | : ( $_->{'dir'} eq "SE" ) ? 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | : 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } @planks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | $self->_process_plank_data($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | #{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # my $d = Data::Dumper->new([$self, $state], ["\$self", "\$state"]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # print $d->Dump(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | return $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | sub _process_plank_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 642 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_plank_data: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 642 | my $state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 642 | my $active = $state->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | my @planks = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2568 | 'len' => $self->{'plank_lens'}->[$_], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 'x' => $state->[ $_ * 3 + 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 'y' => $state->[ $_ * 3 + 1 + 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 'dir' => $state->[ $_ * 3 + 2 + 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 'active' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 642 | } ( 0 .. ( scalar( @{ $self->{'plank_lens'} } ) - 1 ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 642 | foreach my $p (@planks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2568 | my $p_dir = $p->{'dir'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2568 | ▶ | my $dir = ( $p_dir == 0 ) ? "E" : ( $p_dir == 1 ) ? "S" : "SE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2568 | $p->{'dir'} = $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2568 | $p->{'end_x'} = $p->{'x'} + $cell_dirs{$dir}->[0] * $p->{'len'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2568 | $p->{'end_y'} = $p->{'y'} + $cell_dirs{$dir}->[1] * $p->{'len'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # $ap is short for active plank | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 642 | my $ap = $planks[$active]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 642 | $ap->{'active'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 642 | my (@queue); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 642 | push @queue, [ $ap->{'x'}, $ap->{'y'} ], [ $ap->{'end_x'}, $ap->{'end_y'} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 642 | undef($ap); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 642 | ▶ | while ( my $point = pop(@queue) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2113 | my ( $x, $y ) = @$point; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2113 | foreach my $p (@planks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 8452 | ▶ | if ( $p->{'active'} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3901 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4551 | ▶ | if ( ( $p->{'x'} == $x ) && ( $p->{'y'} == $y ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p->{"x"} == $x and $p->{"y"} == $y
MC/DC100%2/2
$p->{"x"} == $x and $p->{"y"} == $y
$p->{"x"} == $x
$p->{"y"} == $y
Truth table100%3/3
A and B
A= $p->{"x"} == $xB= $p->{"y"} == $y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 464 | $p->{'active'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 464 | push @queue, [ $p->{'end_x'}, $p->{'end_y'} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4551 | ▶ | if ( ( $p->{'end_x'} == $x ) && ( $p->{'end_y'} == $y ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p->{"end_x"} == $x and $p->{"end_y"} == $y
MC/DC100%2/2
$p->{"end_x"} == $x and $p->{"end_y"} == $y
$p->{"end_x"} == $x
$p->{"end_y"} == $y
Truth table100%3/3
A and B
A= $p->{"end_x"} == $xB= $p->{"end_y"} == $y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 365 | $p->{'active'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 365 | push @queue, [ $p->{'x'}, $p->{'y'} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 642 | foreach my $i ( 0 .. $#planks ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 964 | ▶ | if ( $planks[$i]->{'active'} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 642 | $state->[0] = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 642 | return \@planks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | sub pack_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 239 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack_state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 239 | my $state_vector = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 239 | return pack( "c*", @$state_vector ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | sub unpack_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 83 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack_state: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 83 | my $state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 83 | return [ unpack( "c*", $state ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | sub display_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_state: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $packed_state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $state = $self->unpack_state($packed_state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $plank_data = $self->_process_plank_data($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my @strings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | foreach my $p (@$plank_data) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | push @strings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | sprintf( "(%i,%i) -> (%i,%i) %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $p->{'x'}, $p->{'y'}, $p->{'end_x'}, $p->{'end_y'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | ( $p->{'active'} ? "[active]" : "" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return join( " ; ", @strings ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | sub check_if_final_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 83 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_if_final_state: called CC=4 SCAR=14.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 83 | my $state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 83 | my $plank_data = $self->_process_plank_data($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 83 | my $goal_x = $self->{'goal_x'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 83 | my $goal_y = $self->{'goal_y'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | scalar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 83 | ( ( $_->{'x'} == $goal_x ) && ( $_->{'y'} == $goal_y ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | || ( ( $_->{'end_x'} == $goal_x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 332 | ▶ | && ( $_->{'end_y'} == $goal_y ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$_->{'x'} == $goal_x && $_->{'y'} == $goal_y || $_->{'end_x'} == $goal_x && $_->{'end_y'} == $goal_y
$_->{"x"} == $goal_x and $_->{"y"} == $goal_y
$_->{"end_x"} == $goal_x and $_->{"end_y"} == $goal_y
MC/DC25%1/4
$_->{'x'} == $goal_x && $_->{'y'} == $goal_y || $_->{'end_x'} == $goal_x && $_->{'end_y'} == $goal_y
$_->{"x"} == $goal_x
$_->{"y"} == $goal_y
$_->{"end_x"} == $goal_x
$_->{"end_y"} == $goal_y
Truth table28%2/7
A and B || C and D
A= $_->{"x"} == $goal_xB= $_->{"y"} == $goal_yC= $_->{"end_x"} == $goal_xD= $_->{"end_y"} == $goal_y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } @$plank_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ) > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | sub enumerate_moves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 82 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enumerate_moves: called CC=21 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 82 | my $state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 82 | my $plank_data = $self->_process_plank_data($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Declare some accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 82 | my $board = $self->{'board'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 82 | my $width = $self->{'width'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 82 | my $height = $self->{'height'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 82 | my $dirs_ptr = $self->{'dirs'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 82 | my @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | my %current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | my $serialize = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 2851 | ▶ | return join "\t", @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 82 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 82 | foreach my $plank (@$plank_data) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $current{ $serialize->( @$plank{qw(x y end_x end_y)} ) } = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 328 | $current{ $serialize->( @$plank{qw(end_x end_y x y)} ) } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 82 | for my $to_move_idx ( 0 .. $#$plank_data ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 328 | my $to_move = $plank_data->[$to_move_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 328 | my $len = $to_move->{'len'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 328 | ▶ | if ( !( $to_move->{'active'} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 166 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 162 | foreach my $move_to (@$plank_data) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 648 | ▶ | if ( !( $move_to->{'active'} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 256 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 392 | for my $point ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | [ $move_to->{'x'}, $move_to->{'y'} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | [ $move_to->{'end_x'}, $move_to->{'end_y'} ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 784 | my ( $x, $y ) = @$point; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 784 | DIR_LOOP: for my $dir (@$dirs_ptr) # (qw(E W S N)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # Find the other ending points of the plank | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3136 | my $other_x = $x + $cell_dirs{$dir}->[0] * $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3136 | my $other_y = $y + $cell_dirs{$dir}->[1] * $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # Check if we are within bounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3136 | ▶ | if ( ( $other_x < 0 ) || ( $other_x >= $width ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$other_x < 0 or $other_x >= $width
MC/DC100%2/2
$other_x < 0 or $other_x >= $width
$other_x < 0
$other_x >= $width
Truth table100%3/3
A or B
A= $other_x < 0B= $other_x >= $width
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 348 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 2788 | ▶ | if ( ( $other_y < 0 ) || ( $other_y >= $height ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$other_y < 0 or $other_y >= $height
MC/DC100%2/2
$other_y < 0 or $other_y >= $height
$other_y < 0
$other_y >= $height
Truth table100%3/3
A or B
A= $other_y < 0B= $other_y >= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 593 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # Check that we're not moving one plank on top of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # other or itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2195 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | $current{ $serialize->( $x, $y, $other_x, $other_y ) } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 558 | next DIR_LOOP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # Check if there is a stump at the other end-point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1637 | ▶ | if ( !$board->[$other_y]->[$other_x] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1378 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Check the validity of the intermediate points. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 259 | ▶ | for ( my $offset = 1 ; $offset < $len ; $offset++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 276 | my $ix = $x + $cell_dirs{$dir}->[0] * $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 276 | my $iy = $y + $cell_dirs{$dir}->[1] * $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 276 | ▶ | if ( $board->[$iy]->[$ix] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 15 | next DIR_LOOP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Check if another plank has this point in between | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 261 | my $collision_plank_idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 261 | for my $plank (@$plank_data) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # Make sure we don't test a plank against | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # a collisions with itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1032 | ▶ | if ( $collision_plank_idx == $to_move_idx ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 261 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 771 | my $p_x = $plank->{'x'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 771 | my $p_y = $plank->{'y'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 771 | my $plank_dir = $plank->{'dir'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 771 | for my $i ( 0 .. $plank->{'len'} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 1892 | ▶ | if ( ( $p_x == $ix ) && ( $p_y == $iy ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p_x == $ix and $p_y == $iy
MC/DC100%2/2
$p_x == $ix and $p_y == $iy
$p_x == $ix
$p_y == $iy
Truth table100%3/3
A and B
A= $p_x == $ixB= $p_y == $iy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 6 | next DIR_LOOP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1886 | $p_x += $cell_dirs{$plank_dir}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1886 | $p_y += $cell_dirs{$plank_dir}->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1026 | $collision_plank_idx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # A perfectly valid move - let's add it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 238 | push @moves, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 'p' => $to_move_idx, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 'x' => $x, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 'y' => $y, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 'dir' => $dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 82 | return @moves; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | sub perform_move | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 238 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perform_move: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 238 | my $state = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 238 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 238 | my $plank_data = $self->_process_plank_data($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 238 | my ( $x, $y, $p, $dir ) = @{$m}{qw(x y p dir)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 238 | my $dir_idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 238 | ▶ | if ( $dir eq "S" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 34 | $dir_idx = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | elsif ( $dir eq "E" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 21 | $dir_idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | elsif ( $dir eq "N" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 76 | $dir_idx = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 76 | $y -= $self->{'plank_lens'}->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | elsif ( $dir eq "W" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 107 | $dir_idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 107 | $x -= $self->{'plank_lens'}->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | elsif ( $dir eq "NW" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $dir_idx = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $y -= $self->{'plank_lens'}->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $x -= $self->{'plank_lens'}->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | elsif ( $dir eq "SE" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $dir_idx = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 238 | my $new_state = [@$state]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 238 | @$new_state[0] = $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 238 | @$new_state[ ( 1 + $p * 3 ) .. ( 1 + $p * 3 + 2 ) ] = ( $x, $y, $dir_idx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 238 | $self->_process_plank_data($new_state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 238 | return $new_state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | sub render_move | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_move: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 19 | my $move = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 19 | ▶ | if ($move) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | return sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | "Move the Plank of Length %i to (%i,%i) %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | $self->{'plank_lens'}->[ $move->{'p'} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 19 | @{$move}{qw(x y dir)} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | return ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||