line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Sudoku::Component::Controller::Status;
|
2
|
|
|
|
|
|
|
{
|
3
|
4
|
|
|
4
|
|
20371
|
use strict;
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
141
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings;
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
95
|
|
5
|
4
|
|
|
4
|
|
25
|
use Carp;
|
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
2919
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $S_NULL = 0;
|
10
|
|
|
|
|
|
|
my $S_OK = 1;
|
11
|
|
|
|
|
|
|
my $S_REWIND = 2;
|
12
|
|
|
|
|
|
|
my $S_SOLVED = 4;
|
13
|
|
|
|
|
|
|
my $S_GIVEUP = 8;
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new {
|
16
|
8
|
|
|
8
|
1
|
1073
|
my $class = shift;
|
17
|
8
|
|
33
|
|
|
75
|
my $this = bless {}, (ref $class || $class);
|
18
|
|
|
|
|
|
|
|
19
|
8
|
50
|
|
|
|
45
|
my %options = ref $_[0] ? %{ $_[0] } : @_;
|
|
0
|
|
|
|
|
0
|
|
20
|
|
|
|
|
|
|
|
21
|
8
|
|
|
|
|
31
|
$this->{status} = $S_NULL;
|
22
|
8
|
|
|
|
|
16
|
$this->{changed} = 0;
|
23
|
|
|
|
|
|
|
|
24
|
8
|
|
100
|
|
|
30
|
$this->{rewind_max} = $options{rewind_max} || 9;
|
25
|
8
|
|
100
|
|
|
26
|
$this->{retry_max} = $options{retry_max} || 3;
|
26
|
|
|
|
|
|
|
|
27
|
8
|
|
|
|
|
22
|
$this->{rewind} = 0;
|
28
|
8
|
|
|
|
|
13
|
$this->{retry} = 0;
|
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
29
|
$this;
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub clear {
|
34
|
11
|
|
|
11
|
1
|
207
|
my $this = shift;
|
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
24
|
$this->{status} = $S_NULL;
|
37
|
11
|
|
|
|
|
21
|
$this->{rewind} = 0;
|
38
|
11
|
|
|
|
|
27
|
$this->{retry} = 0;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
22
|
|
|
22
|
1
|
255
|
sub turn_to_ok { $_[0]->{status} = $S_OK; $_[0]->{changed} = 1; }
|
|
22
|
|
|
|
|
69
|
|
42
|
13
|
|
|
13
|
1
|
316
|
sub turn_to_rewind { $_[0]->{status} = $S_REWIND; $_[0]->{changed} = 1; }
|
|
13
|
|
|
|
|
41
|
|
43
|
8
|
|
|
8
|
1
|
301
|
sub turn_to_solved { $_[0]->{status} = $S_SOLVED; $_[0]->{changed} = 1; }
|
|
8
|
|
|
|
|
27
|
|
44
|
1
|
|
|
1
|
1
|
261
|
sub turn_to_giveup { $_[0]->{status} = $S_GIVEUP; $_[0]->{changed} = 1; }
|
|
1
|
|
|
|
|
4
|
|
45
|
|
|
|
|
|
|
|
46
|
547
|
|
|
547
|
1
|
2705
|
sub is_null { ($_[0]->{status} == $S_NULL); }
|
47
|
547
|
|
|
547
|
1
|
3453
|
sub is_ok { ($_[0]->{status} == $S_OK); }
|
48
|
547
|
|
|
547
|
1
|
3943
|
sub is_rewind { ($_[0]->{status} == $S_REWIND); }
|
49
|
7
|
|
|
7
|
1
|
2034
|
sub is_solved { ($_[0]->{status} == $S_SOLVED); }
|
50
|
6
|
|
|
6
|
1
|
1498
|
sub is_giveup { ($_[0]->{status} == $S_GIVEUP); }
|
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
7
|
1
|
1491
|
sub is_changed { my $prev = $_[0]->{changed}; $_[0]->{changed} = 0; $prev; }
|
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
710
|
|
53
|
554
|
|
|
554
|
1
|
4331
|
sub is_finished { $_[0]->{status} & ($S_GIVEUP|$S_SOLVED) }
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub can_rewind {
|
56
|
28
|
|
|
28
|
1
|
3016
|
my $this = shift;
|
57
|
28
|
|
|
|
|
145
|
($this->{rewind}++ < $this->{rewind_max});
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub can_retry {
|
61
|
8
|
|
|
8
|
1
|
1241
|
my $this = shift;
|
62
|
8
|
|
|
|
|
12
|
$this->{rewind} = 0;
|
63
|
8
|
|
|
|
|
33
|
($this->{retry}++ < $this->{retry_max});
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1;
|
68
|
|
|
|
|
|
|
__END__
|