Commits

Shlomi Fish committed 99f91ec

Extract the Constants module with constants.

We're trying to merge the common code of Solver and Generator.

Comments (0)

Files changed (3)

abc-path/Games-ABC_Path-Solver/MANIFEST

 lib/Games/ABC_Path/Solver/App.pm
 lib/Games/ABC_Path/Solver/Base.pm
 lib/Games/ABC_Path/Solver/Board.pm
+lib/Games/ABC_Path/Solver/Constants.pm
 lib/Games/ABC_Path/Solver/Move/LastRemainingCellForLetter.pm
 lib/Games/ABC_Path/Solver/Move/LastRemainingLetterForCell.pm
 lib/Games/ABC_Path/Solver/Move/LettersNotInVicinity.pm

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

 
 use base 'Games::ABC_Path::Solver::Base';
 
+use Games::ABC_Path::Solver::Constants;
 use Games::ABC_Path::Solver::Move::LastRemainingCellForLetter;
 use Games::ABC_Path::Solver::Move::LastRemainingLetterForCell;
 use Games::ABC_Path::Solver::Move::LettersNotInVicinity;
 my $ABCP_VERDICT_MAYBE = 1;
 my $ABCP_VERDICT_YES = 2;
 
-my $BOARD_LEN = 5;
-my $BOARD_LEN_LIM = $BOARD_LEN - 1;
-
-my @letters = (qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y));
-
-my $ABCP_MAX_LETTER = $#letters;
-
 my %letters_map = (map { $letters[$_] => $_ } (0 .. $ABCP_MAX_LETTER));
 
 sub _get_letter_numeric
 
 sub _y_indexes
 {
-    return (0 .. $BOARD_LEN_LIM);
+    return (0 .. $LEN_LIM);
 }
 
 sub _x_indexes
 {
-    return (0 .. $BOARD_LEN_LIM);
+    return (0 .. $LEN_LIM);
 }
 
 # The letter indexes.
 {
     my ($self, $x, $y) = @_;
 
-    if (($x < 0) or ($x > $BOARD_LEN_LIM))
+    if (($x < 0) or ($x > $LEN_LIM))
     {
         confess "X $x out of range.";
     }
 
-    if (($y < 0) or ($y > $BOARD_LEN_LIM))
+    if (($y < 0) or ($y > $LEN_LIM))
     {
         confess "Y $y out of range.";
     }
 
 
-    return $y * $BOARD_LEN +$x;
+    return $y * $LEN +$x;
 }
 
 sub _calc_offset
         confess "Letter $letter out of range.";
     }
 
-    return $letter * ($BOARD_LEN * $BOARD_LEN) + $self->_xy_to_idx($x,$y);
+    return $letter * ($LEN * $LEN) + $self->_xy_to_idx($x,$y);
 }
 
 sub _get_verdict
             }
         }
 
-        my @neighbourhood = (map { [(0) x $BOARD_LEN] } ($self->_y_indexes));
+        my @neighbourhood = (map { [(0) x $LEN] } ($self->_y_indexes));
         
         foreach my $true (@true_cells)
         {
             foreach my $coords
             (
-                grep { $_->[0] >= 0 and $_->[0] < $BOARD_LEN and $_->[1] >= 0 and
-                $_->[1] < $BOARD_LEN }
+                grep { $_->[0] >= 0 and $_->[0] < $LEN and $_->[1] >= 0 and
+                $_->[1] < $LEN }
                 map { [$true->[0] + $_->[0], $true->[1] + $_->[1]] }
                 map { my $d = $_; map { [$_, $d] } (-1 .. 1) }
                 (-1 .. 1)

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

+package Games::ABC_Path::Solver::Constants;
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+Games::ABC_Path::Solver::Constants - constants in use by the generator.
+B<FOR INTERNAL USE!>.
+
+=cut
+
+our $VERSION = '0.0.1';
+
+=head1 VERSION
+
+Version 0.0.1
+
+=cut
+
+
+use base 'Exporter';
+
+our $LEN = 5;
+our $LEN_LIM = $LEN-1;
+our $BOARD_SIZE = $LEN * $LEN;
+our $Y = 0;
+our $X = 1;
+our @letters = (qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y));
+our $NUM_CLUES = (2+$LEN+$LEN);
+
+our $ABCP_MAX_LETTER = $#letters;
+
+our @EXPORT =
+(
+    qw($X $Y $NUM_CLUES @letters $LEN $LEN_LIM $BOARD_SIZE $ABCP_MAX_LETTER)
+);
+
+1;
+=head1 AUTHOR
+
+Shlomi Fish, L<http://www.shlomifish.org/> .
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-games-abc_path-generator at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-ABC_Path-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::ABC_Path::Solver::Constants
+
+You can also look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker (report bugs here)
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-ABC_Path-Solver>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Games-ABC_Path-Solver>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Games-ABC_Path-Solver>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Games-ABC_Path-Solver/>
+
+=back
+
+
+=head1 ACKNOWLEDGEMENTS
+
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2011 Shlomi Fish.
+
+This program is distributed under the MIT (X11) License:
+L<http://www.opensource.org/licenses/mit-license.php>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+=cut
+
+1; # End of Games::ABC_Path::Solver::Constants