line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Nonogram::Shell;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1292
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
321
|
use Games::Nonogram::Grid;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1029
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my @has_aliases = qw( auto load row col quit exit );
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub bootstrap {
|
10
|
0
|
|
|
0
|
|
|
my $class = shift;
|
11
|
0
|
|
|
|
|
|
my $self = bless {}, $class;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# set aliases
|
14
|
0
|
|
|
|
|
|
my %alias;
|
15
|
0
|
|
|
|
|
|
foreach my $cmd ( @has_aliases ) {
|
16
|
0
|
|
|
|
|
|
$alias{ substr( $cmd, 0, 1 ) } = $cmd;
|
17
|
|
|
|
|
|
|
}
|
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
while ( print '> ' ) {
|
20
|
0
|
|
|
|
|
|
my $input = ;
|
21
|
0
|
0
|
|
|
|
|
$input = '' unless defined $input;
|
22
|
0
|
|
|
|
|
|
chomp $input;
|
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my ($cmd, $args) = split /\s+/, $input, 2;
|
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
$cmd = '_next' unless defined $cmd;
|
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
$cmd = $alias{$cmd} if exists $alias{$cmd};
|
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
0
|
|
|
|
last if $cmd eq 'quit' || $cmd eq 'exit';
|
31
|
0
|
0
|
|
|
|
|
next if $cmd eq 'bootstrap';
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$self->$cmd( $args ) if $self->can( $cmd );
|
34
|
|
|
|
|
|
|
}
|
35
|
0
|
|
|
|
|
|
$self;
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub load {
|
39
|
0
|
|
|
0
|
1
|
|
my ($self, $file) = @_;
|
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
0
|
|
|
|
return unless $file && -f $file;
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $grid = Games::Nonogram::Grid->new_from( file => $file );
|
44
|
0
|
|
|
|
|
|
$grid->as_string;
|
45
|
0
|
|
|
|
|
|
$grid->clear_stash;
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{grid} = $grid;
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub logfile {
|
51
|
0
|
|
|
0
|
1
|
|
my ($self, $file) = @_;
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$grid->set_logfile( $file );
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _next {
|
59
|
0
|
|
|
0
|
|
|
my $self = shift;
|
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ( $grid->has_answers ) {
|
|
|
0
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
print "\nAnswers\n", join "\n", $grid->answers, "\nOK\n";
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
elsif ( $grid->is_done ) {
|
67
|
0
|
|
|
|
|
|
$grid->as_string;
|
68
|
0
|
|
|
|
|
|
print "\nOK\n";
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
else {
|
71
|
0
|
|
|
|
|
|
$grid->update;
|
72
|
0
|
|
|
|
|
|
$grid->as_string;
|
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
print "\nOK\n" if $grid->is_done;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub auto {
|
79
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
while ( $grid->is_dirty ) {
|
84
|
0
|
|
|
|
|
|
$grid->update;
|
85
|
0
|
0
|
|
|
|
|
print $grid->as_string, "\n" if $grid->debug;
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
0
|
|
|
|
if ( $grid->is_done or $grid->has_answers ) {
|
89
|
0
|
|
|
|
|
|
print "\nAnswers\n", join "\n", $grid->answers, "\nOK\n";
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
else {
|
92
|
0
|
|
|
|
|
|
print $grid->as_string,"\n";
|
93
|
0
|
|
|
|
|
|
print "\nAborted\n";
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub row {
|
98
|
0
|
|
|
0
|
1
|
|
my ($self, $row) = @_;
|
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
return unless $row && $row =~ /^\d+$/;
|
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$grid->row( $row )->dump_blocks;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub col {
|
108
|
0
|
|
|
0
|
1
|
|
my ($self, $col) = @_;
|
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
0
|
|
|
|
return unless $col && $col =~ /^\d+$/;
|
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$grid->col( $col )->dump_blocks;
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
0
|
1
|
|
sub on { shift->_value( 1, @_ ) }
|
118
|
0
|
|
|
0
|
1
|
|
sub off { shift->_value( 0, @_ ) }
|
119
|
0
|
|
|
0
|
1
|
|
sub clear { shift->_value( -1, @_ ) }
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _value {
|
122
|
0
|
|
|
0
|
|
|
my ($self, $value, $args) = @_;
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my ($row, $col) = split /,\s*/, $args;
|
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
0
|
|
|
|
return unless $row && $row =~ /^\d+$/;
|
127
|
0
|
0
|
0
|
|
|
|
return unless $col && $col =~ /^\d+$/;
|
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
eval {
|
132
|
0
|
|
|
|
|
|
$grid->row( $row )->value( $col => $value );
|
133
|
0
|
|
|
|
|
|
$grid->update;
|
134
|
0
|
|
|
|
|
|
$grid->as_string;
|
135
|
|
|
|
|
|
|
};
|
136
|
0
|
0
|
|
|
|
|
if ( $@ ) {
|
137
|
0
|
|
|
|
|
|
print "That would break the puzzle.";
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub debug {
|
142
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_;
|
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
my $grid = $self->{grid} or return;
|
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
$value = 1 unless defined $value;
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$grid->debug( $value );
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1;
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__
|