line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# some utility subs for text patterns |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Game::TextPatterns::Util; |
6
|
|
|
|
|
|
|
our $VERSION = '1.47'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
132925
|
use strict; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
72
|
|
9
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
85
|
|
10
|
3
|
|
|
3
|
|
13
|
use constant { COL => 0, ROW => 1, }; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1224
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(adj_4way adj_8way); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# NOTE the adj_* functions for speeds do not check if all points lie |
17
|
|
|
|
|
|
|
# outside the given 0,0,mc,mr bounding box. this may change if this |
18
|
|
|
|
|
|
|
# proves problematic in practice |
19
|
|
|
|
|
|
|
sub adj_4way { |
20
|
16
|
|
|
16
|
1
|
132
|
my ($p, $max_col, $max_row) = @_; |
21
|
16
|
|
|
|
|
24
|
my @adj; |
22
|
16
|
100
|
|
|
|
54
|
push @adj, [ $p->[COL] - 1, $p->[ROW] ] unless $p->[COL] <= 0; |
23
|
16
|
100
|
|
|
|
39
|
push @adj, [ $p->[COL] + 1, $p->[ROW] ] unless $p->[COL] >= $max_col; |
24
|
16
|
100
|
|
|
|
36
|
push @adj, [ $p->[COL], $p->[ROW] - 1 ] unless $p->[ROW] <= 0; |
25
|
16
|
100
|
|
|
|
35
|
push @adj, [ $p->[COL], $p->[ROW] + 1 ] unless $p->[ROW] >= $max_row; |
26
|
16
|
|
|
|
|
85
|
return @adj; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub adj_8way { |
30
|
14
|
|
|
14
|
1
|
27
|
my ($p, $max_col, $max_row) = @_; |
31
|
14
|
|
|
|
|
17
|
my @adj; |
32
|
14
|
100
|
|
|
|
41
|
push @adj, [ $p->[COL] - 1, $p->[ROW] ] unless $p->[COL] == 0; |
33
|
14
|
100
|
|
|
|
33
|
push @adj, [ $p->[COL] + 1, $p->[ROW] ] unless $p->[COL] == $max_col; |
34
|
14
|
100
|
|
|
|
32
|
push @adj, [ $p->[COL], $p->[ROW] - 1 ] unless $p->[ROW] == 0; |
35
|
14
|
100
|
|
|
|
50
|
push @adj, [ $p->[COL], $p->[ROW] + 1 ] unless $p->[ROW] == $max_row; |
36
|
14
|
100
|
100
|
|
|
51
|
push @adj, [ $p->[COL] - 1, $p->[ROW] - 1 ] |
37
|
|
|
|
|
|
|
unless $p->[COL] == 0 |
38
|
|
|
|
|
|
|
or $p->[ROW] == 0; |
39
|
14
|
100
|
100
|
|
|
52
|
push @adj, [ $p->[COL] - 1, $p->[ROW] + 1 ] |
40
|
|
|
|
|
|
|
unless $p->[COL] == 0 |
41
|
|
|
|
|
|
|
or $p->[ROW] == $max_row; |
42
|
14
|
100
|
100
|
|
|
45
|
push @adj, [ $p->[COL] + 1, $p->[ROW] - 1 ] |
43
|
|
|
|
|
|
|
unless $p->[COL] == $max_col |
44
|
|
|
|
|
|
|
or $p->[ROW] == 0; |
45
|
14
|
100
|
100
|
|
|
40
|
push @adj, [ $p->[COL] + 1, $p->[ROW] + 1 ] |
46
|
|
|
|
|
|
|
unless $p->[COL] == $max_col |
47
|
|
|
|
|
|
|
or $p->[ROW] == $max_row; |
48
|
14
|
|
|
|
|
67
|
return @adj; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
__END__ |