Commits

Shlomi Fish committed 5ee20cf

Convert to the methods of Games-ABC_Path-Solver-Base.

Comments (0)

Files changed (4)

abc-path/Games-ABC_Path-Generator/Changes

     - Convert the constants module to Games::ABC_Path::Solver::Constants
     to merge the common parts of Games::ABC_Path::Solver and
     Games::ABC_Path::Generator.
+    - Convert to the methods of Games::ABC_Path::Solver::Base . 
     
 0.0.1       Thu Jul 21 19:02:11 IDT 2011
     - First version, released on an unsuspecting world.

abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator.pm

         [ map {
             my ($y,$x) = ($sy+$_->[$Y], $sx+$_->[$X]);
             (
-                (($x >= 0) && ($x < $LEN) && ($y >= 0) && ($y < $LEN))
+                (__PACKAGE__->_x_in_range($x) && __PACKAGE__->_y_in_range($y))
                 ? (__PACKAGE__->_xy_to_int([$y,$x])) : ()
             )
             }
 =cut
 
 sub _gen_clue_positions {
-    my ($cb) = @_;
-    return [map { $cb->($_) } (0 .. $LEN-1)];
+    my ($self, $cb) = @_;
+    return [map { $cb->($_) } $self->_x_indexes()];
 };
 
-my @_clues_positions =
-(
-    map {
-        [map { __PACKAGE__->_xy_to_int($_) } @{_gen_clue_positions($_)}]
-    }
-    (
-        sub { [$_,$_];   },
-        sub { [$_,4-$_]; },
-        (map { my $y = $_; sub { [$y,$_] }; } (0 .. $LEN-1)),
-        (map { my $x = $_; sub { [$_,$x] }; } (0 .. $LEN-1)),
-    )
-);
+sub _calc_clue_positions {
+    my $self = shift;
+    return
+    [
+        map {
+        [map { $self->_xy_to_int($_) } @{$self->_gen_clue_positions($_)}]
+        }
+        (
+            sub { [$_,$_];   },
+            sub { [$_,4-$_]; },
+            (map { my $y = $_; sub { [$y,$_] }; } $self->_y_indexes()),
+            (map { my $x = $_; sub { [$_,$x] }; } $self->_x_indexes()),
+        )
+    ]
+}
+
+my @_clues_positions = @{__PACKAGE__->_calc_clue_positions()};
 
 sub calc_riddle
 {

abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator/Base.pm

 
 use base 'Games::ABC_Path::Solver::Base';
 
-use Games::ABC_Path::Solver::Constants;
-
 =head1 NAME
 
 Games::ABC_Path::Generator::Base - a base class.

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Board.pm

         }
 
         my @neighbourhood = (map { [(0) x $LEN] } ($self->_y_indexes));
-        
+
         foreach my $true (@true_cells)
         {
             foreach my $coords