line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Solitaire::Verify::Foundations; |
2
|
|
|
|
|
|
|
$Games::Solitaire::Verify::Foundations::VERSION = '0.2403'; |
3
|
8
|
|
|
8
|
|
62
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
327
|
|
4
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
176
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
38
|
use parent 'Games::Solitaire::Verify::Base'; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
46
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
473
|
use Games::Solitaire::Verify::Exception (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
115
|
|
10
|
8
|
|
|
8
|
|
84
|
use Games::Solitaire::Verify::Card (); |
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
6529
|
|
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
|
|
467
|
my $self = shift; |
36
|
274
|
|
|
|
|
524
|
my $str = shift; |
37
|
|
|
|
|
|
|
|
38
|
274
|
|
|
|
|
464
|
my $rank_re = '[0A1-9TJQK]'; |
39
|
|
|
|
|
|
|
|
40
|
274
|
50
|
|
|
|
2362
|
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
|
|
|
|
|
539
|
my @founds_strings = ( $1, $2, $3, $4 ); |
|
274
|
|
|
|
|
1201
|
|
50
|
|
|
|
|
|
|
|
51
|
274
|
|
|
|
|
643
|
foreach my $suit (@SS) |
52
|
|
|
|
|
|
|
{ |
53
|
1096
|
|
|
|
|
2810
|
$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
|
|
621
|
my ( $self, $args ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
281
|
50
|
|
|
|
674
|
if ( !exists( $args->{num_decks} ) ) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
die "No number of decks were specified"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
281
|
|
|
|
|
661
|
$self->_num_decks( $args->{num_decks} ); |
73
|
|
|
|
|
|
|
|
74
|
281
|
|
|
|
|
634
|
$self->_founds( +{ map { $_ => [ (0) x $self->_num_decks() ], } @SS } ); |
|
1124
|
|
|
|
|
3189
|
|
75
|
|
|
|
|
|
|
|
76
|
281
|
|
|
|
|
848
|
$self->_s( $self->_init_s ); |
77
|
|
|
|
|
|
|
|
78
|
281
|
100
|
|
|
|
763
|
if ( exists( $args->{string} ) ) |
79
|
|
|
|
|
|
|
{ |
80
|
274
|
|
|
|
|
649
|
$self->_input_from_string( $args->{string} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
281
|
|
|
|
|
593
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub value |
88
|
|
|
|
|
|
|
{ |
89
|
2018
|
|
|
2018
|
1
|
3959
|
my ( $self, $suit, $idx ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
2018
|
|
|
|
|
6926
|
return $self->_founds()->{$suit}->[$idx]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub assign |
96
|
|
|
|
|
|
|
{ |
97
|
1124
|
|
|
1124
|
1
|
2116
|
my ( $self, $suit, $idx, $rank ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
1124
|
|
|
|
|
2164
|
$self->_founds()->{$suit}->[$idx] = $rank; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Replace the rank in place. |
102
|
1124
|
|
|
|
|
2559
|
substr( $self->{_s}, ( length('Foundations:') + 3 ) + ( $RS{$suit} << 2 ), |
103
|
|
|
|
|
|
|
1, $R[$rank] ); |
104
|
1124
|
|
|
|
|
2597
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub increment |
109
|
|
|
|
|
|
|
{ |
110
|
833
|
|
|
833
|
1
|
1599
|
my ( $self, $suit, $idx ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
substr( |
113
|
|
|
|
|
|
|
$self->{_s}, ( length('Foundations:') + 3 ) + ( $RS{$suit} << 2 ), |
114
|
833
|
|
|
|
|
3091
|
1, $R[ ++( $self->_founds()->{$suit}->[$idx] ) ] |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
833
|
|
|
|
|
1705
|
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
|
6067
|
return $_[0]->_s; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _init_s |
134
|
|
|
|
|
|
|
{ |
135
|
281
|
|
|
281
|
|
476
|
my $S = shift; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return "Foundations:" |
138
|
281
|
|
|
|
|
586
|
. join( "", map { " $_-" . $R[ $S->value( $_, 0 ) ] } @SS ); |
|
1124
|
|
|
|
|
2492
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub clone |
143
|
|
|
|
|
|
|
{ |
144
|
7
|
|
|
7
|
1
|
19
|
my $self = shift; |
145
|
|
|
|
|
|
|
|
146
|
7
|
|
|
|
|
36
|
my $copy = __PACKAGE__->new( |
147
|
|
|
|
|
|
|
{ |
148
|
|
|
|
|
|
|
num_decks => $self->_num_decks(), |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
7
|
|
|
|
|
22
|
foreach my $suit (@SS) |
153
|
|
|
|
|
|
|
{ |
154
|
28
|
|
|
|
|
65
|
foreach my $deck_idx ( 0 .. ( $self->_num_decks() - 1 ) ) |
155
|
|
|
|
|
|
|
{ |
156
|
28
|
|
|
|
|
67
|
$copy->assign( $suit, $deck_idx, |
157
|
|
|
|
|
|
|
$self->value( $suit, $deck_idx ), ); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
7
|
|
|
|
|
25
|
return $copy; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; # End of Games::Solitaire::Verify::Move |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |