Commits

Shlomi Fish committed e3b8883 Merge

Merge

Comments (0)

Files changed (26)

 abc-path/Games-ABC_Path-Generator/Build
+abc-path/Games-ABC_Path-Generator/META.json
+abc-path/Games-ABC_Path-Generator/META.yml
+abc-path/Games-ABC_Path-Generator/MYMETA.json
 abc-path/Games-ABC_Path-Generator/MYMETA.yml
+abc-path/Games-ABC_Path-Generator/Makefile.PL
 abc-path/Games-ABC_Path-Generator/_build/
 abc-path/Games-ABC_Path-Generator/blib
 abc-path/Games-ABC_Path-Generator/tags
 abc-path/Games-ABC_Path-Solver/Build
+abc-path/Games-ABC_Path-Solver/META.yml
+abc-path/Games-ABC_Path-Solver/MYMETA.json
 abc-path/Games-ABC_Path-Solver/MYMETA.yml
+abc-path/Games-ABC_Path-Solver/Makefile.PL
 abc-path/Games-ABC_Path-Solver/_build
 abc-path/Games-ABC_Path-Solver/blib
 53732bc025792bfbd28375d967c4f656985ab6a5 cpan-releases/0.0.3
 2c4630d0edfb6e4ea680670656ee584b77ef299a cpan-releases/0.1.0
 7ba0b7baca157b77ae113db1d146a25170b237fe Games-ABC_Path-Generator-cpan-releases/0.0.1
+7e7b05cc754ca565f5df178e723e6969762ad357 Tagging the Games-ABC_Path-Solver release as 0.2.0
+7e7b05cc754ca565f5df178e723e6969762ad357 Games-ABC_Path-Solver-0.2.0
+19b09cd6ef76278742a0c5fd1dff3a1ef8d84448 Tagging the Games-ABC_Path-Generator release as 0.1.0
+19b09cd6ef76278742a0c5fd1dff3a1ef8d84448 Games-ABC_Path-Generator-0.1.0

abc-path/Games-ABC_Path-Generator/Build.PL

         'Carp' => 0,
         'Class::XSAccessor' => 0,
         'Exporter' => 0,
-        'Games::ABC_Path::Solver::Base' => 0,
-        'Games::ABC_Path::Solver::Board' => '0.1.0',
+        'Games::ABC_Path::Solver::Base' => '0.2.0',
+        'Games::ABC_Path::Solver::Constants' => '0.2.0',
+        'Games::ABC_Path::Solver::Board' => '0.2.0',
         'Getopt::Long' => '2.36',
         'integer' => 0,
         'perl' => 5.006,

abc-path/Games-ABC_Path-Generator/Changes

 Revision history for Games-ABC_Path-Generator
 
+0.1.0       Sat Jul 23 21:34:59 IDT 2011
     - Improved lib/Games/ABC_Path/Generator.pm with acknowldgements, a 
     "SEE ALSO" section and a "DESCRIPTION" section.
     - Add the shuffle method to lib/Games/ABC_Path/MicrosoftRand.pm .
+    - 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 . 
+        - Now requires Games::ABC_Path::Solver version 0.2.0.
     
 0.0.1       Thu Jul 21 19:02:11 IDT 2011
     - First version, released on an unsuspecting world.

abc-path/Games-ABC_Path-Generator/MANIFEST

 t/pod-coverage.t
 t/pod.t
 t/riddle-obj.t
+META.json

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

 
 use base 'Games::ABC_Path::Generator::Base';
 
