NAME

AI::Pathfinding::AStar::Rectangle - AStar search on rectangle map

SYNOPSIS

use AI::Pathfinding::AStar::Rectangle qw(create_map);

my $map = create_map({heigth=>10, width=>10}); 
for my $x ($map->start_x..$map->last_x){
    for my $y ($map->start_y..$map->last_y)
        $map->set_value($x, $y, $A[$x][$y]) # 1 - Can pass throu , 0 - Can't
    }
}

my $path = $map->astar( $from_x, $from_y, $to_x, $to_y);

print $path, "\n"; # print path in presentation of "12346789" like keys at keyboard

DESCRIPTION

AI::Pathfinding::AStar::Rectangle provide abstraction for Rectangle map with AStar algoritm

OBJECT METHODS

new { "width" => map_width, "heigth" => map_heigth }

Create AI::Pathfinding::AStar::Rectangle object. Object represent map with given heigth and width.

set_passability x, y, value # value: 1 - can pass through point, 0 - can't

Set passability for point(x,y)

get_passability (x,y)

Get passability for point

astar(from_x, from_y, to_x, to_y)

Search path from one point to other

return path like "1234"

where 1 - mean go left-down 2 - down 3 - down-right ... 9 - right-up

width()

Get map width

heigth()

Get map heigth

start_x(), start_y()

Get/Set coords for leftbottom-most point

last_x(), last_y()

Get coords for right-upper point

foreach_xy( BLOCK )

Call BLOCK for every point on map.

$map->foreach_xy( sub { $A[$a][$b] = $_ }) ($a, $b, $_) (x, y, passability)

foreach_xy_set( sub { $A[$a][$b] });
set passability for every point at map. 
BLOCK must return passability for point ($a, $b);
$a and  $b must be global var not declared as my, our, 
path_valid( start_x, start_y, path)

In scalar context return boolean value, true - if every point on path is passable, else return false In list context return ( end_x, end_y, weigth, true or false )

path_goto( start_x, start_y, path)

In list context return ( end_x, end_y, weigth )

draw_path( start_x, start_y, path)
print path to STDOUT

EXAMPLES

See ./examples

EXPORT

None by default.

SEE ALSO

AUTHOR

A.G. Grishaev, <gtoly@cpan.org<gt>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by A.G. Grishaev

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 191:

You forgot a '=back' before '=head2'