Commits

Anonymous committed cb1ba70

More conversion to ::Coords.

Comments (0)

Files changed (5)

nurikabe-solver/Games-Nurikabe-Solver/examples/gui.pl

     foreach my $island (@{$self->{board}->_islands()})
     {
         my $cell = $island->known_cells->[0];
-        $self->{numbers}->{join(",", @$cell)} = $island->order();
+        $self->{numbers}->{$cell->to_s()} = $island->order();
     }
 }
 

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

                     Games::Nurikabe::Solver::Island->new(
                         {
                             idx => $index,
-                            known_cells => [[$y,$x]],
+                            known_cells => [
+                                Games::Nurikabe::Solver::Coords->new(
+                                    { y => $y, x => $x}
+                                )
+                            ],
                             order => $num_cells,
                         },
                     );
 
             foreach my $coords (@$black_cells)
             {
-                $self->_mark_as_black($coords);
+                $self->_mark_as_black($coords->_to_pair);
             }
             
             $self->_add_move(
 
         foreach my $coords (@$non_traverse)
         {
-            $self->get_cell(
-                Games::Nurikabe::Solver::Coords->new({y => $coords->[0], x => $coords->[1]}))->island_in_proximity($island->idx());
+            $self->get_cell($coords)->island_in_proximity($island->idx());
         }
     }
 
 
         foreach my $coords (@$non_traverse)
         {
-            $self->get_cell(
-                Games::Nurikabe::Solver::Coords->new({ y => $coords->[0], x => $coords->[1]}))->island_in_proximity($island->idx());
+            $self->get_cell($coords)->island_in_proximity($island->idx());
         }
     }
 

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

 
     return
     [
-        sort { ($a->[0] <=> $b->[0]) || ($a->[1] <=> $b->[1]) }
+        sort { ($a->y <=> $b->y) || ($a->x <=> $b->x) }
         @$coords
     ];
 }
 
 =head1 FUNCTIONS
 
-=head2 $island = Games::Nurikabe::Solver::Island->new( {idx => $index, known_cells => [[0,0],[0,1]] })
+=head2 $island = Games::Nurikabe::Solver::Island->new( {idx => $index, known_cells => [@coords] })
 
 Initialises a new island.
 
     my $board = $args->{'board'};
 
     my %exclude_coords =
-        (map { join(",", @$_) => 1, }
+        (map { $_->to_s() => 1, }
             @{$self->known_cells()},
         );
 
     my @ret;
-    foreach my $cell_pair (@{$self->known_cells()})
+    foreach my $cell_coords (@{$self->known_cells()})
     {
-        my $cell_coords = Games::Nurikabe::Solver::Coords->new(
-            {
-                y => $cell_pair->[0], x => $cell_pair->[1]
-            }
-        );
-
         $board->_vicinity_loop(
             $cell_coords,
             sub {
 
                 if (!exists($exclude_coords{$s}))
                 {
-                    push @ret, $to_check->_to_pair(); 
+                    push @ret, $to_check; 
                     # Make sure we don't repeat ourselves
                     $exclude_coords{$s} = 1;
                 }
 {
     my $island = shift;
 
-    $island->_queue([map { [0,$_] } @{$island->known_cells()}]);
+    $island->_queue([map { [0,$_->_to_pair()] } @{$island->known_cells()}]);
 
     return;
 }
 
     foreach my $coord (@$new_cells)
     {
-        push @{$self->known_cells()}, [@$coord];
+        push @{$self->known_cells()}, 
+            Games::Nurikabe::Solver::Coords->new(
+                {
+                y => $coord->[0], x => $coord->[1]
+                }
+            );
         $board->_mark_as_white($coord, $self->idx);
     }
 

nurikabe-solver/Games-Nurikabe-Solver/t/island-surround.t

             {
                 idx => 0,
                 order => scalar(@$white_cells),
-                known_cells => $white_cells,
+                known_cells =>
+                [ 
+                    map 
+                    { 
+                        Games::Nurikabe::Solver::Coords->new(
+                            { y => $_->[0], x => $_->[1] }
+                        )
+                    }
+                    @$white_cells
+                ],
             }
         );
 
         );
 
     return eq_or_diff(
-        $got_surrounded_cells,
+        [map { $_->_to_pair() } @{$got_surrounded_cells}],
         $bi->positions("B"),
         $blurb
     );

nurikabe-solver/Games-Nurikabe-Solver/t/load-from-string.t

 use Games::Nurikabe::Solver::Constants qw($NK_UNKNOWN $NK_WHITE $NK_BLACK);
 use Games::Nurikabe::Solver::Board;
 
+sub _island_cells_dump
+{
+    my $island = shift;
+
+    return [map { [$_->y,$_->x] } @{$island->known_cells()}];
+}
+
 {
     my $string_representation = <<"EOF";
 Width=5 Height=5
 
     # TEST
     eq_or_diff (
-        $board->get_island(0)->known_cells(),
+        _island_cells_dump($board->get_island(0)),
         [[0,3]], 
         "known_cells of island 0",
     );
 
     # TEST
     eq_or_diff (
-        $board->get_island(2)->known_cells(),
+        _island_cells_dump($board->get_island(2)),
         [[3,3]], 
         "known_cells of island 2",
     );