line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dreamhack::Solitaire::Medici; |
2
|
2
|
|
|
2
|
|
20284
|
use 5.008001; |
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
5
|
2
|
|
|
2
|
|
9
|
no warnings 'recursion'; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
77
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
9
|
use base 'Dreamhack::Solitaire'; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
1387
|
|
8
|
2
|
|
|
2
|
|
30678
|
use Dreamhack::Solitaire; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1007
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
13
|
2
|
|
|
2
|
1
|
3747
|
my ($self, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
50
|
33
|
|
|
13
|
my $imax = (exists $args{'attempts'}) && ($args{'attempts'} =~ m/^[1-9]\d*$/) ? $args{'attempts'} : $self->_iterations(1+$#{$self->{'leftcards'}}); |
|
2
|
|
|
|
|
10
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
6
|
for my $i (1..$imax) { |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
13
|
my @layout = $self->add_rnd_layout(); |
20
|
2
|
|
|
|
|
276
|
my @save = @layout; |
21
|
2
|
|
|
|
|
4
|
my @work = (); |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
3
|
my $cardno = 0; |
24
|
2
|
|
|
|
|
7
|
while (@layout) { |
25
|
72
|
|
|
|
|
106
|
my $el = shift @layout; |
26
|
72
|
|
|
|
|
109
|
push @work, $el; |
27
|
72
|
|
|
|
|
156
|
@work = $self->_pass(0, \@work, $cardno++); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
4
|
$self->{'attempts'} = $i; |
31
|
2
|
100
|
|
|
|
7
|
if ($#work <= 1) { |
32
|
1
|
|
|
|
|
2
|
$self->{'layout'} = \@save; |
33
|
1
|
|
|
|
|
8
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
1
|
|
|
|
|
47
|
$self->{'convolution'} = []; |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
|
|
8
|
return undef; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _pass { |
41
|
446
|
|
|
446
|
|
579
|
my ($self, $offset, $work, $cardno) = @_; |
42
|
446
|
|
|
|
|
1417
|
my @work = @$work; |
43
|
|
|
|
|
|
|
|
44
|
446
|
100
|
100
|
|
|
1500
|
if (($offset >=0) && ($#work - $offset >= 2)) { |
45
|
374
|
|
|
|
|
975
|
my ($vr, $sr) = $self->extract($work[$#work - $offset]); |
46
|
374
|
|
|
|
|
2906
|
my ($vl, $sl) = $self->extract($work[$#work - $offset - 2]); |
47
|
374
|
100
|
100
|
|
|
3025
|
if (($vl eq $vr) or ($sl eq $sr)) { |
48
|
67
|
|
|
|
|
116
|
$work[$#work - $offset - 2] = $work[$#work - $offset - 1]; |
49
|
67
|
|
|
|
|
101
|
splice @work, $#work - $offset - 1, 1; |
50
|
67
|
100
|
|
|
|
124
|
if ($cardno) { |
51
|
24
|
|
|
|
|
27
|
push @{$self->{'convolution'}}, $cardno; |
|
24
|
|
|
|
|
43
|
|
52
|
|
|
|
|
|
|
} |
53
|
67
|
|
|
|
|
205
|
@work = $self->_pass($#work-2, \@work); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
307
|
|
|
|
|
768
|
@work = $self->_pass(--$offset, \@work); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
|
|
|
|
|
|
return @work |
61
|
72
|
|
|
|
|
541
|
} |
62
|
|
|
|
|
|
|
return @work |
63
|
374
|
|
|
|
|
2045
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _iterations { |
66
|
2
|
|
|
2
|
|
5
|
my ($self, $cardscount) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
4
|
my $imax = 0; |
69
|
2
|
50
|
|
|
|
9
|
if ($cardscount <= 1) { |
70
|
2
|
|
|
|
|
4
|
$imax = 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
0
|
$imax = 100_000; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
|
|
|
|
4
|
return $imax |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |