#! /usr/bin/env raku

use Game::Amazing;
use Pod::To::Text;

multi MAIN (*@files)
{
  check-it($_) for @files;
}

multi MAIN(Bool :h(:$help))
{
  say pod2text($=pod);
}

sub check-it ($file)
{
  if $file.IO.f
  {
    next unless $file.ends-with('.maze');
    
    my $m = Game::Amazing.new: $file;
    my ($traversable, $traversable-path) = $m.is-traversable(:get-path);

    say $traversable
      ?? "$file [{ $m.rows },{ $m.cols }] is traversable (difficuly: { ($traversable-path.chars / ( $m.rows + $m.cols -2)).round(0.1) })."
      !! "$file [{ $m.rows },{ $m.cols }] is not traversable.";
  }
  elsif $file.IO.d
  {
    check-it($_) for dir($file).sort;
  }
}

=begin pod

=head1 NAME

maze-solver-summary - Check one or more mazes for traversability

=head1 SYNOPSIS

Use this program to get a summary of traversability and difficulty for the specified mazes.

Usage:

    maze-solver-summary FILE-OR-DIRECTORY [FILE-OR-DIRECTORY ...]
    maze-solver-summary [-h|--help]

Check one or more maze files for traversability and assumed difficulty. You can specify a
directory to get all the maze files in it, recursively.

The difficulty is the ratio between size and length of the shortest path. The shortest
possible path has a difficulty rating of 1.0. Higher values means longer paths.

Examples:

    maze-solver-summary mazes/25x25-ok.maze
    maze-solver-summary *.maze
    maze-solver-summary mazes/

    maze-solver-summary -h

=head1 SEE ALSO

This program is part of the Raku module «Game::Amazing».

=head1 AUTHOR

Arne Sommer <arne@perl6.eu>

=head1 COPYRIGHT AND LICENSE

Copyright 2020 Arne Sommer

This program is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

=end pod
