Anonymous avatar Anonymous committed c4bb5cd

Start converting to Games/Nurikabe/Solver/Coords.pm .

This is a coordinates object instead of the current [$y,$x] array ref.

Comments (0)

Files changed (6)

nurikabe-solver/Games-Nurikabe-Solver/MANIFEST

 lib/Games/Nurikabe/Solver/Board.pm
 lib/Games/Nurikabe/Solver/Cell.pm
 lib/Games/Nurikabe/Solver/Constants.pm
+lib/Games/Nurikabe/Solver/Coords.pm
 lib/Games/Nurikabe/Solver/Island.pm
 lib/Games/Nurikabe/Solver/Move.pm
 lib/Games/Nurikabe/Solver.pm

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

     {
         for my $x (0 .. $board->_width()-1)
         {
-            my $status = $board->get_cell([$y,$x])->status();
+            my $status = $board->get_cell(
+                Games::Nurikabe::Solver::Coords->new({y =>$y, x => $x})
+            )->status();
 
             if ($status eq $NK_UNKNOWN)
             {

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

 {
     my ($board, $coords, $callback) = @_;
 
-    my $cell = $board->get_cell($coords);
+    my $cell = $board->get_cell(
+        Games::Nurikabe::Solver::Coords->new(
+            { y => $coords->[0], x => $coords->[1]}
+        )
+    );
 
     foreach my $off_coords (
         grep { $board->_is_in_bounds($_) }
     return $self;
 }
 
-=head2 $self->get_cell( [$y,$x] )
+=head2 $self->get_cell( $coords )
 
-Returns the cell in position ($y, $x). It is a
+Returns the cell in position of $coords where $coords is a
+L<Games::Nurikabe::Solver::Coords> object. It is a
 L<Games::Nurikabe::Solver::Cell> object.
 
 =cut
     my $self = shift;
     my $c = shift;
 
-    return $self->_cells()->[$c->[0]]->[$c->[1]];
+    return $self->_cells()->[$c->y]->[$c->x];
 }
 
 =head2 $self->get_island($idx)
 {
     my ($self, $coords, $verdict) = @_;
 
-    $self->get_cell($coords)->status($verdict);
+    $self->get_cell(
+        Games::Nurikabe::Solver::Coords->new(
+            {
+                y => $coords->[0],
+                x => $coords->[1],
+            }
+        )
+    )->status($verdict);
 
     push @{$self->_verdict_marked_cells()->{$verdict}},
         $coords
 {
     my ($self, $c) = @_;
 
-    my $cell = $self->get_cell($c);
+    my $cell = $self->get_cell(
+        Games::Nurikabe::Solver::Coords->new
+        (
+            { y => $c->[0], x => $c->[1] }
+        )
+    );
 
     if ($cell->status() eq $NK_WHITE)
     {
 {
     my ($self, $c, $idx) = @_;
 
-    my $cell = $self->get_cell($c);
+    my $cell = $self->get_cell(
+        Games::Nurikabe::Solver::Coords->new(
+            {
+                y => $c->[0],
+                x => $c->[1],
+            }
+        ),
+    );
 
     if ($cell->status() eq $NK_BLACK)
     {
                 return;
             }
 
-            if (all { $self->get_cell($_)->status() eq $NK_BLACK }
+            if (all { $self->get_cell(Games::Nurikabe::Solver::Coords->new({y => $_->[1], x => $_->[0] } ))->status() eq $NK_BLACK }
                 (@{$self->_calc_vicinity($coords)})
             )
             {
         return;
     }
 
-    my $other_cell = $self->get_cell($other_coords);
+    my $other_cell = $self->get_cell(Games::Nurikabe::Solver::Coords->new({y => $other_coords->[0], x => $other_coords->[1]}));
     
     if ($other_cell->not_same_island($cell))
     {
 
         foreach my $coords (@$non_traverse)
         {
-            $self->get_cell($coords)->island_in_proximity($island->idx());
+            $self->get_cell(
+                Games::Nurikabe::Solver::Coords->new({y => $coords->[0], x => $coords->[1]}))->island_in_proximity($island->idx());
         }
     }
 
 
         foreach my $coords (@$non_traverse)
         {
-            $self->get_cell($coords)->island_in_proximity($island->idx());
+            $self->get_cell(
+                Games::Nurikabe::Solver::Coords->new({ y => $coords->[0], x => $coords->[1]}))->island_in_proximity($island->idx());
         }
     }
 
                 QUEUE_LOOP:
                 while (my $coords = shift(@queue))
                 {
-                    my $q_c = $self->get_cell($coords);
+                    my $q_c = $self->get_cell(
+                        Games::Nurikabe::Solver::Coords->new({y => $coords->[0], x => $coords->[1]}));
                     if ($q_c->already_processed)
                     {
                         next QUEUE_LOOP;
                         sub {
                             my $to_check = shift;
 
-                            my $c = $self->get_cell($to_check);
+                            my $c = $self->get_cell(
+                                Games::Nurikabe::Solver::Coords->new({ y => $to_check->[0], x => $to_check->[1]}));
 
                             if ($c->status() eq $NK_BLACK)
                             {

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

+package Games::Nurikabe::Solver::Coords;
+
+use strict;
+use warnings;
+
+use base 'Games::Nurikabe::Solver::Base';
+
+__PACKAGE__->mk_accessors(qw(
+    x
+    y
+    ));
+
+=head1 NAME
+
+Games::Nurikabe::Solver::Coords - an object representing a coordinates pair
+in the Nurikabe board.
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '0.01';
+
+=head1 SYNOPSIS
+
+    use Games::Nurikabe::Solver::Coords;
+
+    my $coords = Games::Nurikabe::Solver::Coords->new({x => $x, y => $y);
+
+    print "X = ", $coords->x();
+    print "Y = ", $coords->y();
+
+=head1 METHODS
+
+=head2 ->new({y => $y, x => $x})
+
+Creates a new object with $y and $x as coordinates.
+
+=cut
+
+sub _init
+{
+    my ($self, $args) = @_;
+
+    $self->y($args->{'y'});
+    $self->x($args->{'x'});
+
+    return;
+}
+
+=head2 x()
+
+Returns the column (or "x") coordinate.
+
+=head2 y()
+
+Returns the row (or "y") coordinate.
+
+=cut
+
+1;
+
+=head1 AUTHOR
+
+Shlomi Fish, C<< <shlomif at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-games-nurikabe-solver at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Nurikabe-Solver>.  I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc Games::Nurikabe::Solver::Coords
+
+You can also look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Nurikabe-Solver>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Games-Nurikabe-Solver>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Games-Nurikabe-Solver>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Games-Nurikabe-Solver>
+
+=item * Version control repository:
+
+L<http://svn.berlios.de/svnroot/repos/fc-solve/nurikabe-solver/trunk/>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2008 Shlomi Fish, all rights reserved.
+
+This program is released under the following license: MIT/X11 Licence. 
+
+=cut
+
+1; # End of Games::Nurikabe::Solver::Coords

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

 
 use base 'Games::Nurikabe::Solver::Base';
 
+use Games::Nurikabe::Solver::Coords;
 use Games::Nurikabe::Solver::Cell;
 use Games::Nurikabe::Solver::Constants qw($NK_UNKNOWN $NK_WHITE $NK_BLACK);
 
         sub {
             my $to_check = shift;
 
-            my $cell = $board->get_cell($to_check);
+            my $cell = $board->get_cell(
+                Games::Nurikabe::Solver::Coords->new(
+                    {
+                        y => $to_check->[0],
+                        x => $to_check->[1],
+                    }
+                )
+            );
 
             if (! $cell->can_be_marked_by_island($island))
             {

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

             $string_representation
         );
 
+    my $get_cell = sub {
+        my $xy = shift;
+        return $board->get_cell(
+            Games::Nurikabe::Solver::Coords->new($xy)
+        );
+    };
+
     # TEST
-    is ($board->get_cell([0,0])->status(),
+    is ($get_cell->({y => 0, x => 0})->status(),
         $NK_UNKNOWN,
         "Checking Status of Cell (0,0)",
     );
 
     # TEST
-    is ($board->get_cell([0,2])->status(),
+    is ($get_cell->({ y => 0, x => 2})->status(),
         $NK_UNKNOWN,
         "Checking Status of Cell (0,2)",
     );
 
     # TEST
-    is ($board->get_cell([0,3])->status(),
+    is ($get_cell->({ y => 0, x => 3})->status(),
         $NK_WHITE,
         "Status of Cell (0,3) - White"
     );
 
     # TEST
-    is ($board->get_cell([0,3])->island(),
+    is ($get_cell->({ y => 0, x => 3})->island(),
         0,
         "Island of Cell (0,4) - 0"
     );
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.