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

filter: Statementstmt 21.4% 18 / 84 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 41.6% 5 / 12 Podpod 100% 7 / 7 totaltotal 24.7% 30 / 121 SCAR 39.7
CC
9
Cov
18%
input_board
56.0
perform_move
12.0
pack_state
2.0
CRAP 53.1
« blib/lib/Games/LMSolve/Tilt/RedBlue.pm ↑ Summary blib/lib/Games/LMSolve.pm »
1 package Games::LMSolve::Tilt::Multi;
2 3 $Games::LMSolve::Tilt::Multi::VERSION = '0.14.0';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Games::LMSolve::Tilt::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Games::LMSolve::Input;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 @ISA = qw(Games::LMSolve::Tilt::Base);
13  
14 sub input_board
15 {
16 0 ▶ my $self = shift;
Subroutine input_board: not called CC=7 SCAR=40.3
Pod documented
17 0 my $filename = shift;
18  
19 0 my $spec = {
20 'dims' => { 'type' => "xy(integer)", 'required' => 1 },
21 'start' => { 'type' => "xy(integer)", 'required' => 1 },
22 'goals' => { 'type' => "array(xy(integer))", 'required' => 1 },
23 'layout' => { 'type' => "layout", 'required' => 1 },
24 };
25  
26 0 my $input_obj = Games::LMSolve::Input->new();
27  
28 0 my $input_fields = $input_obj->input_board( $filename, $spec );
29  
30 my ( $width, $height ) =
31 0 @{ $input_fields->{'dims'}->{'value'} }{ 'x', 'y' };
32 my ( $start_x, $start_y ) =
33 0 @{ $input_fields->{'start'}->{'value'} }{ 'x', 'y' };
34  
35 0 ▶ if ( ( $start_x >= $width ) || ( $start_y >= $height ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($start_x >= $width or $start_y >= $height) 0 0 0
Condition0%0/3
$start_x >= $width or $start_y >= $height
l!l&&r!l&&!r
000
MC/DC0%0/2
$start_x >= $width or $start_y >= $height
$start_x >= $width $start_y >= $height
Truth table0%0/3
A or B
A= $start_x >= $widthB= $start_y >= $height
ABresult
1X1
011
000
36 {
37 0 die
38 "The Starting position is out of bounds of the board in file \"$filename\"!\n";
39 }
40  
41 0 my @goals_map = map { [ (0) x $width ] } ( 1 .. $height );
42 0 my $goals = $input_fields->{'goals'}->{'value'};
43 0 my $goal_id = 1;
44 0 foreach my $g (@$goals)
45 {
46 0 my $x = $g->{'x'};
47 0 my $y = $g->{'y'};
48 0 ▶ if ( ( $x >= $width ) || ( $y >= $height ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($x >= $width or $y >= $height) 0 0 0
Condition0%0/3
$x >= $width or $y >= $height
l!l&&r!l&&!r
000
MC/DC0%0/2
$x >= $width or $y >= $height
$x >= $width $y >= $height
Truth table0%0/3
A or B
A= $x >= $widthB= $y >= $height
ABresult
1X1
011
000
49 {
50 0 die
51 "The goal ($x,$y) is out of bounds of the board in file \"$filename\"!\n";
52 }
53 0 $goals_map[$y]->[$x] = $goal_id;
54 0 $goal_id++;
55 }
56  
57 my ( $horiz_walls, $vert_walls ) =
58 $input_obj->input_horiz_vert_walls_layout( $width, $height,
59 0 $input_fields->{'layout'} );
60  
61 0 $self->{'width'} = $width;
62 0 $self->{'height'} = $height;
63 0 $self->{'horiz_walls'} = $horiz_walls;
64 0 $self->{'vert_walls'} = $vert_walls;
65 0 $self->{'goals_map'} = \@goals_map;
66 0 $self->{'num_goals'} = ( $goal_id - 1 );
67  
68 0 my $reached_goals_bitmap = 0;
69  
70 0 my $dest_goals_bitmap = 0;
71 0 ▶ for ( my $i = 1 ; $i < $goal_id ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $goal_id) 0 0 0
72 {
73 0 $dest_goals_bitmap |= ( 1 << $i );
74 }
75  
76 0 $self->{'dest_goals_bitmap'} = $dest_goals_bitmap;
77  
78 0 return [ $start_x, $start_y, $reached_goals_bitmap ];
79 }
80  
81 sub pack_state
82 {
83 0 ▶ my $self = shift;
Subroutine pack_state: not called CC=1 SCAR=6.9
Pod documented
84 0 my $state_vector = shift;
85  
86 0 return pack( "ccL", @$state_vector );
87 }
88  
89 sub unpack_state
90 {
91 0 ▶ my $self = shift;
Subroutine unpack_state: not called CC=1 SCAR=6.9
Pod documented
92 0 my $state = shift;
93 0 return [ unpack( "ccL", $state ) ];
94 }
95  
96 sub display_state
97 {
98 0 ▶ my $self = shift;
Subroutine display_state: not called CC=1 SCAR=6.9
Pod documented
99 0 my $state = shift;
100 my ( $x, $y, $reached_goals ) =
101 0 ( map { $_ + 1 } @{ $self->unpack_state($state) } );
102 return "($x,$y) Goals Collected=["
103 . join(
104 ",",
105 (
106 0 grep { $reached_goals &= ( 1 << $_ ) }
107 0 ( 1 .. ( $self->{'num_goals'} ) )
108 )
109 ) . "]";
110 }
111  
112 sub check_if_final_state
113 {
114 0 ▶ my $self = shift;
Subroutine check_if_final_state: not called CC=1 SCAR=6.9
Pod documented
115  
116 0 my $coords = shift;
117  
118 0 return ( $coords->[2] == $self->{'dest_goals_bitmap'} );
119 }
120  
121 sub enumerate_moves
122 {
123 0 ▶ my $self = shift;
Subroutine enumerate_moves: not called CC=1 SCAR=6.9
Pod documented
124 0 my $coords = shift;
125  
126 0 return (qw(u d l r));
127 }
128  
129 sub perform_move
130 {
131 0 ▶ my $self = shift;
Subroutine perform_move: not called CC=3 SCAR=24.8
Pod documented
132  
133 0 my $coords = shift;
134 0 my $move = shift;
135  
136 0 my ( $new_coords, $intermediate_states ) =
137 $self->move_ball_to_end( $coords, $move );
138  
139 0 my $goal_bitmap = $coords->[2];
140  
141 0 my $goals_map = $self->{'goals_map'};
142 0 foreach my $state (@$intermediate_states)
143 {
144 0 my ( $x, $y ) = @$state;
145 0 my $goal = $goals_map->[$y]->[$x];
146  
147 #printf("Goal=%i\n", $goal);
148 0 ▶ if ( $goal > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($goal > 0) 0 0 0
149 {
150 0 $goal_bitmap |= ( 1 << $goal );
151 }
152 }
153  
154 0 return [ @$new_coords, $goal_bitmap ];
155 }
156  
157 3 1;
158  
159 __END__
« blib/lib/Games/LMSolve/Tilt/RedBlue.pm ↑ Summary blib/lib/Games/LMSolve.pm »