-use Games::ABC_Path::Generator::Constants;
+use Games::ABC_Path::Solver::Constants;
 
 use Games::ABC_Path::Solver::Board '0.1.0';
 
 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 
 =head1 SYNOPSIS
         [ 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 ($self, $cb) = @_;
+    return [map { $cb->($_) } $self->_x_indexes()];
+};
+
+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
 {
     my ($self) = @_;
             my @positions =
             (
                 grep { !vec($last_state->{pos_taken}, $_, 1) } 
-                (
-                    map { $self->_xy_to_int($_) }
-                    (($clue_idx == 0)
-                        ? (map { [$_,$_] } (0 .. $LEN-1))
-                        : ($clue_idx == 1)
-                        ? (map { [$_,4-$_] } ( 0 .. $LEN-1))
-                        : ($clue_idx < (2+5))
-                        ? (map { [$clue_idx-2,$_] } (0 .. $LEN-1))
-                        : (map { [$_, $clue_idx-(2+5)] } (0 .. $LEN-1))
-                    )
-                )
+                @{$_clues_positions[$clue_idx]}
             );
 
             my @pairs;

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

 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 
 =head1 SYNOPSIS

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

 
 use base 'Games::ABC_Path::Solver::Base';
 
-use Games::ABC_Path::Generator::Constants;
-
 =head1 NAME
 
 Games::ABC_Path::Generator::Base - a base class.
 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
-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
 
 

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

 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 

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

 
 use base 'Games::ABC_Path::Generator::Base';
 
-use Games::ABC_Path::Generator::Constants;
+use Games::ABC_Path::Solver::Constants;
 
 =head1 NAME
 
 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 =head1 SYNOPSIS
 

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

 
 use base 'Games::ABC_Path::Solver::Base';
 
-use Games::ABC_Path::Generator::Constants;
+use Games::ABC_Path::Solver::Constants;
 
 =head1 NAME
 
 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 =head1 SYNOPSIS
 

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

 
 =head1 VERSION
 
-Version 0.0.1
+Version 0.1.0
 
 =cut
 
-our $VERSION = '0.0.1';
+our $VERSION = '0.1.0';
 
 
 =head1 SYNOPSIS

abc-path/Games-ABC_Path-Solver/Changes

 Revision history for Games-ABC_Path-Solver
 
+0.2.0   Sat Jul 23 21:22:17 IDT 2011
+        - Create lib/Games/ABC_Path/Solver/Constants.pm based on the one 
+        from Games::ABC_Path::Generator.
+        - Merge common functionality into lib/Games/ABC_Path/Solver/Base.pm .
+
 0.1.0   Wed Jul 20 20:34:01 IDT 2011
         - Add the input_from_v1_string class method to input from a version
         1 string, so there will be a way to input from something besides

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
 t/results/brain-bashers.2010-12-21.abc-path-sol
 t/results/brain-bashers.2010-12-22.abc-path-sol
 t/solver-output-system-test.t
+META.json

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

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 
 =head1 SYNOPSIS

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

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

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);
+}
+
+sub _x_in_range
+{
+    my ($self, $x) = @_;
+
+    return ($x >= 0 and $x < $LEN);
+}
+
+sub _y_in_range
+{
+    my ($self, $y) = @_;
+
+    return $self->_x_in_range($y);
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, C<< <shlomif at cpan.org> >>

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

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 
 
 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
     return $self->{_layout};
 }
 
-sub _y_indexes
-{
-    return (0 .. $BOARD_LEN_LIM);
-}
-
-sub _x_indexes
-{
-    return (0 .. $BOARD_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 > $BOARD_LEN_LIM))
-    {
-        confess "X $x out of range.";
-    }
-
-    if (($y < 0) or ($y > $BOARD_LEN_LIM))
-    {
-        confess "Y $y out of range.";
-    }
-
-
-    return $y * $BOARD_LEN +$x;
-}
-
 sub _calc_offset
 {
     my ($self, $letter, $x, $y) = @_;
         confess "Letter $letter out of range.";
     }
 
-    return $letter * ($BOARD_LEN * $BOARD_LEN) + $self->_xy_to_idx($x,$y);
+    return $letter * $BOARD_SIZE + $self->_xy_to_int([$y,$x]);
 }
 
 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 {
+                    $self->_x_in_range($_->[0]) and $self->_y_in_range($_->[1])
+                }
                 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.2.0';
+
+=head1 VERSION
+
+Version 0.2.0
+
+=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

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

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/LastRemainingCellForLetter.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/LastRemainingLetterForCell.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/LettersNotInVicinity.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/ResultsInASuccess.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/ResultsInAnError.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/TryingLetterForCell.pm

 
 =head1 VERSION
 
-Version 0.1.0
+Version 0.2.0
 
 =cut
 
-our $VERSION = '0.1.0';
+our $VERSION = '0.2.0';
 
 =head1 SYNOPSIS
 
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.