line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::LMSolve::Tilt::Base; |
2
|
|
|
|
|
|
|
$Games::LMSolve::Tilt::Base::VERSION = '0.14.0'; |
3
|
1
|
|
|
1
|
|
1022
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Games::LMSolve::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
300
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Games::LMSolve::Base); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# x - the x step |
13
|
|
|
|
|
|
|
# y - the y step |
14
|
|
|
|
|
|
|
# w - which wall |
15
|
|
|
|
|
|
|
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
|
|
|
0
|
1
|
|
my $self = shift; |
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
|
0
|
|
|
|
|
if ( !exists( $moves_specs{$move} ) ) |
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' }; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
push @intermediate_coords, [ $x, $y ]; |
46
|
0
|
0
|
|
|
|
|
while ( |
|
|
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
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |