Commits

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

Add more.

  • Participants
  • Parent commits 0213dd9

Comments (0)

Files changed (1)

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

     return $self->{_moves};
 }
 
+sub _error {
+    my $self = shift;
+
+    if (@_) {
+        $self->{_error} = shift;
+    }
+
+    return $self->{_error};
+}
+
+
 sub _inc_changed {
     my ($self) = @_;
 
 
     foreach my $y ($self->_y_indexes)
     {
+        if ($self->_error())
+        {
+            return;
+        }
         foreach my $x ($self->_x_indexes)
         {
+            if ($self->_error())
+            {
+                return;
+            }
             $sub_ref->($x,$y);
         }
     }
             }
         });
 
-        if (@true_cells == 1)
+        if (! @true_cells)
+        {
+            $self->_error(['letter', $letter]);
+            return;
+        }
+        elsif (@true_cells == 1)
         {
             my $xy = $true_cells[0];
             if ($self->get_verdict($letter, @$xy) ==
 
         my $letters_aref = $self->_get_possible_letter_indexes($x, $y);
 
-        if (@$letters_aref == 1)
+        if (! @$letters_aref)
+        {
+            $self->_error(['cell', [$x, $y]]);
+            return;
+        }
+        elsif (@$letters_aref == 1)
         {
             my $letter = $letters_aref->[0];
 
 
     while (my $iter_changed = $self->_inference_iteration())
     {
+        if ($self->_error())
+        {
+            return;
+        }
         $num_changed += $iter_changed;
     }
 
 
     $self->_neighbourhood_and_individuality_inferring;
 
+    if ($self->_error)
+    {
+        return $self->_error;
+    }
+
+    my @min_coords;
+    my @min_options;
+
+    $self->xy_loop(sub {
+        my ($x, $y) = @_;
+
+        my $letters_aref = $self->_get_possible_letter_indexes($x, $y);
+
+        if (! @$letters_aref)
+        {
+            $self->_error(['cell', [$x, $y]]);
+        }
+        elsif (@$letters_aref > 1)
+        {
+            if ((!@min_coords) or (@$letters_aref < @min_options))
+            {
+                @min_options = @$letters_aref;
+                @min_coords = ($x,$y);
+            }
+        }
+
+        return;
+    });
+
+    if ($self->_error)
+    {
+        return $self->_error;
+    }
+
+    if (@min_coords)
+    {
+        # We have at least one multiple rank cell. Let's recurse there:
+    }
+
     return;
 }