Thursday, January 31, 2008

A* Algorythm in Java - Download

I wrote this code a while ago, and I've finally got round to putting it here for public use. It's the A* path-finding algorythm, nicely self contained and ready for use. It can run in a thread if required, and to use it, you can simply write:-

AStar my_astar = new AStar(mymapclass);
WayPoints route = my_astar.findpath(start_x, start_y, end_x, end_y, b_run_in_thread);

Your
mymapclass must implement the IAStarMapInterface (included), which has 3 methods: getWidth(), getHeight() and isTraversable(). This tells the algorythm where it can and can't go. The class WayPoints is just an ArrayList of Points, giving the route.

I've used this code in all of my games (that require pathfinding) like Nuclear Graveyard and TremulousHulk.

(For those not in the know, the A* algorythm basically finds the closest path from one co-ordinate to another, taking into account blocked points.)

No comments: