Commits

Anonymous committed 757e0a2

Extracted the _add_move() method to implement the moves

  • Participants
  • Parent commits ff706b0

Comments (0)

Files changed (1)

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

     _cells
     _height
     _islands
+    _moves
     _verdict_marked_cells
     _width
     ));
     return $ret;
 }
 
+sub _flush_moves
+{
+    my $self = shift;
+
+    my $ret = $self->_moves();
+
+    $self->_moves([]);
+
+    return $ret;
+}
+
 sub new
 {
     my $class = shift;
 
     $self->_clear_verdict_marked_cells();
 
+    $self->_moves([]);
+
     return $self;
 }
 
     ];
 }
 
+sub _add_move
+{
+    my $self = shift;
+    my $args = shift;
+
+    push @{$self->_moves()},
+        Games::Nurikabe::Solver::Move->new(
+            {
+                verdict_cells => $self->_flush_verdict_marked_cells(),
+                %$args,
+            },
+        );
+
+    return;
+}
+
+
 sub _actual_mark
 {
     my ($self, $y, $x, $verdict) = @_;
 {
     my $self = shift;
 
-    my @moves;
-
     foreach my $island (@{$self->_islands()})
     {
         if ($island->order() == @{$island->known_cells()})
                 $self->_mark_as_black(@$coords);
             }
             
-            push @moves,
-                Games::Nurikabe::Solver::Move->new(
-                    {
-                        reason => "surround_island_when_full",
-                        verdict_cells => $self->_flush_verdict_marked_cells(),
-                        reason_params => { island => $island->idx(), },
-                    }
-                );
+            $self->_add_move(
+                {
+                    reason => "surround_island_when_full",
+                    reason_params => { island => $island->idx(), },
+                }
+            );
         }
     }
 
-    return \@moves;
+    return $self->_flush_moves();
 }
 
 sub _calc_vicinity