line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Crosswords; |
2
|
1
|
|
|
1
|
|
8044
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
1347
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub isvalidtable($){ |
8
|
0
|
0
|
|
0
|
0
|
|
caller eq __PACKAGE__ or die; |
9
|
0
|
|
|
|
|
|
my $len = 0; |
10
|
0
|
|
|
|
|
|
for my $l (grep {$_} split //, $_[0]){ |
|
0
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
$len = length $l unless $len; |
12
|
0
|
0
|
|
|
|
|
return 0 unless $len == length $l; |
13
|
|
|
|
|
|
|
} |
14
|
0
|
|
|
|
|
|
$len; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
0
|
|
0
|
1
|
|
isvalidtable $_[1]->{TABLE} or die "Table is not valid"; |
19
|
0
|
|
|
|
|
|
bless{ _TABLE => $_[1]->{TABLE}, _LEXICON => $_[1]->{LEXICON} }, $_[0]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub table { |
23
|
0
|
0
|
|
0
|
1
|
|
isvalidtable $_[1] or die "Table is not valid"; |
24
|
0
|
|
|
|
|
|
$_[0]->{_TABLE} = $_[1]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
|
sub lexicon { $_[0]->{_LEXICON} = $_[1] } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub getdim($) { |
30
|
0
|
|
|
0
|
0
|
|
my @table = split /\n/, shift; |
31
|
0
|
|
|
|
|
|
my ($x) = length ($table[0]); |
32
|
0
|
|
|
|
|
|
my ($y) = scalar @table; |
33
|
0
|
|
|
|
|
|
return ($x, $y); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub mklexarr { |
37
|
0
|
0
|
|
0
|
0
|
|
caller eq __PACKAGE__ or die; |
38
|
0
|
|
|
|
|
|
@{$_[0]->{_LEXICON_ARR}} = (); |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
for my $o (qw/ACROSS DOWN/){ |
40
|
0
|
|
|
|
|
|
for my $e (@{$_[0]->{_LEXICON}->{$o}}){ |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
push @{$_[0]->{_LEXICON_ARR}}, [ $e->[0], $e->[1], $o, $e->[2], $e->[3] ]; |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub genpuzzle { _generate($_[0], 'puzzle', $_[1]) } |
48
|
0
|
|
|
0
|
1
|
|
sub gensolution { _generate($_[0], 'solution', $_[1]) } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _generate { |
51
|
0
|
0
|
|
0
|
|
|
caller eq __PACKAGE__ or die; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $HEAD=<
|
54
|
|
|
|
|
|
|
\\documentclass[letterpaper]{article} |
55
|
|
|
|
|
|
|
\\usepackage{texdraw} |
56
|
|
|
|
|
|
|
\\begin{document} |
57
|
|
|
|
|
|
|
\\begin{texdraw} |
58
|
|
|
|
|
|
|
HEAD |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $FOOT=<
|
61
|
|
|
|
|
|
|
\\end{texdraw} |
62
|
|
|
|
|
|
|
\\end{document} |
63
|
|
|
|
|
|
|
FOOT |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my %dim; |
66
|
0
|
|
|
|
|
|
@dim{qw/x y/} = getdim( $_[0]->{_TABLE}); |
67
|
0
|
|
|
|
|
|
my $arr; |
68
|
0
|
|
|
|
|
|
my ($dx, $dy) = (0.9, 0.9); |
69
|
0
|
|
|
|
|
|
my $tex="\\drawdim{cm} \\linewd 0.03 "; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $i=0; |
72
|
0
|
|
|
|
|
|
for my $L (split /\n/, $_[0]->{_TABLE}){ @{$arr->[$i++]} = split //, $L } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# draws the cells |
75
|
0
|
|
|
|
|
|
for(my $i=0; $i<$dim{y}; $i++){ |
76
|
0
|
|
|
|
|
|
for(my $j=0; $j<$dim{x}; $j++){ |
77
|
0
|
|
|
|
|
|
$tex.="\\move(@{[$j*$dx]} -@{[$i*$dy]}) "; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$tex.="\\rlvec(0 -$dy) \\rlvec($dx 0) \\rlvec(0 $dy) \\rlvec(-$dx 0) "; |
79
|
0
|
0
|
|
|
|
|
if( $arr->[$i]->[$j] eq '@' ){ |
80
|
0
|
|
|
|
|
|
$tex.="\\lfill f:0.1 "; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
mklexarr($_[0]); |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if($_[1] eq 'puzzle'){ |
|
|
0
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$tex.="\\move(0 -@{[(1+$dim{y})*$dy ]}) \\htext{ACROSS} "; |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$tex.="\\move(7 -@{[(1+$dim{y})*$dy ]}) \\htext{DOWN} "; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $j=0; |
92
|
0
|
|
|
|
|
|
my $i=1; |
93
|
0
|
|
|
|
|
|
my %i; |
94
|
0
|
|
|
|
|
|
@i{qw/down across/} = qw/1 1/; |
95
|
0
|
|
|
|
|
|
my $sno=1; |
96
|
0
|
|
|
|
|
|
my %sno; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
for my $entry ( |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
sort { $a->[0] <=> $b->[0] } |
100
|
0
|
|
|
|
|
|
sort { $a->[1] <=> $b->[1] } |
101
|
|
|
|
|
|
|
@{$_[0]->{_LEXICON_ARR}} |
102
|
|
|
|
|
|
|
){ |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
$sno = defined $sno{$entry->[0].q/./.$entry->[1]} ? |
105
|
|
|
|
|
|
|
$sno{$entry->[0].q/./.$entry->[1]} : $i; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if($entry->[2] eq 'ACROSS'){ |
|
|
0
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$tex.="\\move(0 -@{[(1+($i{across})*0.5+$dim{y})*$dy]}) "; |
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$tex.="\\small \\htext{$sno $entry->[3]} "; |
110
|
0
|
|
|
|
|
|
$i{across}++; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif($entry->[2] eq 'DOWN'){ |
113
|
0
|
|
|
|
|
|
$tex.="\\move(7 -@{[(1+($i{down})*0.5+$dim{y})*$dy]}) "; |
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$tex.="\\small \\htext{$sno $entry->[3]} "; |
115
|
0
|
|
|
|
|
|
$i{down}++; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$tex.="\\move(@{[$entry->[1]*$dx + 0.1]} -@{[$entry->[0]*$dy + 0.4]}) "; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$tex.="\\htext{$sno} "; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
unless($sno{$entry->[0].q/./.$entry->[1]}){ |
122
|
0
|
|
|
|
|
|
$sno{$entry->[0].q/./.$entry->[1]} = $i; |
123
|
0
|
|
|
|
|
|
$i++; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif($_[1] eq 'solution'){ |
129
|
0
|
|
|
|
|
|
for my$entry ( @{$_[0]->{_LEXICON_ARR}} ){ |
|
0
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $i=0; |
131
|
0
|
|
|
|
|
|
for my $letter (split //, $entry->[4]){ |
132
|
0
|
0
|
|
|
|
|
$tex .= $entry->[2] eq 'ACROSS' ? |
133
|
0
|
|
|
|
|
|
"\\move(@{[($entry->[1]+$i++)*$dx + 0.2]} -@{[$entry->[0]*$dy + 0.65]}) " : "\\move(@{[$entry->[1]*$dx + 0.2]} -@{[($entry->[0]+$i++)*$dy + 0.65]}) " ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$tex.="\\LARGE \\htext{@{[uc$letter]}} "; |
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
if($_[2]){ |
142
|
0
|
|
|
|
|
|
open F, '>', $_[2]; |
143
|
0
|
|
|
|
|
|
print F $HEAD.$tex.$FOOT; |
144
|
0
|
|
|
|
|
|
close F; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else{ |
147
|
0
|
|
|
|
|
|
$HEAD.$tex.$FOOT; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
__END__ |