1. Shlomi Fish
  2. nurikabe

Commits

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

Refactoring: now Board->_add_move checks for full verdict marked cells.

  • Participants
  • Parent commits bf83a4d
  • Branches default

Comments (0)

Files changed (1)

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

View file
  • Ignore whitespace
     return $ret;
 }
 
+sub _exist_verdict_marked_cells
+{
+    my $self = shift;
+
+    return @{$self->_verdict_marked_cells->{$NK_BLACK}} ||
+           @{$self->_verdict_marked_cells->{$NK_WHITE}}
+        ;
+}
+
 sub _flush_moves
 {
     my $self = shift;
     my $self = shift;
     my $args = shift;
 
-    push @{$self->_moves()},
-        Games::Nurikabe::Solver::Move->new(
-            {
-                verdict_cells => $self->_flush_verdict_marked_cells(),
-                %$args,
-            },
-        );
+    if ($self->_exist_verdict_marked_cells())
+    {
+        push @{$self->_moves()},
+            Games::Nurikabe::Solver::Move->new(
+                {
+                    verdict_cells => $self->_flush_verdict_marked_cells(),
+                    %$args,
+                },
+            );
+    }
 
     return;
 }
             ];
             $self->_mark_as_black(@$b_coords);
         }
-        if (@{$self->_verdict_marked_cells()->{$NK_BLACK}})
-        {
-            $self->_add_move(
+
+        $self->_add_move(
+            {
+                reason => "adjacent_whites",
+                reason_params =>
                 {
-                    reason => "adjacent_whites",
-                    reason_params =>
-                    {
-                        base_coords => [@$c],
-                        offset => [@$offset],
-                        islands =>
-                        [
-                            $cell->island(),
-                            $other_cell->island(),
-                        ],
-                    },
-                }
-            );
-        }
+                    base_coords => [@$c],
+                    offset => [@$offset],
+                    islands =>
+                    [
+                        $cell->island(),
+                        $other_cell->island(),
+                    ],
+                },
+            }
+        );
     }
 
     return;