Commits

Anonymous committed 4a2653c

Implemented _rotate and tested it.

Comments (0)

Files changed (2)

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

     foreach my $y (0 .. $#lines)
     {
         my $l = $lines[$y];
+
         foreach my $x (0 .. $#$l)
         {
             my $offset = $self->_calc_offset($x, $y);
     return;
 }
 
+sub _rotate
+{
+    my ($self, $s_ref) = @_;
+
+    my $ret = "";
+
+    my $width = $self->width()-1;
+    my $height = $self->height()-1;
+
+    for my $x (0 .. $width)
+    {
+        for my $y (0 .. $height)
+        {
+            vec($ret, $self->_calc_offset($y, $width-$x), 2) =
+                vec($$s_ref, $self->_calc_offset($x,$y), 2);
+        }
+    }
+
+    return \$ret;
+}
+
 =head2 width()
 
 Returns the width of the board.

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

 use strict;
 use warnings;
 
-use Test::More tests => 25;
+use Test::More tests => 26;
 
 use Shlomif::Sokoban::Solver::Board;
 
     $not_reach->(3, 3, "3,3 is not reachable since it's a box");
     # TEST
     $not_reach->(3, 0, "3,0 is not reachable since it's a wall");
+
+    my $rotated = ${$board->_rotate($board->_init_state())};
+    my $init = ${$board->_init_state()};
+
+    # Trim the trailing zeros.
+    foreach ($rotated, $init)
+    {
+        s{\0+\z}{};
+    }
+
+    # TEST
+    is ($rotated, $init, 
+        "Rotation is OK",
+    );
 }
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.