| 1 | package Games::Solitaire::Verify::App::CmdLine::Expand; | ||||||||||||||||||||||||||||
| 2 | 2 | $Games::Solitaire::Verify::App::CmdLine::Expand::VERSION = '0.2601'; | |||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Games::Solitaire::Verify::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Data::Dumper qw(Dumper); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Games::Solitaire::Verify::VariantsMap (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Games::Solitaire::Verify::Solution::ExpandMultiCardMoves (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | __PACKAGE__->mk_acc_ref( | |||||||||||||||||||||||||||
| 16 | [ | ||||||||||||||||||||||||||||
| 17 | qw( | ||||||||||||||||||||||||||||
| 18 | _filename | ||||||||||||||||||||||||||||
| 19 | _variant_params | ||||||||||||||||||||||||||||
| 20 | ) | ||||||||||||||||||||||||||||
| 21 | ] | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub _init | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 26 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $argv = $args->{'argv'}; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $variant_map = Games::Solitaire::Verify::VariantsMap->new(); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $variant_params = $variant_map->get_variant_by_id("freecell"); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | GetOptionsFromArray( | ||||||||||||||||||||||||||||
| 35 | $argv, | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | 'g|game|variant=s' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 37 | 0 | my ( undef, $game ) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | $variant_params = $variant_map->get_variant_by_id($game); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( !defined($variant_params) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | die "Unknown variant '$game'!\n"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | 'freecells-num=i' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | 0 | my ( undef, $n ) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | $variant_params->num_freecells($n); | |||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | 'stacks-num=i' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 0 | my ( undef, $n ) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | $variant_params->num_columns($n); | |||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | 'decks-num=i' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 55 | 0 | my ( undef, $n ) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( !( ( $n == 1 ) || ( $n == 2 ) ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n == 1 or $n == 2
MC/DC0%0/2
$n == 1 or $n == 2
$n == 1
$n == 2
Truth table0%0/3
A or B
A= $n == 1B= $n == 2
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | die "Decks should be 1 or 2."; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $variant_params->num_decks($n); | |||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | 'sequences-are-built-by=s' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 65 | 0 | my ( undef, $val ) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | my %seqs_build_by = ( | ||||||||||||||||||||||||||||
| 68 | 0 | ( map { $_ => $_ } (qw(alt_color suit rank)) ), | |||||||||||||||||||||||||||
| 69 | "alternate_color" => "alt_color", | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $proc_val = $seqs_build_by{$val}; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( !defined($proc_val) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 0 | die "Unknown sequences-are-built-by '$val'!"; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $variant_params->seqs_build_by($proc_val); | |||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | 'empty-stacks-filled-by=s' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 82 | 0 | my ( undef, $val ) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my %empty_stacks_filled_by_map = | ||||||||||||||||||||||||||||
| 85 | 0 | ( map { $_ => 1 } (qw(kings any none)) ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( !exists( $empty_stacks_filled_by_map{$val} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | die "Unknown empty stacks filled by '$val'!"; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | $variant_params->empty_stacks_filled_by($val); | |||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | 'sequence-move=s' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 95 | 0 | my ( undef, $val ) = @_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my %seq_moves = ( map { $_ => 1 } (qw(limited unlimited)) ); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( !exists( $seq_moves{$val} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 0 | die "Unknown sequence move '$val'!"; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $variant_params->sequence_move($val); | |||||||||||||||||||||||||||
| 105 | }, | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | ) or die "Cannot process command line arguments"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my $filename = shift(@$argv); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( !defined($filename) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||
| 112 | 0 | $filename = "-"; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | $self->_variant_params($variant_params); | |||||||||||||||||||||||||||
| 116 | 0 | $self->_filename($filename); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub run | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $filename = $self->_filename(); | |||||||||||||||||||||||||||
| 126 | 0 | my $variant_params = $self->_variant_params(); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $fh; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( $filename eq "-" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||
| 132 | 0 | $fh = *STDIN; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | else | ||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | open $fh, "<", $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | or die "Cannot open '$filename' - $!"; | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $solution = | |||||||||||||||||||||||||||
| 141 | Games::Solitaire::Verify::Solution::ExpandMultiCardMoves->new( | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | input_fh => $fh, | ||||||||||||||||||||||||||||
| 144 | variant => "custom", | ||||||||||||||||||||||||||||
| 145 | variant_params => $variant_params, | ||||||||||||||||||||||||||||
| 146 | output_fh => \*STDOUT, | ||||||||||||||||||||||||||||
| 147 | }, | ||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | my $verdict = $solution->verify(); | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ( !$verdict ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||
| 153 | 0 | exit(0); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | else | ||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | 0 | print STDERR Dumper($verdict); | |||||||||||||||||||||||||||
| 158 | 0 | print STDERR "Solution is Wrong.\n"; | |||||||||||||||||||||||||||
| 159 | 0 | exit(-1); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | 1; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||