| 1 | package Games::ABC_Path::Solver::Board; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | $Games::ABC_Path::Solver::Board::VERSION = '0.6.1'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use parent 'Games::ABC_Path::Solver::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Games::ABC_Path::Solver::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Games::ABC_Path::Solver::Move::LastRemainingCellForLetter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Games::ABC_Path::Solver::Move::LastRemainingLetterForCell; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use Games::ABC_Path::Solver::Move::LettersNotInVicinity; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use Games::ABC_Path::Solver::Move::ResultsInAnError; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Games::ABC_Path::Solver::Move::ResultsInASuccess; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use Games::ABC_Path::Solver::Move::TryingLetterForCell; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Games::ABC_Path::Solver::Coord; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | my $ABCP_VERDICT_NO = 0; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | my $ABCP_VERDICT_MAYBE = 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | my $ABCP_VERDICT_YES = 2; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | my %letters_map = (map { $letters[$_] => $_ } (0 .. $ABCP_MAX_LETTER)); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _get_letter_numeric | ||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 75 | ▶ | my ($self, $letter_ascii) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_letter_numeric: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 75 | my $index = $letters_map{$letter_ascii}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 75 | ▶ | if (!defined ($index)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | confess "Unknown letter '$letter_ascii'"; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 75 | return $index; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | sub _iter_changed { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 584 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iter_changed: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 584 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 296 | $self->{_iter_changed} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 584 | return $self->{_iter_changed}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | sub _moves { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 284 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_moves: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 284 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | $self->{_moves} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 284 | return $self->{_moves}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub _error { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 40164 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 40164 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | $self->{_error} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 40164 | return $self->{_error}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | sub _inc_changed { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 272 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inc_changed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 272 | $self->_iter_changed($self->_iter_changed+1); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 272 | return; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub _flush_changed { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flush_changed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | my $ret = $self->_iter_changed; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 16 | $self->_iter_changed(0); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub _add_move { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 272 | ▶ | my ($self, $move) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_move: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 272 | push @{$self->_moves()}, $move; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 272 | $self->_inc_changed; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 272 | return; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub get_successful_layouts { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_successful_layouts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | return [@{$self->_successful_layouts}]; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | sub _successful_layouts { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_successful_layouts: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 11 | $self->{_successful_layouts} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 18 | return $self->{_successful_layouts}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | sub _layout { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 43705 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_layout: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 43705 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | $self->{_layout} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 43705 | return $self->{_layout}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # The letter indexes. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | sub _l_indexes | ||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 667 | ▶ | return (0 .. $ABCP_MAX_LETTER); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_l_indexes: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub _init | ||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | my $layout_string = $args->{layout}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | if (!defined($layout_string)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | $layout_string = ''; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | $self->_layout(\$layout_string); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | $self->_successful_layouts([]); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | $self->_moves([]); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | $self->_iter_changed(0); | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub _calc_offset | ||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 43692 | ▶ | my ($self, $letter, $xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_offset: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 43692 | ▶ | if (($letter < 0) or ($letter >= 25)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$letter < 0 or $letter >= 25
MC/DC0%0/2
$letter < 0 or $letter >= 25
$letter < 0
$letter >= 25
Truth table33%1/3
A or B
A= $letter < 0B= $letter >= 25
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | confess "Letter $letter out of range."; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 43692 | return $letter * $BOARD_SIZE + $self->_xy_to_int([$xy->y, $xy->x]); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | sub _get_verdict | ||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 37882 | ▶ | my ($self, $letter, $xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_verdict: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | return vec( | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 37882 | ${$self->_layout}, | |||||||||||||||||||||||||||||||||||||||||
| 175 | $self->_calc_offset($letter, $xy,), | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | sub _set_verdict | ||||||||||||||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 5810 | ▶ | my ($self, $letter, $xy, $verdict) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_verdict: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # Temporary - remove later. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 5810 | ▶ | if (@_ != 4) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | confess "_set_verdict has wrong number of args."; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5810 | ▶ | if (not | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$verdict == $ABCP_VERDICT_NO or $verdict == $ABCP_VERDICT_MAYBE or $verdict == $ABCP_VERDICT_YES
$verdict == $ABCP_VERDICT_NO or $verdict == $ABCP_VERDICT_MAYBE
MC/DC0%0/3
$verdict == $ABCP_VERDICT_NO or $verdict == $ABCP_VERDICT_MAYBE or $verdict == $ABCP_VERDICT_YES
$verdict == $ABCP_VERDICT_NO
$verdict == $ABCP_VERDICT_MAYBE
$verdict == $ABCP_VERDICT_YES
Truth table75%3/4
A or B or C
A= $verdict == $ABCP_VERDICT_NOB= $verdict == $ABCP_VERDICT_MAYBEC= $verdict == $ABCP_VERDICT_YES
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | (($verdict == $ABCP_VERDICT_NO) | ||||||||||||||||||||||||||||||||||||||||||
| 192 | || ($verdict == $ABCP_VERDICT_MAYBE) | ||||||||||||||||||||||||||||||||||||||||||
| 193 | || ($verdict == $ABCP_VERDICT_YES)) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | confess "Invalid verdict $verdict ."; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 5810 | vec(${$self->_layout}, $self->_calc_offset($letter, $xy), 2) | |||||||||||||||||||||||||||||||||||||||||
| 200 | = $verdict; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 5810 | return; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | sub _xy_loop | ||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 1338 | ▶ | my ($self, $sub_ref) = (@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xy_loop: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1338 | foreach my $y ($self->_y_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 210 | { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 6690 | ▶ | if ($self->_error()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 6690 | foreach my $x ($self->_x_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 33449 | ▶ | if ($self->_error()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 33448 | $sub_ref->(Games::ABC_Path::Solver::Coord->new({x => $x, y => $y})); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 1337 | return; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | sub _set_verdicts_for_letter_sets | ||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 36 | ▶ | my ($self, $letter_list, $maybe_list) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_verdicts_for_letter_sets: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 36 | my %cell_is_maybe = (map { $_->_to_s() => 1 } @$maybe_list); | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | foreach my $letter_ascii (@$letter_list) | |||||||||||||||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 72 | my $letter = $self->_get_letter_numeric($letter_ascii); | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | $self->_xy_loop( | ||||||||||||||||||||||||||||||||||||||||||
| 239 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 1800 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | $self->_set_verdict($letter, $xy, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 1800 | ▶ | ((exists $cell_is_maybe{$xy->_to_s()}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | ? $ABCP_VERDICT_MAYBE | ||||||||||||||||||||||||||||||||||||||||||
| 245 | : $ABCP_VERDICT_NO | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 72 | ); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 36 | return; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | sub _set_conclusive_verdict_for_letter | ||||||||||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 78 | ▶ | my ($self, $letter, $l_xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_conclusive_verdict_for_letter: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | $self->_xy_loop(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 1950 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1950 | ▶ | $self->_set_verdict($letter, $xy, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | ($l_xy->_equal($xy) | ||||||||||||||||||||||||||||||||||||||||||
| 264 | ? $ABCP_VERDICT_YES | ||||||||||||||||||||||||||||||||||||||||||
| 265 | : $ABCP_VERDICT_NO | ||||||||||||||||||||||||||||||||||||||||||
| 266 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 267 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 78 | ); | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | OTHER_LETTER: | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 78 | foreach my $other_letter ($self->_l_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 1950 | ▶ | if ($other_letter == $letter) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 78 | next OTHER_LETTER; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 1872 | $self->_set_verdict($other_letter, $l_xy, $ABCP_VERDICT_NO); | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 78 | return; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | sub _get_possible_letter_indexes | ||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 573 | ▶ | my ($self, $xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_possible_letter_indexes: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | return | ||||||||||||||||||||||||||||||||||||||||||
| 289 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 573 | grep { $self->_get_verdict($_, $xy) != $ABCP_VERDICT_NO } | |||||||||||||||||||||||||||||||||||||||||
| 291 | $self->_l_indexes() | ||||||||||||||||||||||||||||||||||||||||||
| 292 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | sub get_possible_letters_for_cell | ||||||||||||||||||||||||||||||||||||||||||
| 297 | { | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 75 | ▶ | my ($self, $x, $y) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_possible_letters_for_cell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 75 | return [@letters[@{$self->_get_possible_letter_indexes(Games::ABC_Path::Solver::Coord->new({x => $x, y => $y}))}]]; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | sub _get_possible_letters_string | ||||||||||||||||||||||||||||||||||||||||||
| 304 | { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 75 | ▶ | my ($self, $xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_possible_letters_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 75 | return join(',', @{$self->get_possible_letters_for_cell($xy->x, $xy->y)}); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | sub _infer_letters | ||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_infer_letters: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 16 | foreach my $letter ($self->_l_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 400 | my @true_cells; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | $self->_xy_loop(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 10000 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 10000 | my $ver = $self->_get_verdict($letter, $xy); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 10000 | ▶ | if ( ($ver == $ABCP_VERDICT_YES) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ver == $ABCP_VERDICT_YES or $ver == $ABCP_VERDICT_MAYBE
MC/DC100%2/2
$ver == $ABCP_VERDICT_YES or $ver == $ABCP_VERDICT_MAYBE
$ver == $ABCP_VERDICT_YES
$ver == $ABCP_VERDICT_MAYBE
Truth table100%3/3
A or B
A= $ver == $ABCP_VERDICT_YESB= $ver == $ABCP_VERDICT_MAYBE
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | || ($ver == $ABCP_VERDICT_MAYBE)) | ||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 627 | push @true_cells, $xy; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 400 | }); | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 400 | ▶ | if (! @true_cells) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $self->_error(['letter', $letter]); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | elsif (@true_cells == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 270 | my $xy = $true_cells[0]; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 270 | ▶ | if ($self->_get_verdict($letter, $xy) == | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | $ABCP_VERDICT_MAYBE) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | $self->_set_conclusive_verdict_for_letter($letter, $xy); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 26 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 343 | Games::ABC_Path::Solver::Move::LastRemainingCellForLetter->new( | ||||||||||||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||||||||||||
| 345 | vars => | ||||||||||||||||||||||||||||||||||||||||||
| 346 | { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | letter => $letter, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | coords => $xy, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 400 | my @neighbourhood = (map { [(0) x $LEN] } ($self->_y_indexes)); | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 400 | foreach my $true (@true_cells) | |||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 627 | foreach my $coords | |||||||||||||||||||||||||||||||||||||||||
| 361 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 362 | grep { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 5643 | ▶ | $self->_x_in_range($_->[0]) and $self->_y_in_range($_->[1]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 5643 | map { [$true->x + $_->[0], $true->y + $_->[1]] } | |||||||||||||||||||||||||||||||||||||||||
| 366 | 1881 | map { my $d = $_; map { [$_, $d] } (-1 .. 1) } | |||||||||||||||||||||||||||||||||||||||||
| 367 | (-1 .. 1) | ||||||||||||||||||||||||||||||||||||||||||
| 368 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 4360 | $neighbourhood[$coords->[1]][$coords->[0]] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 400 | ▶ | foreach my $neighbour_letter ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | (($letter > 0) ? ($letter-1) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 376 | (($letter < $ABCP_MAX_LETTER) ? ($letter+1) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | $self->_xy_loop(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 19200 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 19200 | ▶ | if ($neighbourhood[$xy->y][$xy->x]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | { | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 6228 | return; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 12972 | my $existing_verdict = | |||||||||||||||||||||||||||||||||||||||||
| 388 | $self->_get_verdict($neighbour_letter, $xy); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 12972 | ▶ | if ($existing_verdict == $ABCP_VERDICT_YES) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $self->_error(['mismatched_verdict', $xy]); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 12972 | ▶ | if ($existing_verdict == $ABCP_VERDICT_MAYBE) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 188 | $self->_set_verdict($neighbour_letter, $xy, $ABCP_VERDICT_NO); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 188 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 400 | Games::ABC_Path::Solver::Move::LettersNotInVicinity->new( | ||||||||||||||||||||||||||||||||||||||||||
| 401 | { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | vars => | ||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | target => $neighbour_letter, | ||||||||||||||||||||||||||||||||||||||||||
| 405 | coords => $xy, | ||||||||||||||||||||||||||||||||||||||||||
| 406 | source => $letter, | ||||||||||||||||||||||||||||||||||||||||||
| 407 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 768 | }); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | sub _infer_cells | ||||||||||||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_infer_cells: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | $self->_xy_loop(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 398 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 398 | my $letters_aref = $self->_get_possible_letter_indexes($xy); | |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 398 | ▶ | if (! @$letters_aref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | $self->_error(['cell', $xy]); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | elsif (@$letters_aref == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 315 | my $letter = $letters_aref->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 315 | ▶ | if ($self->_get_verdict($letter, $xy) == $ABCP_VERDICT_MAYBE) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 47 | $self->_set_conclusive_verdict_for_letter($letter, $xy); | |||||||||||||||||||||||||||||||||||||||||
| 440 | 47 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 441 | Games::ABC_Path::Solver::Move::LastRemainingLetterForCell->new( | ||||||||||||||||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||||||||||||||||
| 443 | vars => | ||||||||||||||||||||||||||||||||||||||||||
| 444 | { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | coords => $xy, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | letter => $letter, | ||||||||||||||||||||||||||||||||||||||||||
| 447 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | sub _inference_iteration | ||||||||||||||||||||||||||||||||||||||||||
| 460 | { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inference_iteration: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 16 | $self->_infer_letters; | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 16 | $self->_infer_cells; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 16 | return $self->_flush_changed; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | sub _neighbourhood_and_individuality_inferring | ||||||||||||||||||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_neighbourhood_and_individuality_inferring: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | my $num_changed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 5 | ▶ | while (my $iter_changed = $self->_inference_iteration()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 12 | ▶ | if ($self->_error()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | $num_changed += $iter_changed; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 4 | return $num_changed; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | sub _clone | ||||||||||||||||||||||||||||||||||||||||||
| 489 | { | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clone: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | return | ||||||||||||||||||||||||||||||||||||||||||
| 493 | ref($self)->new( | ||||||||||||||||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 5 | layout => ${$self->_layout()}, | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | sub solve | ||||||||||||||||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
solve: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | my $error = $self->_solve_wrapper; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | return [map { | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 3 | my $obj = $_; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 3 | ▶ | (blessed($obj) && $obj->isa('Games::ABC_Path::Solver::Coord')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($obj) and $obj->isa("Games::ABC_Path::Solver::Coord")
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa("Games::ABC_Path::Solver::Coord")
builtin::blessed($obj)
$obj->isa("Games::ABC_Path::Solver::Coord")
Truth table33%1/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Games::ABC_Path::Solver::Coord")
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | ? ($obj->x, $obj->y) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | : ($obj) | ||||||||||||||||||||||||||||||||||||||||||
| 512 | } @$error]; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | sub _solve_wrapper | ||||||||||||||||||||||||||||||||||||||||||
| 516 | { | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_solve_wrapper: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 5 | $self->_neighbourhood_and_individuality_inferring; | |||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 5 | ▶ | if ($self->_error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | { | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | return $self->_error; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | my @min_coords; | |||||||||||||||||||||||||||||||||||||||||
| 527 | my @min_options; | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | $self->_xy_loop(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 100 | ▶ | my ($xy) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 100 | my $letters_aref = $self->_get_possible_letter_indexes($xy); | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 100 | ▶ | if (! @$letters_aref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | { | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $self->_error(['cell', $xy]); | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | elsif (@$letters_aref > 1) | ||||||||||||||||||||||||||||||||||||||||||
| 539 | { | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 4 | ▶ | if ((!@min_coords) or (@$letters_aref < @min_options)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @min_coords or @$letters_aref < @min_options
MC/DC50%1/2
not @min_coords or @$letters_aref < @min_options
not @min_coords
@$letters_aref < @min_options
Truth table66%2/3
not(A) or B
A= not @min_coordsB= @$letters_aref < @min_options
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | { | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | @min_options = @$letters_aref; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | @min_coords = ($xy); | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 100 | return; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 4 | }); | |||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 4 | ▶ | if ($self->_error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | { | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | return $self->_error; | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | ▶ | if (@min_coords) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | { | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | my ($xy) = @min_coords; | |||||||||||||||||||||||||||||||||||||||||
| 558 | # We have at least one multiple rank cell. Let's recurse there: | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | foreach my $letter (@min_options) | |||||||||||||||||||||||||||||||||||||||||
| 560 | { | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | my $recurse_solver = $self->_clone; | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 2 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 564 | Games::ABC_Path::Solver::Move::TryingLetterForCell->new( | ||||||||||||||||||||||||||||||||||||||||||
| 565 | { | ||||||||||||||||||||||||||||||||||||||||||
| 566 | vars => { letter => $letter, coords => $xy, }, | ||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 569 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | $recurse_solver->_set_conclusive_verdict_for_letter( | |||||||||||||||||||||||||||||||||||||||||
| 572 | $letter, $xy | ||||||||||||||||||||||||||||||||||||||||||
| 573 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | $recurse_solver->_solve_wrapper; | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 2 | foreach my $move (@{ $recurse_solver->get_moves }) | |||||||||||||||||||||||||||||||||||||||||
| 578 | { | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 7 | $self->_add_move($move->bump()); | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 2 | ▶ | if ($recurse_solver->_error()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 585 | Games::ABC_Path::Solver::Move::ResultsInAnError->new( | ||||||||||||||||||||||||||||||||||||||||||
| 586 | { | ||||||||||||||||||||||||||||||||||||||||||
| 587 | vars => | ||||||||||||||||||||||||||||||||||||||||||
| 588 | { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | letter => $letter, | ||||||||||||||||||||||||||||||||||||||||||
| 590 | coords => $xy, | ||||||||||||||||||||||||||||||||||||||||||
| 591 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 594 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | else | ||||||||||||||||||||||||||||||||||||||||||
| 597 | { | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | $self->_add_move( | |||||||||||||||||||||||||||||||||||||||||
| 599 | Games::ABC_Path::Solver::Move::ResultsInASuccess->new( | ||||||||||||||||||||||||||||||||||||||||||
| 600 | { | ||||||||||||||||||||||||||||||||||||||||||
| 601 | vars => { letter => $letter, coords => $xy,}, | ||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 604 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | push @{$self->_successful_layouts}, | |||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | @{$recurse_solver->get_successful_layouts()}; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | my $count = @{$self->_successful_layouts()}; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 1 | ▶ | if (! $count) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | { | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | return ['all_options_bad']; | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | elsif ($count == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 616 | { | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | return ['success']; | |||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 619 | else | ||||||||||||||||||||||||||||||||||||||||||
| 620 | { | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | return ['success_multiple']; | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | else | ||||||||||||||||||||||||||||||||||||||||||
| 625 | { | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 3 | $self->_successful_layouts([$self->_clone()]); | |||||||||||||||||||||||||||||||||||||||||
| 627 | 3 | return ['success']; | |||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 7 | my $letter_re_s = join('', map { quotemeta($_) } @letters); | |||||||||||||||||||||||||||||||||||||||||
| 632 | 7 | my $letter_re = qr{[$letter_re_s]}; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 7 | my $letter_and_space_re = qr{[ $letter_re_s]}; | |||||||||||||||||||||||||||||||||||||||||
| 634 | 7 | my $top_bottom_re = qr/^${letter_re}{7}\n/ms; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 7 | my $inner_re = qr/^${letter_re}${letter_and_space_re}{5}${letter_re}\n/ms; | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | sub _assert_letters_appear_once | ||||||||||||||||||||||||||||||||||||||||||
| 638 | { | ||||||||||||||||||||||||||||||||||||||||||
| 639 | 3 | ▶ | my ($self, $layout_string) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_letters_appear_once: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | my %count_letters = (map { $_ => 0 } @letters); | |||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | foreach my $letter ($layout_string =~ m{($letter_re)}g) | |||||||||||||||||||||||||||||||||||||||||
| 643 | { | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 75 | ▶ | if ($count_letters{$letter}++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | { | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | confess "Letter '$letter' encountered twice in the layout."; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | sub _process_major_diagonal | ||||||||||||||||||||||||||||||||||||||||||
| 654 | { | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_major_diagonal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 3 | my @major_diagonal_letters; | |||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | 3 | $args->{top} =~ m{\A($letter_re)}; | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 3 | push @major_diagonal_letters, $1; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 3 | $args->{bottom} =~ m{($letter_re)\z}; | |||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 3 | push @major_diagonal_letters, $1; | |||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | $self->_set_verdicts_for_letter_sets( | ||||||||||||||||||||||||||||||||||||||||||
| 668 | \@major_diagonal_letters, | ||||||||||||||||||||||||||||||||||||||||||
| 669 | [map | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 3 | { Games::ABC_Path::Solver::Coord->new({x => $_, y => $_}) } | |||||||||||||||||||||||||||||||||||||||||
| 671 | $self->_y_indexes | ||||||||||||||||||||||||||||||||||||||||||
| 672 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 673 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | sub _process_minor_diagonal | ||||||||||||||||||||||||||||||||||||||||||
| 679 | { | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 3 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_minor_diagonal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 3 | my @minor_diagonal_letters; | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | $args->{top} =~ m{($letter_re)\z}; | |||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | 3 | push @minor_diagonal_letters, $1; | |||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 3 | $args->{bottom} =~ m{\A($letter_re)}; | |||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 3 | push @minor_diagonal_letters, $1; | |||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | $self->_set_verdicts_for_letter_sets( | ||||||||||||||||||||||||||||||||||||||||||
| 693 | \@minor_diagonal_letters, | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 3 | [map { Games::ABC_Path::Solver::Coord->new({x => $_, y => 4-$_}) } ($self->_y_indexes)] | |||||||||||||||||||||||||||||||||||||||||
| 695 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | sub _process_input_columns | ||||||||||||||||||||||||||||||||||||||||||
| 701 | { | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_input_columns: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | 3 | my $top_row = $args->{top}; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 3 | my $bottom_row = $args->{bottom}; | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | foreach my $x ($self->_x_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 708 | { | ||||||||||||||||||||||||||||||||||||||||||
| 709 | $self->_set_verdicts_for_letter_sets( | ||||||||||||||||||||||||||||||||||||||||||
| 710 | [substr($top_row, $x+1, 1), substr($bottom_row, $x+1, 1),], | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 15 | [map { Games::ABC_Path::Solver::Coord->new({x =>$x, y => $_}) } $self->_y_indexes], | |||||||||||||||||||||||||||||||||||||||||
| 712 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | sub _process_input_rows_and_initial_letter_clue | ||||||||||||||||||||||||||||||||||||||||||
| 719 | { | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 3 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_input_rows_and_initial_letter_clue: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | my $rows = $args->{rows}; | |||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 3 | my ($clue_x, $clue_y, $clue_letter); | |||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | 3 | foreach my $y ($self->_y_indexes) | |||||||||||||||||||||||||||||||||||||||||
| 727 | { | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 15 | my $row = $rows->[$y]; | |||||||||||||||||||||||||||||||||||||||||
| 729 | $self->_set_verdicts_for_letter_sets( | ||||||||||||||||||||||||||||||||||||||||||
| 730 | [substr($row, 0, 1), substr($row, -1),], | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 15 | [map { Games::ABC_Path::Solver::Coord->new({x => $_,y => $y}) } $self->_x_indexes], | |||||||||||||||||||||||||||||||||||||||||
| 732 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 15 | my $s = substr($row, 1, -1); | |||||||||||||||||||||||||||||||||||||||||
| 735 | 15 | ▶ | if ($s =~ m{($letter_re)}g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 3 | my ($l, $x_plus_1) = ($1, pos($s)); | |||||||||||||||||||||||||||||||||||||||||
| 738 | 3 | ▶ | if (defined($clue_letter)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | { | ||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | confess "Found more than one clue letter in the layout!"; | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 3 | ($clue_x, $clue_y, $clue_letter) = ($x_plus_1-1, $y, $l); | |||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | 3 | ▶ | if (!defined ($clue_letter)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | { | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | confess "Did not find any clue letters inside the layout."; | |||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | $self->_set_conclusive_verdict_for_letter( | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 3 | $self->_get_letter_numeric($clue_letter), | |||||||||||||||||||||||||||||||||||||||||
| 753 | Games::ABC_Path::Solver::Coord->new({x => $clue_x, y => $clue_y}), | ||||||||||||||||||||||||||||||||||||||||||
| 754 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||
| 756 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | sub _input | ||||||||||||||||||||||||||||||||||||||||||
| 760 | { | ||||||||||||||||||||||||||||||||||||||||||
| 761 | 3 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_input: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 3 | ▶ | if ($args->{version} ne 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | die "Can only handle version 1"; | |||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 3 | my $layout_string = $args->{layout}; | |||||||||||||||||||||||||||||||||||||||||
| 769 | 3 | ▶ | if ($layout_string !~ m/\A${top_bottom_re}${inner_re}{5}${top_bottom_re}\z/ms) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | { | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | die "Invalid format. Should be Letter{7}\n(Letter{spaces or one letter}{5}Letter){5}\nLetter{7}"; | |||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 3 | my @rows = split(/\n/, $layout_string); | |||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 3 | my $top_row = shift(@rows); | |||||||||||||||||||||||||||||||||||||||||
| 777 | 3 | my $bottom_row = pop(@rows); | |||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | # Now let's process the layout string and populate the verdicts table. | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 3 | $self->_assert_letters_appear_once($layout_string); | |||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | 3 | my $parse_context = | |||||||||||||||||||||||||||||||||||||||||
| 783 | { top => $top_row, bottom => $bottom_row, rows => \@rows, } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | 3 | $self->_process_major_diagonal($parse_context); | |||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 3 | $self->_process_minor_diagonal($parse_context); | |||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | $self->_process_input_columns($parse_context); | |||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 3 | $self->_process_input_rows_and_initial_letter_clue($parse_context); | |||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | sub _get_results_text_table | ||||||||||||||||||||||||||||||||||||||||||
| 799 | { | ||||||||||||||||||||||||||||||||||||||||||
| 800 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_results_text_table: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | my $render_row = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 803 | 18 | ▶ | my $cols = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | return | ||||||||||||||||||||||||||||||||||||||||||
| 806 | "| " . | ||||||||||||||||||||||||||||||||||||||||||
| 807 | join( | ||||||||||||||||||||||||||||||||||||||||||
| 808 | " | ", | ||||||||||||||||||||||||||||||||||||||||||
| 809 | 18 | ▶ | map { length($_) == 1 ? " $_ " : $_ } @$cols | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | ) . " |\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | return join('', | ||||||||||||||||||||||||||||||||||||||||||
| 814 | 18 | map { $render_row->($_) } | |||||||||||||||||||||||||||||||||||||||||
| 815 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 816 | 15 | [map { sprintf("X = %d", $_+1) } $self->_x_indexes ], | |||||||||||||||||||||||||||||||||||||||||
| 817 | 3 | map { my $y = $_; | |||||||||||||||||||||||||||||||||||||||||
| 818 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 819 | map | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 15 | { $self->_get_possible_letters_string(Games::ABC_Path::Solver::Coord->new({x => $_, y => $y})) } | |||||||||||||||||||||||||||||||||||||||||
| 821 | $self->_x_indexes | ||||||||||||||||||||||||||||||||||||||||||
| 822 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||
| 824 | $self->_y_indexes | ||||||||||||||||||||||||||||||||||||||||||
| 825 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 826 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | sub get_successes_text_tables | ||||||||||||||||||||||||||||||||||||||||||
| 831 | { | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_successes_text_tables: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | 3 | return [map { $_->_get_results_text_table() } @{$self->get_successful_layouts()}]; | |||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | sub input_from_file | ||||||||||||||||||||||||||||||||||||||||||
| 839 | { | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 2 | ▶ | my ($class, $board_fn) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_from_file: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 2 | ▶ | open my $in_fh, "<", $board_fn | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | or die "Cannot open '$board_fn' - $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 2 | my $first_line = <$in_fh>; | |||||||||||||||||||||||||||||||||||||||||
| 846 | 2 | chomp($first_line); | |||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | 2 | my $magic = 'ABC Path Solver Layout Version 1:'; | |||||||||||||||||||||||||||||||||||||||||
| 849 | 2 | ▶ | if ($first_line !~ m{\A\Q$magic\E\s*\z}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | { | ||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | die "Can only process files whose first line is '$magic'!"; | |||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | 2 | my $layout_string = ''; | |||||||||||||||||||||||||||||||||||||||||
| 855 | 2 | foreach my $line_idx (1 .. 7) | |||||||||||||||||||||||||||||||||||||||||
| 856 | { | ||||||||||||||||||||||||||||||||||||||||||
| 857 | 14 | chomp(my $line = <$in_fh>); | |||||||||||||||||||||||||||||||||||||||||
| 858 | 14 | $layout_string .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||
| 860 | 2 | close($in_fh); | |||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 2 | return $class->input_from_v1_string($layout_string); | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | sub input_from_v1_string | ||||||||||||||||||||||||||||||||||||||||||
| 867 | { | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 3 | ▶ | my ($class, $layout_string) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_from_v1_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 3 | my $self = $class->new; | |||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | 3 | $self->_input({ layout => $layout_string, version => 1}); | |||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | sub get_moves | ||||||||||||||||||||||||||||||||||||||||||
| 879 | { | ||||||||||||||||||||||||||||||||||||||||||
| 880 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_moves: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | 4 | return [@{ $self->_moves }]; | |||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||
| 886 | 7 | 1; # End of Games::ABC_Path::Solver::Board | |||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | __END__ | ||||||||||||||||||||||||||||||||||||||||||