Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed 25adf0b

Refactoring : add _l_indexes and $ABCP_MAX_LETTER.

  • Participants
  • Parent commits c9d1fec

Comments (0)

Files changed (1)

File abc-path/perl-quick-and-dirty/abc-path-solver.pl

 my $BOARD_LEN = 5;
 my $BOARD_LEN_LIM = $BOARD_LEN - 1;
 
-
 my @letters = (qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y));
 
-my %letters_map = (map { $letters[$_] => $_ } (0 .. $#letters));
+my $ABCP_MAX_LETTER = $#letters;
+
+my %letters_map = (map { $letters[$_] => $_ } (0 .. $ABCP_MAX_LETTER));
 
 sub get_letter_numeric
 {
     return (0 .. $BOARD_LEN_LIM);
 }
 
+# The letter indexes.
+sub _l_indexes
+{
+    return (0 .. $ABCP_MAX_LETTER);
+}
+
 sub _init
 {
     my ($self, $args) = @_;
         }
     );
     OTHER_LETTER:
-    foreach my $other_letter (0 .. $#letters)
+    foreach my $other_letter ($solver->_l_indexes)
     {
         if ($other_letter == $letter)
         {
     return 
     [
         grep { $solver->get_verdict($_, $x, $y) != $ABCP_VERDICT_NO }
-        (0 .. $#letters)
+        $solver->_l_indexes()
     ];
 }
 
 
     my $num_changed = 0;
 
-    foreach my $letter (0 .. $#letters)
+    foreach my $letter ($solver->_l_indexes)
     {
         my @true_cells;
 
 
         foreach my $neighbour_letter (
             (($letter > 0) ? ($letter-1) : ()),
-            (($letter < $#letters) ? ($letter+1) : ()),
+            (($letter < $ABCP_MAX_LETTER) ? ($letter+1) : ()),
         )
         {
             $solver->xy_loop(sub {