Alternatives to AStar pathing?

BlitzMax Forums/BlitzMax Programming/Alternatives to AStar pathing?

coffeedotbean(Posted 2010) [#1]
Hi all

Is there a good alternative to AStar for finding a path on a 2 dimensional array with simple rules of 1=passable & 0=impassable? (no diagonal movement). Or maybe a good tie breaker rule I could employ to Astar?

I currently use AStar which is fine but does not always find the shortest path due to some nodes having equal scores and so it just picks the first in the list which is not always the best. (tie breaker)

I followed Patrick Lester’s excellent A* tutorial to create my routine http://www.policyalmanac.org/games/aStarTutorial.htm - only without the diagonal movement.

I am not concerned with speed or efficiency as it will be used on a grid no bigger than 25x25, but I would like to find the best path every time. I have goggled but did not find much.

I have used Astar with great success in my santas workshop game but for my current project I need more accuracy in my pathing.


ima747(Posted 2010) [#2]
There are a few alternatives to AStar but they've always let me down. Personally I would focus on improving your tie break method. If you determine a tie perhaps check for the one with the closest strait line distance.

Also check out http://www-cs-students.stanford.edu/~amitp/gameprog.html#paths (referenced from Patrick's tutorial which I also used to get started with AStar :0) I found lots of good ideas and options there.


Robert Cummings(Posted 2010) [#3]
http://www.policyalmanac.org/games/aStarTutorial.htm is the best/most widely accepted. Did you mess about with the heuristics? it is what determines if you'll be taking a diagonal or not.

The default behaviour is to cost diagonals slightly more. Just change the costing, read this: http://www.policyalmanac.org/games/heuristics.htm


Robert Cummings(Posted 2010) [#4]
"I would like to find the best path every time" - as above, mess with the heuristics, or simply use Dijkstra's Algorithm, since Dijkstra's Algorithm will always be guaranteed to always find the absolute shortest path.

People use A* instead of Dijkstra's Algorithm, because its a lot quicker to use Dijkstra's Algorithm with a "heuristic" which basically means "best guess".

I'm guessing you didn't read up much on that site as all the info is there. There is also a Dijkstra's Algorithm implementation in code archives on this site.


coffeedotbean(Posted 2010) [#5]
Hi all - i'll look into Dijkstra's Algorithm I did check the links in Patrick Lesters post under further reading but maybe I didn't look hard enough.

If I cannot fathom Dijkstra's Algorithm then I'll try a better tie breaker on AStar - maybe doing several passes with different tie break rules and which ever is shortest is the path returned.


Czar Flavius(Posted 2010) [#6]
A* is proven optimal and indeed I proved it myself in my exam last year, provided the heuristic function never overestimates the minimum distance remaining. A* is supposed to backtrack if it finds the route it's going down is not the shortest way. You shouldn't need to program an explicit tie-break rule. This gif gives an example:


When it considers c, it estimates this node will take even longer than the path through d, and so investigates that path instead.


coffeedotbean(Posted 2010) [#7]
Hum my implementation does not 'backtrack', there is one section of Patrick's explanation I missed out as I thought it just dealt with diagonal movements ( step 6 under Continuing the Search ). I'll look at that again.


ima747(Posted 2010) [#8]
Just a note the "tie break" I mentioned above was related to best guessing shortest path between 2 options. Proper A* should backtrack... the tie break just makes it possibly save time since it's more likely to guess which option is shorter, rather than just pull from the top of the list. It's a heuristic tool. I forget all the lingo, so I hope that was relatively clear...


Dreamora(Posted 2010) [#9]
A* without backtrack is nothing but depth search, at best dijstra, isn't it.

As distance estimates without backtracks are just worthless / miss their purpose of early dropping a significant amount of the search set.


Robert Cummings(Posted 2010) [#10]
A* is Dijkstra's with a heuristic to guess best paths for speed purposes, they are pretty much similar methods. Coffee, dont forget there is blitzbasic code on that link if you fancy a short cut.


slenkar(Posted 2010) [#11]
Ive been using A* in blitz for years, if you want my codez just say...


BladeRunner(Posted 2010) [#12]
Try this, hope it helps


GW(Posted 2010) [#13]
Try this, hope it helps

+3 for sharing code
-1 for no indentation
-1 for using tLink!


coffeedotbean(Posted 2010) [#14]
@ Rob Cummings - nah thats cheating
@ slenkar - nah thats cheating
@ BladeRunner - nah that' s-Betrug

I made a simple Dijkstra's system it took 1ms to calc a path on a 20x15 grid (top-left to bottom-right - no obstuctions) and 20ms to calc a path on a 60x45 grid (top-left to bottom-right - no obstuctions) - as I am only goona be dealing with a 20x15 grid I think I am good.

As a test my atom based netbook also took 1ms to calc a 20x15 grid.

The Dijkstra's system in all cases found a equal or better path than my botched A*.

Would any one be interested in seeing my botched A* to see where I went wrong? its all indented and commented.


slenkar(Posted 2010) [#15]
yeah an A* competition in blitzmax would be fun


BladeRunner(Posted 2010) [#16]
GW - no intendation? This must be a rendering error of the browser as I posted the code with intendation and get it showed with it, too.
But to solve this problem:

What is wrong about tlink? I added the Tlinks to speed things up, and it gave some more Performance. It shouldn't be a problem though to alter the code without tlinks (as a matter of fact i added them last, before i used 'normal' tlist methods.
coffeedotbean: As you like, but if you change your mind feel free to use it.


Czar Flavius(Posted 2010) [#17]
I can't understand that code as it isn't commented in English. Is there any particular reason you comment a function as function?


BladeRunner(Posted 2010) [#18]
It was my style back then of commenting code- I split the Types in their subsets: Functions, Methods, globals and Data. Was just to keep some order in them.
I posted this code on the german board some time ago - maybe I# ll get into it and translate the comments some time. Sorry for the trouble, but I'm not often around here and therefor i use my native language most of the time in my codes.


GW(Posted 2010) [#19]
If you want speed, use pre-allocated arrays instead of a linked list.
This is the fastest astar implemented in bmax that I have encountered.