|
AI::Pathfinding::AStar - Perl implementation of the A* pathfinding algorithm |
AI::Pathfinding::AStar - Perl implementation of the A* pathfinding algorithm
use AI::Pathfinding::AStar qw(findPath) my $path = &findPath($map_obj, $start, $target);
print join(', ', @$path), "\n";
This module implements the A* pathfinding algorithm. It attempts to be as generally useful as possible by leaving the determination of legal moves and heuristic calculations to an external map object.
This object can export a single function, &findPath, and requires the following parameters:
&astar_surrounding which accepts an identifier for a node on your map as well as an identifier for the target node. This method must return a reference to an array containing references to sub-arrays each describing the nodes adjacent to the given node. Each sub-array should have 3 elements:
Basically you should return a reference like this: return [ [$node1, $cost1, $h1], [$node2, $cost2, $h2], [...], ...];
I know this sounds confusing. Please refer to the ExampleMap.pm sourcefile for a very basic example of a conforming map object.
exists $hash{$nodeid} then they will work.
This routine then returns a reference to an array of Node IDs representing the least expensive path to your target node.
This module requires Heap::Simple to function.
Heap::Simple, http://www.policyalmanac.org/games/aStarTutorial.htm This distribution contains an example map object and test script in the examples directory that may be of assistance.
Aaron Dalton - acdalton@cpan.org This is my very first CPAN contribution and I am not a professional programmer. Any feedback you may have, even regarding issues of style, would be greatly appreciated. I hope it is of some use to somebody.
Copyright 2003 by Aaron Dalton
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
AI::Pathfinding::AStar - Perl implementation of the A* pathfinding algorithm |