#! /usr/bin/env raku

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

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

multi MAIN ($maze where $maze.IO.e && $maze.IO.r, $transform where $transform eq "90" | "180" | "270" | "R" | "D" | "L" | "V" | "H" = "90", :c(:$corners) = False)
{
  my $m = Game::Amazing.new: $maze;

  my $new = $m.transform($transform, :$corners);

  $new.save($*OUT);
}

=begin pod

=head1 NAME

maze-transform - Transform (rotate or flip) a maze

=head1 SYNOPSIS

Use this program to transform a maze in a number of ways. Rotation (R or 90, D or 180,
L or 270) and Flip horizontally (H) and vertically (V) is currently supported. The new
maze is printed to the screen.

Usage:

    maze-transform [-c|--corners] MAZE-FILE [90|180|270|R|D|L|H|V]

    maze-transform [-h|--help]

It will transform the maze in the specified way. The rotation is in degrees in the
clockwise direction.

90 is to the right, 180 is down and 270 is to the left.

The entrance and exit (the same symbol) in the upper left and lower right corners,
may end up in wrong corners as a result of the transformation. Use the [-c|--corners]
command line option to ensure that they stay in the correct corners. The result of
this is that the upper right hand corner is set to «╗», and the lower left hand corner
to «╚». This will actually roundtrip (if we apply more changes), but only if the
original cells do not have spurious exits. (Scroll down to «An Even More Amazing Program»
in https://raku-musings.com/amazing1.html for more information.) 

Examples:

    maze-transform mazes/10x10-hard.maze 90
    maze-transform -c mazes/10x10-hard.maze 90
    maze-transform mazes/10x10-hard.maze R 
    maze-transform -c mazes/10x10-hard.maze R 

    maze-transform -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
