AI::Pathfinding::AStar::Rectangle - AStar algorithm on rectangle map
use AI::Pathfinding::AStar::Rectangle qw(create_map); my $map = create_map({height=>10, width=>10}); # # -or- # # $map = AI::Pathfinding::AStar::Rectangle->new({{height=>10, width=>10}); for my $x ($map->start_x..$map->last_x){ for my $y ($map->start_y..$map->last_y){ $map->set_passability($x, $y, $A[$x][$y]) # 1 - Can pass througth , 0 - Can't pass } } 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
AI::Pathfinding::AStar::Rectangle provide abstraction for Rectangle map with AStar algoritm
Create AI::Pathfinding::AStar::Rectangle object. Object represent map with given height and width.
Set passability for point(x,y)
Get passability for point
Search path from one point to other
return path like "1234..9"
where 1 - mean go left-down 2 - down 3 - down-right ... 9 - right-up
Get map width
Get map height
Get/Set coords for leftbottom-most point
Set coordinates of left-bootom point
Get coords for right-upper point
Call BLOCK for every point on map.
$map->foreach_xy( sub { $A[$a][$b] = $_ }) ($a, $b, $_) (x, y, passability)
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,
In list context return ( end_x, end_y, weigth, true or false )
In list context return ( end_x, end_y, weigth ) weight is sum of <diagonal (1379)> * 14 + <short path> * 10
$m->foreach_xy_set( sub { $a < 12 && 1<$b && $b <9 } ); $m->draw_path( 5, 5, '1666666888' );
Result:
# Steps: 10 # 00010203040506070809101112131415 # |#|#|#|#|#|#|#|#|#|#|#|#|#|#|#0 # |#|#|#|#|#|#|#|#|#|#|#|#|#|#|#1 # |_|_|_|_|_|_|_|_|_|_|_|_|#|#|#2 # |_|_|_|_|_|_|_|_|_|_|_|_|#|#|#3 # |_|_|_|_|o|o|o|o|o|o|o|_|#|#|#4 # |_|_|_|_|_|o|_|_|_|_|o|_|#|#|#5 # |_|_|_|_|_|_|_|_|_|_|o|_|#|#|#6 # |_|_|_|_|_|_|_|_|_|_|o|_|#|#|#7 # |_|_|_|_|_|_|_|_|_|_|_|_|#|#|#8
See ./examples
None by default.
A.G. Grishaev, <gtoly@cpan.org<gt>
Copyright (C) 2010 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:
You forgot a '=back' before '=head2'
To install AI::Pathfinding::AStar::Rectangle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::Pathfinding::AStar::Rectangle
CPAN shell
perl -MCPAN -e shell install AI::Pathfinding::AStar::Rectangle
For more information on module installation, please visit the detailed CPAN module installation guide.