A* haXe pathfinding

I rewrote bmod at BaseOneOnline.com’s Actionscript 3.0 A* classes to haXe (flash9 because I’m working on a game and needed some quick pathfinding. I also wanted to see if haXe would solve the A* algorithm faster than the adobe actionscript 3 compiler, and by how much. The benchmarks are not as accurate on bmod’s as3 because he mentions he used an inaccurate timing method. I had trouble with haXe’s flash9.utils.Timer class too, so i used the haXe haxe.Timer class to get a more accurate measurement.

The solved path is not always the shortest path possible as intended. But will suffice for what i need it for.

When sorting a node’s neighbors by it’s cost (distance), I had some trouble because i didn’t know how to translate AS3’s Array.sort) to haXe’s Array.sort. So i added DiskTree.net’s QuickSort (sorting the node property for distance “f”) to the com.baseoneonline.haxe.astar package.

Other than the timer and replacing Array.sort with QuickSort, the code is pretty much the same, just re-written to be compiled on haXe. There may be a few more enhancements i can make to make this faster, such as using Vector instead of Array and compiling for flash10, something i may try, or you can try and let me know :)

The original BaseOneOnline.com AS3 A* Article is here: http://blog.baseoneonline.com/?p=87

The exact Actionscript3 source that i used to convert to haXe:
BaseOneOnline-AStar-AS3.zip
Check the site though, he may have an update

My haXe‘d A* classes:
zipped: AStar-haXe.zip
svn: http://publicsvn.remixtechnology.com/AStar-haXe

Both examples have random “unwalkable” tiles generated, so just refresh this page to get a new random tile map. Just click around on the lighter tiles to find new paths

Original A* path finding in Actionscript 3 [Source][Destination]

Ported A* path finding to haXe as3 [Source][Destination]

i hope this fills your haXe tile based path finding needs well. Many thanks to bmod for his great work!

Adrian said

Nov 26, 2008 @ 03:48 AM

Nice work.

It would be nice to be able to compare the two finding the same path, from the attempts I made I couldn’t tell which was faster, sometimes one sometimes the other.

kaalh said

Nov 27, 2008 @ 10:04 PM

nice work !

the following exception occurs whith debug player when the path cannot be solved on both versions

TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.baseoneonline.haxe.astar::QuickSortNodes$/quicksort() at com.baseoneonline.haxe.astar::QuickSortNodes$/run() at com.baseoneonline.haxe.astar::AStar/solve() at AStarHaxe/onClick()

RSS feed for comments on this post

Leave a Comment