line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Solitaire::Verify::Foundations; |
2
|
|
|
|
|
|
|
$Games::Solitaire::Verify::Foundations::VERSION = '0.2402'; |
3
|
8
|
|
|
8
|
|
57
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
266
|
|
4
|
8
|
|
|
8
|
|
43
|
use strict; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
172
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
55
|
use parent 'Games::Solitaire::Verify::Base'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
38
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
453
|
use Games::Solitaire::Verify::Exception (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
117
|
|
10
|
8
|
|
|
8
|
|
74
|
use Games::Solitaire::Verify::Card (); |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
6485
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# _s is the string. |
13
|
|
|
|
|
|
|
__PACKAGE__->mk_acc_ref( |
14
|
|
|
|
|
|
|
[ |
15
|
|
|
|
|
|
|
qw( |
16
|
|
|
|
|
|
|
_num_decks |
17
|
|
|
|
|
|
|
_founds |
18
|
|
|
|
|
|
|
_s |
19
|
|
|
|
|
|
|
) |
20
|
|
|
|
|
|
|
] |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Suits sequence: |
24
|
|
|
|
|
|
|
my @SS = ( @{ Games::Solitaire::Verify::Card->get_suits_seq() } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Reverse. |
27
|
|
|
|
|
|
|
my %RS = ( map { $SS[$_] => $_ } ( 0 .. $#SS ) ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Ranks |
30
|
|
|
|
|
|
|
my @R = ( @{ Games::Solitaire::Verify::Card->get_ranks_strings() } ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _input_from_string |
34
|
|
|
|
|
|
|
{ |
35
|
274
|
|
|
274
|
|
463
|
my $self = shift; |
36
|
274
|
|
|
|
|
569
|
my $str = shift; |
37
|
|
|
|
|
|
|
|
38
|
274
|
|
|
|
|
469
|
my $rank_re = '[0A1-9TJQK]'; |
39
|
|
|
|
|
|
|
|
40
|
274
|
50
|
|
|
|
2344
|
if ( $str !~ |
41
|
|
|
|
|
|
|
m{\AFoundations: H-($rank_re) C-($rank_re) D-($rank_re) S-($rank_re) *\z}ms |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
0
|
die "str=<$str>"; |
45
|
0
|
|
|
|
|
0
|
Games::Solitaire::Verify::Exception::Parse::State::Foundations->throw( |
46
|
|
|
|
|
|
|
error => "Wrong Foundations", ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
{ |
49
|
274
|
|
|
|
|
542
|
my @founds_strings = ( $1, $2, $3, $4 ); |
|
274
|
|
|
|
|
1215
|
|
50
|
|
|
|
|
|
|
|
51
|
274
|
|
|
|
|
612
|
foreach my $suit (@SS) |
52
|
|
|
|
|
|
|
{ |
53
|
1096
|
|
|
|
|
2821
|
$self->assign( |
54
|
|
|
|
|
|
|
$suit, 0, |
55
|
|
|
|
|
|
|
Games::Solitaire::Verify::Card->calc_rank_with_0( |
56
|
|
|
|
|
|
|
shift(@founds_strings) |
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _init |
64
|
|
|
|
|
|
|
{ |
65
|
281
|
|
|
281
|
|
613
|
my ( $self, $args ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
281
|
50
|
|
|
|
704
|
if ( !exists( $args->{num_decks} ) ) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
die "No number of decks were specified"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
281
|
|
|
|
|
660
|
$self->_num_decks( $args->{num_decks} ); |
73
|
|
|
|
|
|
|
|
74
|
281
|
|
|
|
|
680
|
$self->_founds( +{ map { $_ => [ (0) x $self->_num_decks() ], } @SS } ); |
|
1124
|
|
|
|
|
3328
|
|
75
|
|
|
|
|
|
|
|
76
|
281
|
|
|
|
|
799
|
$self->_s( $self->_init_s ); |
77
|
|
|
|
|
|
|
|
78
|
281
|
100
|
|
|
|
780
|
if ( exists( $args->{string} ) ) |
79
|
|
|
|
|
|
|
{ |
80
|
274
|
|
|
|
|
680
|
$self->_input_from_string( $args->{string} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
281
|
|
|
|
|
575
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub value |
88
|
|
|
|
|
|
|
{ |
89
|
2018
|
|
|
2018
|
1
|
3844
|
my ( $self, $suit, $idx ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
2018
|
|
|
|
|
7180
|
return $self->_founds()->{$suit}->[$idx]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub assign |
96
|
|
|
|
|
|
|
{ |
97
|
1124
|
|
|
1124
|
1
|
2102
|
my ( $self, $suit, $idx, $rank ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
1124
|
|
|
|
|
2209
|
$self->_founds()->{$suit}->[$idx] = $rank; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Replace the rank in place. |
102
|
1124
|
|
|
|
|
2556
|
substr( $self->{_s}, ( length('Foundations:') + 3 ) + ( $RS{$suit} << 2 ), |
103
|
|
|
|
|
|
|
1, $R[$rank] ); |
104
|
1124
|
|
|
|
|
2574
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub increment |
109
|
|
|
|
|
|
|
{ |
110
|
833
|
|
|
833
|
1
|
1549
|
my ( $self, $suit, $idx ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
substr( |
113
|
|
|
|
|
|
|
$self->{_s}, ( length('Foundations:') + 3 ) + ( $RS{$suit} << 2 ), |
114
|
833
|
|
|
|
|
2978
|
1, $R[ ++( $self->_founds()->{$suit}->[$idx] ) ] |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
833
|
|
|
|
|
1760
|
return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _foundations_strings |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
0
|
return []; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub to_string |
129
|
|
|
|
|
|
|
{ |
130
|
2226
|
|
|
2226
|
1
|
6354
|
return $_[0]->_s; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _init_s |
134
|
|
|
|
|
|
|
{ |
135
|
281
|
|
|
281
|
|
490
|
my $S = shift; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return "Foundations:" |
138
|
281
|
|
|
|
|
557
|
. join( "", map { " $_-" . $R[ $S->value( $_, 0 ) ] } @SS ); |
|
1124
|
|
|
|
|
2873
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub clone |
143
|
|
|
|
|
|
|
{ |
144
|
7
|
|
|
7
|
1
|
17
|
my $self = shift; |
145
|
|
|
|
|
|
|
|
146
|
7
|
|
|
|
|
31
|
my $copy = __PACKAGE__->new( |
147
|
|
|
|
|
|
|
{ |
148
|
|
|
|
|
|
|
num_decks => $self->_num_decks(), |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
7
|
|
|
|
|
20
|
foreach my $suit (@SS) |
153
|
|
|
|
|
|
|
{ |
154
|
28
|
|
|
|
|
67
|
foreach my $deck_idx ( 0 .. ( $self->_num_decks() - 1 ) ) |
155
|
|
|
|
|
|
|
{ |
156
|
28
|
|
|
|
|
60
|
$copy->assign( $suit, $deck_idx, |
157
|
|
|
|
|
|
|
$self->value( $suit, $deck_idx ), ); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
7
|
|
|
|
|
29
|
return $copy; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; # End of Games::Solitaire::Verify::Move |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |