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