blib/lib/Games/Solitaire/Verify/App/CmdLine/From_Patsolve.pm

filter: Statementstmt 90.0% 45 / 50 Branchbran 72.2% 13 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 86.8% 66 / 76 SCAR 23.3
CC
10
Cov
85%
_perform_move
10.4
_process_main
2.0
BEGIN
1.0
CRAP 10.3
« blib/lib/Games/Solitaire/Verify/Card.pm ↑ Summary Build »
1 package Games::Solitaire::Verify::App::CmdLine::From_Patsolve;
2 2 $Games::Solitaire::Verify::App::CmdLine::From_Patsolve::VERSION = '0.2402';
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 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use parent 'Games::Solitaire::Verify::FromOtherSolversBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 __PACKAGE__->mk_acc_ref(
12 [
13 qw(
14 _st
15 _filename
16 _sol_filename
17 _variant_params
18 _buffer_ref
19 )
20 ]
21 );
22  
23 sub _perform_move
24 {
25 147 ▶ my ( $self, $move_line ) = @_;
Subroutine _perform_move: called CC=9 SCAR=23.4
26  
27 147 ▶ if ( my ($src_card_s) = $move_line =~ /\A(.[HCDS]) to temp\z/ )
Branch: 4 branches
BranchTrueFalseTotal
if (my($src_card_s) = $move_line =~ /\A(.[HCDS]) to temp\z/) { } 31 116 147
elsif (($src_card_s) = $move_line =~ /\A(.[HCDS]) out\z/) { } 54 62 116
elsif (($src_card_s) = $move_line =~ /\A(.[HCDS]) to empty pile\z/) { } 11 51 62
elsif (($src_card_s, my $dest_card_s) = $move_line =~ /\A(.[HCDS]) to (.[HCDS])\z/) { } 51 0 51
28 {
29 31 my $src_col_idx = $self->_find_col_card($src_card_s);
30 31 ▶ if ( not defined($src_col_idx) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $src_col_idx) 0 31 31
31 {
32 0 die "Cannot find card.";
33 }
34  
35 my $dest_fc_idx = first
36 {
37 80 ▶ !defined( $self->_st->get_freecell($_) )
Subroutine __ANON__: called CC=1 SCAR=0.0
38 }
39 31 ( 0 .. $self->_st->num_freecells - 1 );
40  
41 31 ▶ if ( not defined($dest_fc_idx) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dest_fc_idx) 0 31 31
42 {
43 0 die "No empty freecell.";
44 }
45  
46 $self->_perform_and_output_move(
47 31 sprintf(
48 "Move a card from stack %d to freecell %d",
49 $src_col_idx, $dest_fc_idx,
50 ),
51 );
52  
53 }
54 elsif ( ($src_card_s) = $move_line =~ /\A(.[HCDS]) out\z/ )
55 {
56 54 my @src_s = $self->_find_card_src_string($src_card_s);
57 54 $self->_perform_and_output_move(
58 sprintf( "Move a card from %s to the foundations", $src_s[1] ),
59 );
60 }
61 elsif ( ($src_card_s) = $move_line =~ /\A(.[HCDS]) to empty pile\z/ )
62 {
63 11 my $dest_col_idx = $self->_find_empty_col;
64 11 ▶ if ( not defined($dest_col_idx) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dest_col_idx) 0 11 11
65 {
66 0 die "Cannot find empty col.";
67 }
68 11 my @src_s = $self->_find_card_src_string($src_card_s);
69  
70 11 $self->_perform_and_output_move(
71 sprintf( "Move %s from %s to stack %d", @src_s, $dest_col_idx ),
72 );
73 }
74 elsif ( ( $src_card_s, ( my $dest_card_s ) ) =
75 $move_line =~ /\A(.[HCDS]) to (.[HCDS])\z/ )
76 {
77 51 my $dest_col_idx = $self->_find_col_card($dest_card_s);
78 51 ▶ if ( not defined($dest_col_idx) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dest_col_idx) 0 51 51
79 {
80 0 die "Cannot find card <$dest_card_s>.";
81 }
82  
83 51 my @src_s = $self->_find_card_src_string($src_card_s);
84 51 $self->_perform_and_output_move(
85 sprintf( "Move %s from %s to stack %d", @src_s, $dest_col_idx ) );
86 }
87 else
88 {
89 0 die "Unrecognised move_line <$move_line>";
90 }
91 }
92  
93 sub _process_main
94 {
95 1 ▶ my $self = shift;
Subroutine _process_main: called CC=2 SCAR=6.9
96  
97 1 $self->_read_initial_state;
98  
99 1 open my $in_fh, '<', $self->_sol_filename;
100  
101 1 ▶ while ( my $l = <$in_fh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $in_fh)) 128 1 129
102 {
103 128 chomp($l);
104 128 $self->_perform_move($l);
105 }
106  
107 1 close($in_fh);
108  
109 1 $self->_append("This game is solveable.\n");
110  
111 1 return;
112 }
113  
114 2 1;
115  
116 __END__
« blib/lib/Games/Solitaire/Verify/Card.pm ↑ Summary Build »