README.TXT

This zip file contains a Flash MX file and several script files for my A* pathfinding demo.  This zip file was created 16 March 2003.  I wrote most of the code in July of 2002.

Questions:

- What is A* pathfinding?

A* is a pathfinding algorithm that finds the shortest path between two points on a graph.  It is a specific implementation of Dykstra's algorithm, which is just a method for finding the shortest path from one point to every other point in a graph.  A* is sometimes called a flooding algorithm, if you watch it try to find a path around an obstacle you will understand why.

- What is A* pathfinding used for?

A* can be used for a lot of things, like finding the shortest solution to a 15 slider puzzle or finding the shortest path on a map.  It is a very popular algorithm for computer games, where the user wants to tell a unit to go to some location without telling it specifically how to get there.  Pathfinding can be a blessing or a curse in games, because good pathfinding must be optimized to not slow the program down, and bad pathfinding is just embarrassing.  A lot of things can affect pathfinding, so even a correctly programmed A* routine will be a turkey if it has to operate on badly designed structures.

- Why did you write this in Flash MX?

I wanted to learn how A* worked and for me Flash is an easy tool for quick prototyping.  I also wanted to see how it would perform in Flash, if Flash was at all viable for more sophisticated games than Space Invaders.  I could have written it in Java, or I could have used Director if I just had to use a Macromedia product.  As it is, it works in Flash, the performance is okay (I'm working on a laptop with a PII 450), but a million times slower than it is in most commercial games.

- I'm looking at the Flash file.  Where is the ActionScript code?

There is almost no code in the Flash file.  The code is in the *.as files.  Use your favorite text editor (I use HomeSite with JavaScript color coding) to edit.  If you're writing code at this level, you don't need Flash's context help, do you?

- How can I understand the code?

I've extracted some variables out so they can be tweaked.  On-screen there is a box that says "Steps per frame" - when the movie is playing you can enter a number and it will control how many nodes get searched each frame.  Or you can set the variable called algSteps.

If you look in "astar.as" there is a variable called nodeSize.  This is the height/width of nodes, so if you make this smaller (say 6) you will get a grid of nodes that are 6 x 6 pixels.  That means the graph will contain 50x40 = 2000 nodes, which is a decent sized search space.  If you set it to 30, you will have only 10x8 = 80 nodes in the search space.

The file "linkedlist.as" contains a rather hasty linked list implementation.  Use at your own risk.  This is where a lot of CPU gets wasted, a linked list isn't very good for A*.

The file "alg.as" contains the A* implementation.  It is set up to run a limited number of ticks per frame.  Not only is this the nice thing to do when coding, it lets you watch the algorithm in progress.

I did some other strange things in the code, like set up a node bank instead of creating hundreds/thousands of nodes at the start.  I'm not sure why I did this, I guess I didn't want to eat up too much memory right away.  Flash doesn't allow any control for memory use anyway.

You can toggle the heuristic function between Euclidean distance and Manhattan distance.  It is instructive to see what difference it makes.

- Where did this come from?

You can find this zip file at
http://www.antimodal.com/astar/

- I have questions/comments/want to offer you $$$.

Feel free to send me your comments.

Brandon Rickman
shoehorn@antimodal.com

