line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::Pathfinding::AStar::Rectangle; |
2
|
8
|
|
|
8
|
|
366896
|
use strict; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
281
|
|
3
|
8
|
|
|
8
|
|
41
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
1532
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
10
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
11
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# This allows declaration use AI::Pathfinding::AStar::Rectangle ':all'; |
14
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
15
|
|
|
|
|
|
|
# will save memory. |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(create_map |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
) ] ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT = qw( |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
require XSLoader; |
28
|
|
|
|
|
|
|
XSLoader::load('AI::Pathfinding::AStar::Rectangle', $VERSION); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Preloaded methods go here. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub foreach_xy{ |
33
|
11
|
|
|
11
|
1
|
5771
|
my $self = shift; |
34
|
11
|
|
|
|
|
18
|
my $sub = shift; |
35
|
8
|
|
|
8
|
|
46
|
no strict 'refs'; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
1432
|
|
36
|
11
|
|
|
|
|
16
|
local *a= *{ caller() . '::a' }; |
|
11
|
|
|
|
|
53
|
|
37
|
11
|
|
|
|
|
14
|
local *b= *{ caller() . '::b' }; |
|
11
|
|
|
|
|
34
|
|
38
|
11
|
|
|
|
|
16
|
local ($a, $b ); |
39
|
11
|
|
|
|
|
13
|
local $_; |
40
|
11
|
|
|
|
|
62
|
for $a ( $self->start_x .. $self->last_x ){ |
41
|
101
|
|
|
|
|
586
|
for $b ( $self->start_y .. $self->last_y ){ |
42
|
1341
|
|
|
|
|
4470
|
$_ = $self->get_passability( $a, $b ); |
43
|
1341
|
|
|
|
|
2184
|
&$sub(); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
sub foreach_xy_set{ |
48
|
6
|
|
|
6
|
1
|
4129
|
my $self = shift; |
49
|
6
|
|
|
|
|
10
|
my $sub = shift; |
50
|
|
|
|
|
|
|
|
51
|
8
|
|
|
8
|
|
45
|
no strict 'refs'; |
|
8
|
|
|
|
|
65
|
|
|
8
|
|
|
|
|
7791
|
|
52
|
6
|
|
|
|
|
10
|
local *a= *{ caller() . '::a' }; |
|
6
|
|
|
|
|
27
|
|
53
|
6
|
|
|
|
|
9
|
local *b= *{ caller() . '::b' }; |
|
6
|
|
|
|
|
17
|
|
54
|
6
|
|
|
|
|
12
|
local ($a, $b ); |
55
|
6
|
|
|
|
|
8
|
local $_; |
56
|
6
|
|
|
|
|
41
|
for $a ( $self->start_x .. $self->last_x ){ |
57
|
65
|
|
|
|
|
376
|
for $b ( $self->start_y .. $self->last_y ){ |
58
|
925
|
|
|
|
|
3050
|
$_ = $self->get_passability( $a, $b ); |
59
|
925
|
|
|
|
|
10270
|
$self->set_passability( $a, $b, (scalar &$sub()) ); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
sub create_map($){ |
65
|
1
|
|
|
1
|
0
|
740
|
unshift @_, __PACKAGE__; |
66
|
1
|
|
|
|
|
10
|
goto &new; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1 for ($a, $b); #suppress warnings |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub set_passability_string{ |
72
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
my $passability = shift; |
74
|
0
|
0
|
|
|
|
|
die "Bad passabilitity param for set_passability_string" unless $self->width * $self->height == length( $passability ); |
75
|
0
|
|
|
0
|
|
|
$self->foreach_xy_set( sub { substr $passability, 0, 1, '' } ); |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub get_passability_string{ |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my $buf = ''; |
81
|
0
|
|
|
0
|
|
|
$self->foreach_xy( sub { $buf.= chr( $_)} ); |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $buf; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub draw_path{ |
87
|
0
|
|
|
0
|
1
|
|
my $map = shift; |
88
|
0
|
|
|
|
|
|
my ($x, $y) = splice @_, 0, 2; |
89
|
0
|
|
|
|
|
|
my $path = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @map; |
92
|
0
|
|
|
0
|
|
|
$map->foreach_xy( sub {$map[$a][$b]= $_} ); |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# draw path |
95
|
0
|
|
|
|
|
|
my %vect = ( |
96
|
|
|
|
|
|
|
# x y |
97
|
|
|
|
|
|
|
1 => [-1, 1, ], |
98
|
|
|
|
|
|
|
2 => [ 0, 1, '.|'], |
99
|
|
|
|
|
|
|
3 => [ 1, 1, '|\\'], |
100
|
|
|
|
|
|
|
4 => [-1, 0, '|<'], |
101
|
|
|
|
|
|
|
6 => [ 1, 0, '|>'], |
102
|
|
|
|
|
|
|
7 => [-1,-1, '|\\'], |
103
|
|
|
|
|
|
|
8 => [ 0,-1, '\'|'], |
104
|
|
|
|
|
|
|
9 => [ 1,-1, '|/'] |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @path = split //, $path; |
108
|
0
|
|
|
|
|
|
print "Steps: ".scalar(@path)."\n"; |
109
|
0
|
|
|
|
|
|
for ( @path ) |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
|
|
|
$map[$x][$y] = '|o'; |
112
|
0
|
|
|
|
|
|
$x += $vect{$_}->[0]; |
113
|
0
|
|
|
|
|
|
$y -= $vect{$_}->[1]; |
114
|
0
|
|
|
|
|
|
$map[$x][$y] = '|o'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
printf "%02d", $_ for 0 .. $map->last_x; |
118
|
0
|
|
|
|
|
|
print "\n"; |
119
|
0
|
|
|
|
|
|
for my $y ( 0 .. $map->last_y - 1 ) |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
|
|
|
for my $x ( 0 .. $map->last_x - 1 ) |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
0
|
|
|
|
|
print $map[$x][$y] eq |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
124
|
|
|
|
|
|
|
'1' ? "|_" : ( |
125
|
|
|
|
|
|
|
$map[$x][$y] eq '0' ? "|#" : ( |
126
|
|
|
|
|
|
|
$map[$x][$y] eq '3' ? "|S" : ( |
127
|
|
|
|
|
|
|
$map[$x][$y] eq '4' ? "|E" : $map[$x][$y] ) ) ); |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
print "$y\n"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |