line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Sudoku::Component::Table;
|
2
|
|
|
|
|
|
|
{
|
3
|
4
|
|
|
4
|
|
22732
|
use strict;
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
162
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings;
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
116
|
|
5
|
4
|
|
|
4
|
|
30
|
use Carp;
|
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
434
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02';
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
26
|
use base qw/Games::Sudoku::Component::Base/;
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
9081
|
|
10
|
4
|
|
|
4
|
|
2789
|
use Games::Sudoku::Component::Table::Cell;
|
|
4
|
|
|
|
|
32
|
|
|
4
|
|
|
|
|
117
|
|
11
|
4
|
|
|
4
|
|
2585
|
use Games::Sudoku::Component::Table::Item;
|
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
121
|
|
12
|
4
|
|
|
4
|
|
3364
|
use Games::Sudoku::Component::Table::Permission;
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
7186
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _initialize {
|
15
|
9
|
|
|
9
|
|
24
|
my ($this, %options) = @_;
|
16
|
|
|
|
|
|
|
|
17
|
9
|
|
|
|
|
19
|
my $size = $this->{size};
|
18
|
9
|
|
|
|
|
16
|
my $block_width = $this->{block_width};
|
19
|
9
|
|
|
|
|
16
|
my $block_height = $this->{block_height};
|
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
|
|
76
|
my $perm = Games::Sudoku::Component::Table::Permission->new(
|
22
|
|
|
|
|
|
|
block_width => $block_width,
|
23
|
|
|
|
|
|
|
block_height => $block_height,
|
24
|
|
|
|
|
|
|
);
|
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
|
|
21
|
foreach my $row (1..$size) {
|
27
|
93
|
|
|
|
|
177
|
foreach my $col (1..$size) {
|
28
|
1119
|
|
|
|
|
2338
|
my $cell_id = $this->_cell_id($row, $col);
|
29
|
1119
|
|
|
|
|
3849
|
$this->{cells}->[$cell_id] =
|
30
|
|
|
|
|
|
|
Games::Sudoku::Component::Table::Cell->new(
|
31
|
|
|
|
|
|
|
row => $row,
|
32
|
|
|
|
|
|
|
col => $col,
|
33
|
|
|
|
|
|
|
block_width => $block_width,
|
34
|
|
|
|
|
|
|
block_height => $block_height,
|
35
|
|
|
|
|
|
|
perm => $perm,
|
36
|
|
|
|
|
|
|
);
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub cells {
|
42
|
502
|
|
|
502
|
1
|
2041
|
my $this = shift;
|
43
|
|
|
|
|
|
|
|
44
|
502
|
|
|
|
|
560
|
my @cells = @{ $this->{cells} };
|
|
502
|
|
|
|
|
8284
|
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub cell {
|
48
|
1339
|
|
|
1339
|
1
|
50746
|
my ($this, $row, $col) = @_;
|
49
|
|
|
|
|
|
|
|
50
|
1339
|
|
|
|
|
2795
|
my $cell_id = $this->_cell_id($row, $col);
|
51
|
|
|
|
|
|
|
|
52
|
1339
|
|
|
|
|
5826
|
$this->{cells}->[$cell_id];
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _cell_id {
|
56
|
2458
|
|
|
2458
|
|
3343
|
my ($this, $row, $col) = @_;
|
57
|
|
|
|
|
|
|
|
58
|
2458
|
50
|
|
|
|
6590
|
croak "Invalid row: $row" unless $this->_check($row);
|
59
|
2458
|
50
|
|
|
|
6629
|
croak "Invalid col: $col" unless $this->_check($col);
|
60
|
|
|
|
|
|
|
|
61
|
2458
|
|
|
|
|
6420
|
($row - 1) * $this->{size} + ($col - 1);
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub clear {
|
65
|
2
|
|
|
2
|
1
|
685
|
my $this = shift;
|
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
10
|
foreach my $cell ($this->cells) {
|
68
|
117
|
|
|
|
|
294
|
$cell->unlock;
|
69
|
117
|
|
|
|
|
287
|
$cell->value(0);
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub find_next {
|
74
|
470
|
|
|
470
|
1
|
1167
|
my $this = shift;
|
75
|
|
|
|
|
|
|
|
76
|
470
|
|
|
|
|
670
|
my $size = $this->{size};
|
77
|
470
|
|
|
|
|
658
|
my $min = $size + 1;
|
78
|
470
|
|
|
|
|
564
|
my $next = undef;
|
79
|
470
|
|
|
|
|
1277
|
foreach my $cell ($this->cells) {
|
80
|
20670
|
100
|
|
|
|
52337
|
my @allowed = $cell->allowed or next;
|
81
|
|
|
|
|
|
|
|
82
|
7784
|
100
|
|
|
|
20518
|
if (scalar @allowed < $min) {
|
83
|
607
|
|
|
|
|
697
|
$min = scalar @allowed;
|
84
|
607
|
|
|
|
|
1940
|
$next = {
|
85
|
|
|
|
|
|
|
row => $cell->row,
|
86
|
|
|
|
|
|
|
col => $cell->col,
|
87
|
|
|
|
|
|
|
allowed => \@allowed,
|
88
|
|
|
|
|
|
|
};
|
89
|
|
|
|
|
|
|
}
|
90
|
7784
|
100
|
|
|
|
20853
|
last if $min == 1;
|
91
|
|
|
|
|
|
|
}
|
92
|
470
|
100
|
|
|
|
7051
|
$next ? Games::Sudoku::Component::Table::Item->new($next) : undef;
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub find_all {
|
96
|
1
|
|
|
1
|
1
|
768
|
my $this = shift;
|
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
3
|
my $size = $this->{size};
|
99
|
1
|
|
|
|
|
2
|
my $min = $size + 1;
|
100
|
1
|
|
|
|
|
3
|
my @all = ();
|
101
|
1
|
|
|
|
|
5
|
foreach my $cell ($this->cells) {
|
102
|
81
|
50
|
|
|
|
247
|
my @allowed = $cell->allowed or next;
|
103
|
81
|
100
|
|
|
|
210
|
if (scalar @allowed < $min) {
|
104
|
1
|
|
|
|
|
2
|
@all = ();
|
105
|
1
|
|
|
|
|
2
|
$min = scalar @allowed;
|
106
|
|
|
|
|
|
|
}
|
107
|
81
|
50
|
|
|
|
166
|
if (scalar @allowed == $min) {
|
108
|
81
|
|
|
|
|
249
|
push @all, Games::Sudoku::Component::Table::Item->new(
|
109
|
|
|
|
|
|
|
row => $cell->row,
|
110
|
|
|
|
|
|
|
col => $cell->col,
|
111
|
|
|
|
|
|
|
allowed => \@allowed,
|
112
|
|
|
|
|
|
|
);
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
}
|
115
|
1
|
|
|
|
|
93
|
@all;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub lock_all {
|
119
|
2
|
|
|
2
|
1
|
5
|
my $this = shift;
|
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
9
|
foreach my $cell ($this->cells) {
|
122
|
72
|
50
|
|
|
|
163
|
$cell->lock if $cell->realvalue;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub unlock_all {
|
127
|
0
|
|
|
0
|
1
|
0
|
my $this = shift;
|
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
foreach my $cell ($this->cells) {
|
130
|
0
|
|
|
|
|
0
|
$cell->unlock;
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub check_tmpvalue {
|
135
|
2
|
|
|
2
|
1
|
1225
|
my $this = shift;
|
136
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
5
|
my $size = $this->{size};
|
138
|
|
|
|
|
|
|
|
139
|
2
|
|
|
|
|
8
|
foreach my $cell ($this->cells) {
|
140
|
162
|
100
|
|
|
|
418
|
my $tmpvalue = $cell->tmpvalue or next;
|
141
|
2
|
50
|
|
|
|
8
|
if ($cell->is_allowed($tmpvalue)) {
|
142
|
2
|
|
|
|
|
7
|
$cell->value($tmpvalue);
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub num_of_finished {
|
148
|
0
|
|
|
0
|
1
|
0
|
my $this = shift;
|
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
my $sum = 0;
|
151
|
0
|
|
|
|
|
0
|
foreach my $cell ($this->cells) {
|
152
|
0
|
0
|
|
|
|
0
|
$sum++ if $cell->realvalue;
|
153
|
|
|
|
|
|
|
}
|
154
|
0
|
|
|
|
|
0
|
$sum;
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub is_finished {
|
158
|
22
|
|
|
22
|
1
|
51
|
my $this = shift;
|
159
|
|
|
|
|
|
|
|
160
|
22
|
|
|
|
|
84
|
foreach my $cell ($this->cells) {
|
161
|
511
|
100
|
|
|
|
1134
|
return 0 unless $cell->realvalue;
|
162
|
|
|
|
|
|
|
}
|
163
|
7
|
|
|
|
|
48
|
return 1;
|
164
|
|
|
|
|
|
|
}
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub as_string {
|
167
|
6
|
|
|
6
|
1
|
759
|
my $this = shift;
|
168
|
|
|
|
|
|
|
|
169
|
6
|
50
|
|
|
|
30
|
my %options = ref $_[0] ? %{ $_[0] } : @_;
|
|
0
|
|
|
|
|
0
|
|
170
|
|
|
|
|
|
|
|
171
|
6
|
|
50
|
|
|
44
|
my $separator = $options{separator} || ' ';
|
172
|
6
|
|
50
|
|
|
37
|
my $break = $options{linebreak} || "\n";
|
173
|
|
|
|
|
|
|
|
174
|
6
|
|
|
|
|
17
|
my $size = $this->{size};
|
175
|
6
|
|
|
|
|
38
|
my $digit = int(log($size) / log(10)) + 1;
|
176
|
6
|
|
|
|
|
20
|
my $numfmt = '%'.$digit.'d';
|
177
|
|
|
|
|
|
|
|
178
|
6
|
|
|
|
|
19
|
my @lines;
|
179
|
6
|
|
|
|
|
20
|
foreach my $row (1..$size) {
|
180
|
39
|
|
|
|
|
47
|
my @cells;
|
181
|
39
|
|
|
|
|
66
|
foreach my $col (1..$size) {
|
182
|
261
|
|
|
|
|
529
|
my $value = $this->cell($row, $col)->value;
|
183
|
261
|
|
|
|
|
770
|
push @cells, sprintf($numfmt,$value);
|
184
|
|
|
|
|
|
|
}
|
185
|
39
|
|
|
|
|
172
|
push @lines, join $separator, @cells;
|
186
|
|
|
|
|
|
|
}
|
187
|
6
|
|
|
|
|
49
|
join $break, @lines;
|
188
|
|
|
|
|
|
|
}
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub as_HTML {
|
191
|
1
|
|
|
1
|
1
|
375
|
my $this = shift;
|
192
|
|
|
|
|
|
|
|
193
|
1
|
50
|
|
|
|
5
|
my %options = ref $_[0] ? %{ $_[0] } : @_;
|
|
0
|
|
|
|
|
0
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
50
|
|
|
7
|
my $border = $options{border} || 1;
|
196
|
1
|
|
50
|
|
|
7
|
my $break = $options{linebreak} || "\n";
|
197
|
|
|
|
|
|
|
|
198
|
1
|
|
|
|
|
2
|
my $size = $this->{size};
|
199
|
|
|
|
|
|
|
|
200
|
1
|
|
|
|
|
2
|
my @lines;
|
201
|
1
|
|
|
|
|
3
|
push @lines, qq{};
202
|
1
|
|
|
|
|
3
|
foreach my $row (1..$size) {
|
203
|
9
|
|
|
|
|
9
|
my @cells;
|
204
|
9
|
|
|
|
|
16
|
foreach my $col (1..$size) {
|
205
|
81
|
|
|
|
|
144
|
my $value = $this->cell($row, $col)->value;
|
206
|
81
|
|
|
|
|
272
|
my $class;
|
207
|
81
|
50
|
|
|
|
152
|
if ($options{color_by_block}) {
|
208
|
0
|
0
|
|
|
|
0
|
$class =
|
209
|
|
|
|
|
|
|
$this->_block_id($row, $col) % 2 ? 'odd' : 'even';
|
210
|
|
|
|
|
|
|
}
|
211
|
81
|
50
|
|
|
|
305
|
if ($options{color_by_cell}) {
|
212
|
0
|
0
|
|
|
|
0
|
$class =
|
213
|
|
|
|
|
|
|
$this->_cell_id($row, $col) % 2 ? 'odd' : 'even';
|
214
|
|
|
|
|
|
|
}
|
215
|
81
|
50
|
|
|
|
777
|
push @cells,
|
216
|
|
|
|
|
|
|
$class ? qq{ | } : qq{ | },
|
217
|
|
|
|
|
|
|
qq{$value | };
218
|
|
|
|
|
|
|
}
|
219
|
9
|
|
|
|
|
24
|
my $tds = join '', @cells;
|
220
|
9
|
|
|
|
|
207
|
push @lines, qq{ | $tds };
221
|
|
|
|
|
|
|
}
|
222
|
1
|
|
|
|
|
3
|
push @lines, qq{ | };
|
223
|
1
|
|
|
|
|
10
|
join $break, @lines;
|
224
|
|
|
|
|
|
|
}
|
225
|
|
|
|
|
|
|
}
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1;
|
228
|
|
|
|
|
|
|
__END__
|