Commits

Anonymous committed f454fea

Extracted the ::Cell->can_be_marked_by_island() method

  • Participants
  • Parent commits 2142c88

Comments (0)

Files changed (2)

nurikabe-solver/Games-Nurikabe-Solver/lib/Games/Nurikabe/Solver/Cell.pm

     return ([$dist, $c]);
 }
 
+=head2 $self->can_be_marked_by_island($island)
+
+Checks if during the $island BrFS, the cell is available for being
+marked by the island.
+
+=cut
+
+sub can_be_marked_by_island
+{
+    my ($self, $island) = @_;
+
+    if (($self->status() eq $NK_BLACK)
+        || (defined($self->island()) 
+            && $self->island() != $island->idx()
+        )
+    )
+    {
+        return;
+    }
+
+    if (defined($self->island_in_proximity()) &&
+        $self->island_in_proximity() != $island->idx()
+    )
+    {
+        return;
+    }
+
+    return 1;
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, C<< <shlomif at cpan.org> >>

nurikabe-solver/Games-Nurikabe-Solver/lib/Games/Nurikabe/Solver/Island.pm

 
             my $cell = $board->get_cell($to_check);
 
-            if (($cell->status() eq $NK_BLACK)
-                || (defined($cell->island()) 
-                    && $cell->island() != $island->idx()
-                )
-            )
-            {
-                return;
-            }
-
-            if (defined($cell->island_in_proximity()) &&
-                $cell->island_in_proximity() != $island->idx()
-            )
+            if (! $cell->can_be_marked_by_island($island))
             {
                 return;
             }