Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed db04ff9

Refactoring - extract the _calc_offset method.

  • Participants
  • Parent commits e426bb2

Comments (0)

Files changed (1)

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

     return;
 }
 
-sub xy_to_idx
+sub _xy_to_idx
 {
     my ($self, $x, $y) = @_;
 
     }
 
 
-    return $y*5+$x;
+    return $y * $BOARD_LEN +$x;
 }
 
-sub get_verdict
+sub _calc_offset
 {
     my ($solver, $letter, $x, $y) = @_;
 
         confess "Letter $letter out of range.";
     }
 
-    return vec(${$solver->_layout}, 
-        $letter * 25 + $solver->xy_to_idx($x,$y), 2
-    );
+    return $letter * ($BOARD_LEN * $BOARD_LEN) + $solver->_xy_to_idx($x,$y);
+}
+
+sub get_verdict
+{
+    my ($solver, $letter, $x, $y) = @_;
+
+    return vec(${$solver->_layout}, $solver->_calc_offset($letter, $x, $y), 2);
 }
 
 sub set_verdict
 {
     my ($solver, $letter, $x, $y, $verdict) = @_;
 
-    if (($letter < 0) or ($letter >= 25))
-    {
-        confess "Letter $letter out of range.";
-    }
-
     if (not
         (($verdict == $ABCP_VERDICT_NO)
         || ($verdict == $ABCP_VERDICT_MAYBE)
         confess "Invalid verdict $verdict .";
     }
 
-    vec(${$solver->_layout}, $letter * 25 + $solver->xy_to_idx($x,$y), 2)
+    vec(${$solver->_layout}, $solver->_calc_offset($letter,$x,$y), 2)
         = $verdict;
 
     return;