Commits

Shlomi Fish committed 8bcc129

Convert _error to accept ::Coord objects.

Comments (0)

Files changed (1)

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Board.pm

 
 use Games::ABC_Path::Solver::Coord;
 
+use Scalar::Util qw(blessed);
+
 my $ABCP_VERDICT_NO = 0;
 my $ABCP_VERDICT_MAYBE = 1;
 my $ABCP_VERDICT_YES = 2;
 
                 if ($existing_verdict == $ABCP_VERDICT_YES)
                 {
-                    $self->_error(['mismatched_verdict', $xy->x, $xy->y]);
+                    $self->_error(['mismatched_verdict', $xy]);
                     return;
                 }
 
 
         if (! @$letters_aref)
         {
-            $self->_error(['cell', [$xy->x, $xy->y]]);
+            $self->_error(['cell', $xy]);
             return;
         }
         elsif (@$letters_aref == 1)
 {
     my ($self) = @_;
 
+    my $error = $self->_solve_wrapper;
+
+    return [map {
+        my $obj = $_;
+        (blessed($obj) && $obj->isa('Games::ABC_Path::Solver::Coord'))
+            ? ($obj->x, $obj->y)
+            : ($obj)
+        } @$error];
+}
+
+sub _solve_wrapper
+{
+    my ($self) = @_;
+
     $self->_neighbourhood_and_individuality_inferring;
 
     if ($self->_error)
 
         if (! @$letters_aref)
         {
-            $self->_error(['cell', [$xy->x, $xy->y]]);
+            $self->_error(['cell', $xy]);
         }
         elsif (@$letters_aref > 1)
         {
                 $letter, Games::ABC_Path::Solver::Coord->new({x => $x, y => $y}),
             );
 
-            $recurse_solver->solve;
+            $recurse_solver->_solve_wrapper;
 
             foreach my $move (@{ $recurse_solver->get_moves })
             {