blib/lib/Games/LMSolve/Tilt/Base.pm

filter: Statementstmt 48.4% 16 / 33 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 42.8% 21 / 49 SCAR 27.0
CC
6
Cov
37%
move_ball_to_end
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 14.9
« blib/lib/Games/LMSolve/Tilt/Single.pm ↑ Summary Build »
1 package Games::LMSolve::Tilt::Base;
2 6 $Games::LMSolve::Tilt::Base::VERSION = '0.14.0';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use Games::LMSolve::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 @ISA = qw(Games::LMSolve::Base);
11  
12 # x - the x step
13 # y - the y step
14 # w - which wall
15 6 my %moves_specs = (
16 'u' => { 'x' => 0, 'y' => -1, 'w' => 'h' },
17 'd' => { 'x' => 0, 'y' => 1, 'w' => 'h' },
18 'l' => { 'x' => -1, 'y' => 0, 'w' => 'v' },
19 'r' => { 'x' => 1, 'y' => 0, 'w' => 'v' },
20 );
21  
22 # This function moves the ball to the end.
23 # It returns the new position as well as all the intermediate positions.
24 sub move_ball_to_end
25 {
26 0 ▶ my $self = shift;
Subroutine move_ball_to_end: not called CC=6 SCAR=37.4
Pod documented
27  
28 0 my $coords = shift;
29 0 my $move = shift;
30  
31 0 my ( $x, $y ) = @$coords;
32 0 my @intermediate_coords = ();
33  
34 0 ▶ if ( !exists( $moves_specs{$move} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $moves_specs{$move}) 0 0 0
35 {
36 0 die "Unknown move \"$move\"!";
37 }
38  
39 0 my $horiz_walls = $self->{'horiz_walls'};
40 0 my $vert_walls = $self->{'vert_walls'};
41  
42 my ( $x_dir, $y_dir, $which_wall ) =
43 0 @{ $moves_specs{$move} }{ 'x', 'y', 'w' };
44  
45 0 push @intermediate_coords, [ $x, $y ];
46 0 ▶ while (
Branch: 4 branches
BranchTrueFalseTotal
unless ($which_wall eq "v" ? $vert_walls->[$y][$x + ($x_dir < 0 ? 0 : 1)] : $$horiz_walls[$y + ($y_dir < 0 ? 0 : 1)][$x]) 0 0 0
$which_wall eq 'v' ? : 0 0 0
$x_dir < 0 ? : 0 0 0
$y_dir < 0 ? : 0 0 0
47 !(
48 ( $which_wall eq 'v' )
49 ? ( $vert_walls->[$y]->[ $x + ( ( $x_dir < 0 ) ? 0 : 1 ) ] )
50 : ( $horiz_walls->[ $y + ( ( $y_dir < 0 ) ? 0 : 1 ) ]->[$x] )
51 )
52 )
53 {
54 0 $x += $x_dir;
55 0 $y += $y_dir;
56 0 push @intermediate_coords, [ $x, $y ];
57 }
58  
59 0 return ( [ $x, $y ], \@intermediate_coords );
60 }
61  
62 6 1;
63  
64 __END__
« blib/lib/Games/LMSolve/Tilt/Single.pm ↑ Summary Build »