Commits

Anonymous committed 185fabf

Add the abc-path-gen script and testing it.

Fixed some bugs in the ::Generator in the process.

Comments (0)

Files changed (5)

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

     dist_author         => q{Shlomi Fish <shlomif@cpan.org>},
     dist_version_from   => 'lib/Games/ABC_Path/Generator.pm',
     build_requires => {
+        'Test::Differences' => 0,
         'Test::More' => 0,
     },
     requires => {

abc-path/Games-ABC_Path-Generator/MANIFEST

 MANIFEST			This list of files
 META.yml
 README
+scripts/abc-path-gen
 scripts/bump-version-number.pl
 scripts/tag-release.pl
 t/00-load.t
+t/cmd-line-test.t
 t/manifest.t
 t/ms-rand.t
 t/pod-coverage.t

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

 use strict;
 use warnings;
 
+use integer;
+
 use base 'Games::ABC_Path::Solver::Base';
 
 use Games::ABC_Path::Solver::Board '0.1.0';
 
+use Games::ABC_Path::MicrosoftRand;
+
 =head1 NAME
 
 Games::ABC_Path::Generator - a generator for ABC Path puzzle games.
 
     my $i = @$deck;
     while (--$i) {
-        my $j = $r->range_rand($i+1);
+        my $j = $r->max_rand($i+1);
         @$deck[$i,$j] = @$deck[$j,$i];
     }
 
         @{$get_next_cells_lookup[$init_idx]}
     ];
 }
-
 }
 
 
     my $self = shift;
 
     my @dfs_stack;
-    $self->_add_next_state(\@dfs_stack, '', $self->{rand}->range_rand($BOARD_SIZE));
+    $self->_add_next_state(\@dfs_stack, '', $self->{rand}->max_rand($BOARD_SIZE));
 
     DFS:
     while (@dfs_stack)

abc-path/Games-ABC_Path-Generator/scripts/abc-path-gen

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Games::ABC_Path::Generator;
+
+use Getopt::Long;
+
+my $seed = 24;
+my $mode = 'final';
+if (!GetOptions(
+        'seed=i' => \$seed,
+        'mode=s' => \$mode,
+    ))
+{
+    die "Could not get options for program!";
+}
+
+my $gen = Games::ABC_Path::Generator->new({ seed => $seed, });
+
+if ($mode eq 'final')
+{
+    print $gen->get_layout_as_string($gen->calc_final_layout());
+}
+elsif ($mode eq 'riddle')
+{
+    print $gen->get_riddle_as_string($gen->calc_riddle());
+}

abc-path/Games-ABC_Path-Generator/t/cmd-line-test.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Test::Differences;
+
+use File::Spec;
+
+my $prog_path = File::Spec->catfile(
+    File::Spec->curdir(), 'scripts', 'abc-path-gen'
+);
+
+{
+    # TEST
+    eq_or_diff(
+        scalar(`$^X -Mblib $prog_path --seed=1`),
+        <<'EOF',
+Y | X | R | S | T
+E | D | W | Q | U
+F | B | C | V | P
+G | A | K | L | O
+H | I | J | N | M
+EOF
+        'For seed #1',
+    );
+}
+
+{
+    # TEST
+    eq_or_diff(
+        scalar(`$^X -Mblib $prog_path --seed=1 --mode=riddle`),
+        <<'EOF',
+ABC Path Solver Layout Version 1:
+YGBJNUT
+S     R
+D     W
+F     V
+O A   K
+M     I
+HEXCQPL
+
+Solution:
+Y | X | R | S | T
+E | D | W | Q | U
+F | B | C | V | P
+G | A | K | L | O
+H | I | J | N | M
+EOF
+        'Riddle mode for seed #1',
+    );
+}
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.