| 1 | package Games::Solitaire::BlackHole::Solver::Golf::App; | ||||||||||||||||||||||||||||
| 2 | 2 | $Games::Solitaire::BlackHole::Solver::Golf::App::VERSION = '0.4.1'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | extends('Games::Solitaire::BlackHole::Solver::App::Base'); | |||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Games::Solitaire::BlackHole::Solver::App::Base qw/ $card_re /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub run | ||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=13 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 1 | my $RANK_KING = $self->_RANK_KING; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # A boolean | ||||||||||||||||||||||||||||
| 16 | 1 | my $place_queens_on_kings = ''; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # A boolean | ||||||||||||||||||||||||||||
| 19 | 1 | my $wrap_ranks = ''; | |||||||||||||||||||||||||||
| 20 | 1 | $self->_process_cmd_line( | |||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | extra_flags => { | ||||||||||||||||||||||||||||
| 23 | "queens-on-kings!" => \$place_queens_on_kings, | ||||||||||||||||||||||||||||
| 24 | "wrap-ranks!" => \$wrap_ranks, | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | if ($wrap_ranks) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 0 | $place_queens_on_kings = 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | my $talon_line = shift( @{ $self->_board_lines } ); | |||||||||||||||||||||||||||
| 34 | 1 | my @talon_values; | |||||||||||||||||||||||||||
| 35 | 1 | my $talon_ptr = 0; | |||||||||||||||||||||||||||
| 36 | 1 | ▶ | if ( my ($cards) = $talon_line =~ m{\ATalon:((?: $card_re){16})\z} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 16 | @talon_values = map { $self->_get_rank($_) } | |||||||||||||||||||||||||||
| 39 | 1 | @{ $self->_talon_cards( [ $cards =~ /($card_re)/g ] ) }; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else | ||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | die "Could not match first talon line!"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | $self->_set_up_solver( $talon_ptr, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | [ 1, ( $wrap_ranks ? ($RANK_KING) : () ) ] ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | my $positions = $self->_positions; | |||||||||||||||||||||||||||
| 50 | 1 | my $board_values = $self->_board_values; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | my $verdict = 0; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | $self->_next_task; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | QUEUE_LOOP: | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | while ( my $state = $self->_get_next_state_wrapper ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | # The foundation | ||||||||||||||||||||||||||||
| 60 | 953 | my $fnd = vec( $state, 0, 8 ); | |||||||||||||||||||||||||||
| 61 | 953 | my $no_cards = 1; | |||||||||||||||||||||||||||
| 62 | 953 | my $tln = vec( $state, 1, 8 ); | |||||||||||||||||||||||||||
| 63 | 953 | my @sub_queue; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | my @_pending; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 953 | ▶ | if ( $place_queens_on_kings || ( $fnd != $RANK_KING ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$place_queens_on_kings or $fnd != $RANK_KING
MC/DC0%0/2
$place_queens_on_kings or $fnd != $RANK_KING
$place_queens_on_kings
$fnd != $RANK_KING
Truth table33%1/3
A or B
A= $place_queens_on_kingsB= $fnd != $RANK_KING
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 953 | $self->_find_moves( \@sub_queue, $state, \$no_cards ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | COL: | ||||||||||||||||||||||||||||
| 74 | 0 | foreach my $col_idx ( keys @$board_values ) | |||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 0 | my $pos = vec( $state, 4 + $col_idx, 4 ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($pos) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | $no_cards = 0; | |||||||||||||||||||||||||||
| 81 | 0 | last COL; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 953 | ▶ | if ($no_cards) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 1 | $self->_trace_solution( $state, ); | |||||||||||||||||||||||||||
| 89 | 1 | $verdict = 1; | |||||||||||||||||||||||||||
| 90 | 1 | last QUEUE_LOOP; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 952 | ▶ | if ( $tln < @talon_values ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 833 | my $next_s = $state; | |||||||||||||||||||||||||||
| 96 | 833 | vec( $next_s, 0, 8 ) = $talon_values[$tln]; | |||||||||||||||||||||||||||
| 97 | 833 | ++vec( $next_s, 1, 8 ); | |||||||||||||||||||||||||||
| 98 | 833 | ▶ | if ( !exists( $positions->{$next_s} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 586 | $positions->{$next_s} = | |||||||||||||||||||||||||||
| 101 | [ $state, scalar(@$board_values), 1, 0 ]; | ||||||||||||||||||||||||||||
| 102 | 586 | push @_pending, [ $next_s, 0 ]; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Give preference to non-talon moves | ||||||||||||||||||||||||||||
| 107 | 952 | push @_pending, @sub_queue; | |||||||||||||||||||||||||||
| 108 | last QUEUE_LOOP | ||||||||||||||||||||||||||||
| 109 | 952 | ▶ | if not $self->_process_pending_items( \@_pending, $state ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | return $self->_my_exit( $verdict, ); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||