| 1 | package Dreamhack::Solitaire::Medici; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | no warnings 'recursion'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use base 'Dreamhack::Solitaire'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Dreamhack::Solitaire; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my $imax = (exists $args{'attempts'}) && ($args{'attempts'} =~ m/^[1-9]\d*$/) ? $args{'attempts'} : $self->_iterations(1+$#{$self->{'leftcards'}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args{"attempts"} and $args{"attempts"} =~ /^[1-9]\d*$/
MC/DC0%0/2
exists $args{"attempts"} and $args{"attempts"} =~ /^[1-9]\d*$/
exists $args{"attempts"}
$args{"attempts"} =~ /^[1-9]\d*$/
Truth table33%1/3
A and B
A= exists $args{"attempts"}B= $args{"attempts"} =~ /^[1-9]\d*$/
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | for my $i (1..$imax) { | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | my @layout = $self->add_rnd_layout(); | |||||||||||||||||||||||||||
| 20 | 2 | my @save = @layout; | |||||||||||||||||||||||||||
| 21 | 2 | my @work = (); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | my $cardno = 0; | |||||||||||||||||||||||||||
| 24 | 2 | ▶ | while (@layout) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 72 | my $el = shift @layout; | |||||||||||||||||||||||||||
| 26 | 72 | push @work, $el; | |||||||||||||||||||||||||||
| 27 | 72 | @work = $self->_pass(0, \@work, $cardno++); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | $self->{'attempts'} = $i; | |||||||||||||||||||||||||||
| 31 | 2 | ▶ | if ($#work <= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $self->{'layout'} = \@save; | |||||||||||||||||||||||||||
| 33 | 1 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 1 | $self->{'convolution'} = []; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 1 | return undef; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 446 | ▶ | sub _pass { | ||||||||||||||||||||||||||
|
Subroutine
_pass: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 41 | 446 | my ($self, $offset, $work, $cardno) = @_; | |||||||||||||||||||||||||||
| 42 | 446 | my @work = @$work; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 446 | ▶ | if (($offset >=0) && ($#work - $offset >= 2)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$offset >= 0 and $#work - $offset >= 2
MC/DC100%2/2
$offset >= 0 and $#work - $offset >= 2
$offset >= 0
$#work - $offset >= 2
Truth table100%3/3
A and B
A= $offset >= 0B= $#work - $offset >= 2
| |||||||||||||||||||||||||||||
| 45 | 374 | my ($vr, $sr) = $self->extract($work[$#work - $offset]); | |||||||||||||||||||||||||||
| 46 | 374 | my ($vl, $sl) = $self->extract($work[$#work - $offset - 2]); | |||||||||||||||||||||||||||
| 47 | 374 | ▶ | if (($vl eq $vr) or ($sl eq $sr)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$vl eq $vr or $sl eq $sr
MC/DC100%2/2
$vl eq $vr or $sl eq $sr
$vl eq $vr
$sl eq $sr
Truth table100%3/3
A or B
A= $vl eq $vrB= $sl eq $sr
| |||||||||||||||||||||||||||||
| 48 | 67 | $work[$#work - $offset - 2] = $work[$#work - $offset - 1]; | |||||||||||||||||||||||||||
| 49 | 67 | splice @work, $#work - $offset - 1, 1; | |||||||||||||||||||||||||||
| 50 | 67 | ▶ | if ($cardno) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 24 | push @{$self->{'convolution'}}, $cardno; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 67 | @work = $self->_pass($#work-2, \@work); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||
| 56 | 307 | @work = $self->_pass(--$offset, \@work); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||
| 60 | return @work | ||||||||||||||||||||||||||||
| 61 | 72 | } | |||||||||||||||||||||||||||
| 62 | return @work | ||||||||||||||||||||||||||||
| 63 | 374 | } | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub _iterations { | ||||||||||||||||||||||||||
|
Subroutine
_iterations: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 66 | 2 | my ($self, $cardscount) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | my $imax = 0; | |||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ($cardscount <= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2 | $imax = 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | $imax = 100_000; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 2 | return $imax | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | 1; | |||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||