| 1 | package Games::Solitaire::Verify::App::CmdLine::From_Patsolve; | ||||||||||||||||||||||
| 2 | 2 | $Games::Solitaire::Verify::App::CmdLine::From_Patsolve::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 | 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 | 147 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_perform_move: called CC=9 SCAR=23.4
| |||||||||||||||||||||||
| 25 | 147 | my ( $self, $move_line ) = @_; | |||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 147 | ▶ | if ( my ($src_card_s) = $move_line =~ /\A(.[HCDS]) to temp\z/ ) | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||
| 32 | 0 | die "Cannot find card."; | |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | 80 | ▶ | my $dest_fc_idx = first { !defined( $self->_st->get_freecell($_) ) } | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 36 | 31 | ( 0 .. $self->_st->num_freecells - 1 ); | |||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | 31 | ▶ | if ( not defined($dest_fc_idx) ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||
| 40 | 0 | die "No empty freecell."; | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | $self->_perform_and_output_move( | ||||||||||||||||||||||
| 44 | 31 | sprintf( | |||||||||||||||||||||
| 45 | "Move a card from stack %d to freecell %d", | ||||||||||||||||||||||
| 46 | $src_col_idx, $dest_fc_idx, | ||||||||||||||||||||||
| 47 | ), | ||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | elsif ( ($src_card_s) = $move_line =~ /\A(.[HCDS]) out\z/ ) | ||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||
| 53 | 54 | my @src_s = $self->_find_card_src_string($src_card_s); | |||||||||||||||||||||
| 54 | 54 | $self->_perform_and_output_move( | |||||||||||||||||||||
| 55 | sprintf( "Move a card from %s to the foundations", $src_s[1] ), ); | ||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | elsif ( ($src_card_s) = $move_line =~ /\A(.[HCDS]) to empty pile\z/ ) | ||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||
| 59 | 11 | my $dest_col_idx = $self->_find_empty_col; | |||||||||||||||||||||
| 60 | 11 | ▶ | if ( not defined($dest_col_idx) ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||
| 62 | 0 | die "Cannot find empty col."; | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | 11 | my @src_s = $self->_find_card_src_string($src_card_s); | |||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | 11 | $self->_perform_and_output_move( | |||||||||||||||||||||
| 67 | sprintf( "Move %s from %s to stack %d", @src_s, $dest_col_idx ), ); | ||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | elsif ( ( $src_card_s, ( my $dest_card_s ) ) = | ||||||||||||||||||||||
| 70 | $move_line =~ /\A(.[HCDS]) to (.[HCDS])\z/ ) | ||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||
| 72 | 51 | my $dest_col_idx = $self->_find_col_card($dest_card_s); | |||||||||||||||||||||
| 73 | 51 | ▶ | if ( not defined($dest_col_idx) ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||
| 75 | 0 | die "Cannot find card <$dest_card_s>."; | |||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | 51 | my @src_s = $self->_find_card_src_string($src_card_s); | |||||||||||||||||||||
| 79 | 51 | $self->_perform_and_output_move( | |||||||||||||||||||||
| 80 | sprintf( "Move %s from %s to stack %d", @src_s, $dest_col_idx ) ); | ||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | else | ||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||
| 84 | 0 | die "Unrecognised move_line <$move_line>"; | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | sub _process_main | ||||||||||||||||||||||
| 89 | 1 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_process_main: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 90 | 1 | my $self = shift; | |||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 1 | $self->_read_initial_state; | |||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 1 | open my $in_fh, '<', $self->_sol_filename; | |||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 1 | ▶ | while ( my $l = <$in_fh> ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||
| 98 | 128 | chomp($l); | |||||||||||||||||||||
| 99 | 128 | $self->_perform_move($l); | |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | 1 | close($in_fh); | |||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | 1 | $self->_append("This game is solveable.\n"); | |||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | 1 | return; | |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||