Commits

Anonymous committed 044b40e

Implemented the is_dest.

Comments (0)

Files changed (2)

modules/Shlomif-Sokoban-Solver/lib/Shlomif/Sokoban/Solver/Board.pm

     height
     width
     _data
+    _dests
 /;
 
-my $wall_bits = 2;
-my $dest_place_bits = 2;
+my $dest_place_bits = 0x1;
+my $wall_bits = 0x2;
 
 =head1 METHODS
 
             height => scalar(@lines),
             width => max(map { scalar(@$_) } @lines),
             _data => \$data,
+            _dests => [],
         );
 
     foreach my $y (0 .. $#lines)
             {
                 vec(${$self->_data()}, $offset, 2) = $wall_bits;
             }
+            elsif ($l->[$x] eq ".")
+            {
+                vec(${$self->_data()}, $offset, 2) = $dest_place_bits;
+                push @{$self->_dests()}, [$x, $y];
+            }
             else
             {
                 vec(${$self->_data()}, $offset, 2) = 0;
     return (vec(${$self->_data()}, $y*$self->width()+$x, 2) == $wall_bits);
 }
 
+=head2 $board->is_dest($x,$y)
+
+Returns if the block at the position $x,$y is a destination block.
+
+=cut
+
+sub is_dest
+{
+    my ($self, $x, $y) = @_;
+
+    return (vec(${$self->_data()}, $y*$self->width()+$x, 2) 
+            == $dest_place_bits
+        );
+}
+
+
 =head2 width()
 
 Returns the width of the board.

modules/Shlomif-Sokoban-Solver/t/01-loading.t

 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 
 use Shlomif::Sokoban::Solver::Board;
 
     ok ($board->is_wall(7, 5), "7,5 is a wall");
     # TEST
     ok (!$board->is_wall(4, 7), "4,7 is not a wall");
+    # TEST
+    ok ($board->is_dest(4, 3), "4,7 is a dest");
+    # TEST
+    ok (!$board->is_wall(4, 3), "4,3 (which is a dest) is not a wall");
 }
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.