Commits

Shlomi Fish committed d9c310d

Moved a method to the base class.

  • Participants
  • Parent commits 6b0f911

Comments (0)

Files changed (3)

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

 
 our $VERSION = '0.0.1';
 
-sub _xy_to_int
-{
-    my ($self, $xy) = @_;
-
-    return $xy->[$Y] * $LEN + $xy->[$X];
-}
-
-sub _to_xy
-{
-    my ($self, $int) = @_;
-
-    return (($int / $LEN), ($int % $LEN));
-}
 =head1 SYNOPSIS
 
 B<For internal use.>.
 
 =back
 
-
 =head1 ACKNOWLEDGEMENTS
 
 

File abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Base.pm

 use warnings;
 use strict;
 
+use Games::ABC_Path::Solver::Constants;
+
 =head1 NAME
 
 Games::ABC_Path::Solver::Base - base class for Games::ABC_Path::Solver classes.
 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
-
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 
     return $self;
 }
 
+use integer;
+
+sub _xy_to_int
+{
+    my ($self, $xy) = @_;
+
+=begin foo
+
+    {
+    my ($y, $x) = @{$xy}[$Y,$X];
+    if (($x < 0) or ($x > $LEN_LIM))
+    {
+        confess "X $x out of range.";
+    }
+
+    if (($y < 0) or ($y > $LEN_LIM))
+    {
+        confess "Y $y out of range.";
+    }
+    }
+=end foo
+
+=cut
+
+    return $xy->[$Y] * $LEN + $xy->[$X];
+}
+
+sub _to_xy
+{
+    my ($self, $int) = @_;
+
+    return (($int / $LEN), ($int % $LEN));
+}
+
+sub _y_indexes
+{
+    return (0 .. $LEN_LIM);
+}
+
+sub _x_indexes
+{
+    return (0 .. $LEN_LIM);
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, C<< <shlomif at cpan.org> >>

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

     return $self->{_layout};
 }
 
-sub _y_indexes
-{
-    return (0 .. $LEN_LIM);
-}
-
-sub _x_indexes
-{
-    return (0 .. $LEN_LIM);
-}
-
 # The letter indexes.
 sub _l_indexes
 {
     return (0 .. $ABCP_MAX_LETTER);
 }
 
-
 sub _init
 {
     my ($self, $args) = @_;
     return;
 }
 
-sub _xy_to_idx
-{
-    my ($self, $x, $y) = @_;
-
-    if (($x < 0) or ($x > $LEN_LIM))
-    {
-        confess "X $x out of range.";
-    }
-
-    if (($y < 0) or ($y > $LEN_LIM))
-    {
-        confess "Y $y out of range.";
-    }
-
-
-    return $y * $LEN +$x;
-}
-
 sub _calc_offset
 {
     my ($self, $letter, $x, $y) = @_;
         confess "Letter $letter out of range.";
     }
 
-    return $letter * $BOARD_SIZE + $self->_xy_to_idx($x,$y);
+    return $letter * $BOARD_SIZE + $self->_xy_to_int([$y,$x]);
 }
 
 sub _get_verdict