line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Nonogram::CommandLine;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2611
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
1143
|
use Getopt::Long;
|
|
1
|
|
|
|
|
13224
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
188
|
use Games::Nonogram::Grid;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
682
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub bootstrap {
|
9
|
0
|
|
|
0
|
|
|
my $class = shift;
|
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
my %options;
|
12
|
0
|
|
|
|
|
|
GetOptions(
|
13
|
|
|
|
|
|
|
'dir=s' => \$options{dir},
|
14
|
|
|
|
|
|
|
'check_only' => \$options{check_only},
|
15
|
|
|
|
|
|
|
'debug' => \$options{debug},
|
16
|
|
|
|
|
|
|
'verbose' => \$options{verbose},
|
17
|
|
|
|
|
|
|
);
|
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my @files = @ARGV;
|
20
|
0
|
0
|
|
|
|
|
push @files, $class->_files_from_dir( $options{dir} ) if $options{dir};
|
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
foreach my $file ( @files ) {
|
23
|
0
|
|
|
|
|
|
$class->_solve( $file, \%options );
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _files_from_dir {
|
28
|
0
|
|
|
0
|
|
|
my ($class, $dir) = @_;
|
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
$dir .= '/' unless $dir =~ m{[/\\]$};
|
31
|
0
|
|
|
|
|
|
$dir .= '*';
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
my @dirs = grep { /^[^\.]/ && -f } glob( $dir );
|
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
}
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _solve {
|
37
|
0
|
|
|
0
|
|
|
my ($class, $file, $options) = @_;
|
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
0
|
|
|
|
return unless $file && -f $file;
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $grid = Games::Nonogram::Grid->new_from( file => $file );
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
0
|
|
|
|
my $debug = $options->{debug} || 0;
|
44
|
0
|
|
0
|
|
|
|
my $verbose = $options->{verbose} || $debug;
|
45
|
0
|
|
0
|
|
|
|
my $check_only = $options->{check_only} || 0;
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$grid->debug( $debug );
|
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
while ( $grid->is_dirty ) {
|
50
|
0
|
|
|
|
|
|
$grid->update;
|
51
|
0
|
0
|
|
|
|
|
print $grid->as_string,"\n" if $verbose;
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
if ( $grid->is_done or $grid->has_answers ) {
|
55
|
0
|
|
|
|
|
|
my @answers = $grid->answers;
|
56
|
0
|
0
|
|
|
|
|
unless ( $check_only ) {
|
|
|
0
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
print "\n$file: Answers\n", join "\n", @answers;
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
elsif ( @answers > 1 ) {
|
60
|
0
|
|
|
|
|
|
print "$file is ambiguous.\n";
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
else {
|
63
|
0
|
|
|
|
|
|
print "$file is ok.\n";
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
else {
|
67
|
0
|
0
|
|
|
|
|
unless ( $check_only ) {
|
68
|
0
|
|
|
|
|
|
print "\n$file: Failed\n";
|
69
|
0
|
|
|
|
|
|
print $grid->as_string,"\n";
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
else {
|
72
|
0
|
|
|
|
|
|
print "$file seems broken.\n";
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1;
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__
|