| 1 | package Games::Solitaire::Verify::HorneAutomovePrune; | ||||||||||||||
| 2 | 2 | $Games::Solitaire::Verify::HorneAutomovePrune::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 | sub _calc_foundation_to_put_card_on | ||||||||||||||
| 7 | 16 | ▶ | { | ||||||||||||
|
Subroutine
_calc_foundation_to_put_card_on: called CC=6 SCAR=18.1
| |||||||||||||||
| 8 | 16 | my ( $running_state, $card ) = @_; | |||||||||||||
| 9 | |||||||||||||||
| 10 | DECKS_LOOP: | ||||||||||||||
| 11 | 16 | for my $deck ( 0 .. $running_state->num_decks() - 1 ) | |||||||||||||
| 12 | { | ||||||||||||||
| 13 | 16 | ▶ | if ( $running_state->get_foundation_value( $card->suit(), $deck ) == | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | $card->rank() - 1 ) | ||||||||||||||
| 15 | { | ||||||||||||||
| 16 | 1 | for my $other_deck_idx ( | |||||||||||||
| 17 | 0 .. ( ( $running_state->num_decks() << 2 ) - 1 ) ) | ||||||||||||||
| 18 | { | ||||||||||||||
| 19 | 4 | ▶ | if ( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 20 | $running_state->get_foundation_value( | ||||||||||||||
| 21 | $card->get_suits_seq->[ $other_deck_idx % 4 ], | ||||||||||||||
| 22 | ( $other_deck_idx >> 2 ), | ||||||||||||||
| 23 | ) < $card->rank() - 2 - ( | ||||||||||||||
| 24 | ( | ||||||||||||||
| 25 | $card->color_for_suit( | ||||||||||||||
| 26 | $card->get_suits_seq->[ $other_deck_idx % 4 ] | ||||||||||||||
| 27 | ) eq $card->color() | ||||||||||||||
| 28 | ) ? 1 : 0 | ||||||||||||||
| 29 | ) | ||||||||||||||
| 30 | ) | ||||||||||||||
| 31 | { | ||||||||||||||
| 32 | 0 | next DECKS_LOOP; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | } | ||||||||||||||
| 35 | 1 | return [ $card->suit(), $deck ]; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | 15 | return; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | sub perform_and_output_move | ||||||||||||||
| 42 | 1 | ▶ | { | ||||||||||||
|
Subroutine
perform_and_output_move: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 43 | 1 | my ($args) = @_; | |||||||||||||
| 44 | 1 | my $running_state = $args->{state}; | |||||||||||||
| 45 | 1 | my $out_running_state = $args->{output_state}; | |||||||||||||
| 46 | 1 | my $out_move = $args->{output_move}; | |||||||||||||
| 47 | 1 | my $move_s = $args->{move_string}; | |||||||||||||
| 48 | 1 | $out_move->($move_s); | |||||||||||||
| 49 | 1 | $running_state->verify_and_perform_move( | |||||||||||||
| 50 | Games::Solitaire::Verify::Move->new( | ||||||||||||||
| 51 | { | ||||||||||||||
| 52 | fcs_string => $move_s, | ||||||||||||||
| 53 | game => $running_state->_variant(), | ||||||||||||||
| 54 | }, | ||||||||||||||
| 55 | ) | ||||||||||||||
| 56 | ); | ||||||||||||||
| 57 | 1 | $out_running_state->($running_state); | |||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | return; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | sub _check_for_prune_move | ||||||||||||||
| 63 | 24 | ▶ | { | ||||||||||||
|
Subroutine
_check_for_prune_move: called CC=3 SCAR=11.0
| |||||||||||||||
| 64 | 24 | my ( $running_state, $card, $prune_move, $out_running_state, $out_move ) = | |||||||||||||
| 65 | @_; | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 24 | ▶ | if ( defined($card) ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | { | ||||||||||||||
| 69 | 16 | my $f = _calc_foundation_to_put_card_on( $running_state, $card ); | |||||||||||||
| 70 | |||||||||||||||
| 71 | 16 | ▶ | if ( defined($f) ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | { | ||||||||||||||
| 73 | 1 | perform_and_output_move( | |||||||||||||
| 74 | { | ||||||||||||||
| 75 | state => $running_state, | ||||||||||||||
| 76 | move_string => $prune_move, | ||||||||||||||
| 77 | output_state => $out_running_state, | ||||||||||||||
| 78 | output_move => $out_move | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | ); | ||||||||||||||
| 81 | 1 | return 1; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 23 | return 0; | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | sub do_prune | ||||||||||||||
| 89 | 1 | ▶ | { | ||||||||||||
|
Subroutine
do_prune: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||
| 90 | 1 | my ($args) = @_; | |||||||||||||
| 91 | 1 | my $running_state = $args->{state}; | |||||||||||||
| 92 | 1 | my $out_running_state = $args->{output_state}; | |||||||||||||
| 93 | 1 | my $out_move = $args->{output_move}; | |||||||||||||
| 94 | PRUNE: | ||||||||||||||
| 95 | 1 | while (1) | |||||||||||||
| 96 | { | ||||||||||||||
| 97 | 2 | my $num_moved = 0; | |||||||||||||
| 98 | 2 | foreach my $idx ( 0 .. ( $running_state->num_columns() - 1 ) ) | |||||||||||||
| 99 | { | ||||||||||||||
| 100 | 16 | my $col = $running_state->get_column($idx); | |||||||||||||
| 101 | |||||||||||||||
| 102 | 16 | ▶ | $num_moved += _check_for_prune_move( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | $running_state, | ||||||||||||||
| 104 | scalar( $col->len() ? $col->top() : undef() ), | ||||||||||||||
| 105 | "Move a card from stack $idx to the foundations", | ||||||||||||||
| 106 | $out_running_state, | ||||||||||||||
| 107 | $out_move, | ||||||||||||||
| 108 | ); | ||||||||||||||
| 109 | } | ||||||||||||||
| 110 | |||||||||||||||
| 111 | 2 | foreach my $idx ( 0 .. ( $running_state->num_freecells() - 1 ) ) | |||||||||||||
| 112 | { | ||||||||||||||
| 113 | 8 | $num_moved += _check_for_prune_move( | |||||||||||||
| 114 | $running_state, | ||||||||||||||
| 115 | $running_state->get_freecell($idx), | ||||||||||||||
| 116 | "Move a card from freecell $idx to the foundations", | ||||||||||||||
| 117 | $out_running_state, | ||||||||||||||
| 118 | $out_move, | ||||||||||||||
| 119 | ); | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | 2 | ▶ | last PRUNE if $num_moved == 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 122 | } | ||||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 2 | 1; | |||||||||||||
| 126 | |||||||||||||||
| 127 | __END__ | ||||||||||||||