Games-ABC_Path-Solver
view release on metacpan or search on metacpan
lib/Games/ABC_Path/Solver/App.pm view on Meta::CPAN
=cut
our $VERSION = '0.4.1';
=head1 SYNOPSIS
#!/usr/bin/perl
use strict;
use warnings;
use Games::ABC_Path::Solver::App;
Games::ABC_Path::Solver::App->new({argv => [@ARGV] })->run;
=head1 FUNCTIONS
=head2 new
The constructor. Accepts a hash ref of named arguments. Currently only C<'argv'>
which should point to an array ref of command-line arguments.
=head2 run
Run the application based on the arguments in the constructor.
=cut
use base 'Games::ABC_Path::Solver::Base';
use Carp;
use Getopt::Long;
use Pod::Usage;
use Games::ABC_Path::Solver::Board;
sub _argv
{
my $self = shift;
if (@_) {
$self->{_argv} = shift;
}
return $self->{_argv};
}
sub _init
{
my ($self, $args) = @_;
$self->_argv([@{$args->{argv}}]);
return;
}
sub run
{
my $self = shift;
local @ARGV = @{$self->_argv};
my $man = 0;
my $help = 0;
my $gen_template = 0;
GetOptions(
'help|h' => \$help,
man => \$man,
'gen-v1-template' => \$gen_template,
)
or pod2usage(2);
if ($help)
{
pod2usage(1);
}
elsif ($man)
{
pod2usage(-verbose => 2);
}
elsif ($gen_template)
{
print <<'EOF';
ABC Path Solver Layout Version 1:
???????
? ?
? ?
? ?
? A ?
? ?
???????
EOF
}
else
{
my $board_fn = shift(@ARGV);
if (!defined ($board_fn))
{
die "Filename not specified - usage: abc-path-solver.pl [filename]!";
}
my $solver = Games::ABC_Path::Solver::Board->input_from_file($board_fn);
# Now let's do a neighbourhood inferring of the board.
$solver->solve;
foreach my $move (@{$solver->get_moves})
{
print +(' => ' x $move->get_depth()), $move->get_text(), "\n";
}
print @{$solver->get_successes_text_tables};
}
exit(0);
}
=head1 AUTHOR
( run in 1.035 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )