Commits

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

Refactoring: extracted the ::Cell->not_same_island() method.

  • Participants
  • Parent commits a75d3ce

Comments (0)

Files changed (2)

File nurikabe-solver/Games-Nurikabe-Solver/lib/Games/Nurikabe/Solver/Board.pm

 
     my $other_cell = $self->get_cell(@$other_coords);
     
-    if (   $other_cell->belongs_to_island()
-        && ($other_cell->island() != $cell->island()))
+    if ($other_cell->not_same_island($cell))
     {
         # Bingo.
         foreach my $b_off (@$blacks_offsets)

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

 
 our @EXPORT_OK = (qw($NK_BLACK $NK_WHITE $NK_UNKNOWN));
 
-=head2 $self->belongs_to_island()
+=head2 my $bool = $self->belongs_to_island()
 
 Returns true if the cell is white and belongs to an island (i.e: it isn't
 marked as white but its island is not yet known).
     return ( ($self->status() eq $NK_WHITE) && defined($self->island()) );
 }
 
+=head2 my $bool = $cell->not_same_island($other_cell);
+
+Sees if the two cells belong to different islands.
+
+=cut
+
+sub not_same_island
+{
+    my $self = shift;
+    my $other = shift;
+
+    return 
+    (
+           $self->belongs_to_island() 
+        && ($self->island() != $other->island())
+    );
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, C<< <shlomif at cpan.org> >>