Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / A* Pathfinding, A beginners guide and still an Epic Fail.

Author
Message
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 15th Dec 2008 02:00
I have been trying to get my head round A* Pathfinding. After searching the forums and looking through the CodeBase I have managed to find a little on the subject mainly this website:

http://www.policyalmanac.org/games/aStarTutorial.htm

and IanM's A* Pathfinding functions.

I don't quite understand however how IanM's code actually works, to the point that learning from it as a reference has been impossible. Using the site I have listed as help I have managed to come up with the following example:



Looking through the article and what I have at the moment I cant tell if what I'm doing is completely wrong or If I'm just a little off and quite incomplete.

I'm not going for something fast and complicated just something simple, so I can really understand how it works.

If anyone has had any recent experience with this and could point me in the right direction it would be much appreciated. Even if its something as harsh as ' Your way off go back and look at.....'

Thanks for any time you can spare
Regards,
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Dec 2008 21:46
I agree - my code is certainly not the place to go to for learning A*.

Did you follow any of the links at the bottom of that page? Amit's site is the one I prefer, and has a good introduction, although you may find the rest of the explanation of A* to be a bit heavy going.

http://theory.stanford.edu/~amitp/GameProgramming/

Once you've read that, you'll understand when I say that my A* code uses a binary-heap for the open list, while the 'flood' search is a form of Dijkstra's that uses a queue for the open list. In both cases, the 'arena' also doubles up as the closed list.

A purist would probably say my A* isn't technically A*, but I say hey, it produces the same results

DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 15th Dec 2008 21:47
Still no luck trying to get this. I have tried to follow to article more specifically. Although I'm trying to avoid binary heaps for now.

It wont compile but at least you can see what I'm trying to do:


This post is starting to look like a 'please write my code for me' so I just wanted to reiterate that I'm not looking for any code, just a nudge in the right direction.
Thanks for anyone that can help.
Regards,
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 15th Dec 2008 21:54
Should of refreshed the screen to save a double post.

Thank you IanM for the link to Amit's A* Pages, that will defiantly help.
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 15th Dec 2008 22:37
After reading that Article My head is spinning so I'll take a rest, come back to it tomorrow and rewrite it. However just a few questions:

1)I'm using Stacks for the Open/closed list (trying to avoid binary heaps) Should I be using Ques? Or should I just be using a normal array and there is a better way to arrange via Smallest F Cost.

2)Am I working out the Manhattan distance correctly
Taking the Range of X - The Walls + The Range of Y - Walls * 10

3)Also concerning the cost of G, like the article I'm using 10 and 14 on the horizontals and diagonals respectively but am I assigning these values correctly?

Thanks again.
Regards,
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Dec 2008 13:28 Edited at: 16th Dec 2008 13:29
Using a binary heap is an optimisation - don't go there. Get an understanding of the algorithm and a working version before you do that.

The simplest implementations of the open list use an array - remember that you need to find the lowest-cost position each time. You simply search from top to bottom to identify the lowest cost and use that, removing it from the array at the same time.

One way remove it from the list is by copying over it with the last one in the array and reducing the array size by one.

I'd also suggest that you write functions for all handling of your open list. If you don't you'll have a heck of a job putting in other implementations later.

Something like this:


Manhatten distance is simply the blocks you need to travel:

I assume from what youve written that you are using integers and need to handle diagonals too, so multiply the result by 10.

DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 17th Dec 2008 00:23
Thank you IanM for taking the time to write that. Using what you have told me here and the article you gave me I have pieced together the following:


I'm currently getting an array out of bounds on 297.
So my question to anybody who may see this is; any obvious reason you can see for this?

At the moment I'm handling the ClosedList in the same way as I'm handling the Openlist (or at least How IanM showed me, see IanM's post).Using the Variable 'NeighborID' to identify it. Which is then inc every time the while loop repeats given a new ID/Neighbour each time.

I'll keep at it I'm sure I'll get it eventually I'm just posting just in case anybody is looking in on this post trying to learn from it, as well as to show people like IanM that I am grateful for the information and it is being put to good use.

Regards,
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Dec 2008 21:42
Take another read of your link - the summary part in particular.

Your search loop doesn't look much like the method described there: you are attempting to create the path as you go, and you've tried to take a shortcut by using Id's rather than coordinates (the Id's change constantly, that's why your code crashes out).

As I said before, don't try to optimise it, just get it working and get an understanding of it. Once it's working, you can then work on making it faster.

DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 19th Dec 2008 03:10
I haven't had much time to myself to sit down at my own computer and compile this, however taking into consideration what IanM said I have tried again with another attempt.

I'll save it onto my PC and compile it tomorrow. I just wanted to post something to show that I haven't given up just just that and this looks to be more on track. If I cant get it working this time then I'm going to just break it down into smaller parts and make sure they work correctly.

DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 19th Dec 2008 21:21
.....Still no joy.
For anyone that's looking in here is the function:



A couple of questions:
a)Am I over complicating this again. All the examples I have managed to see have used an OpenList and a Closed list. Should I somehow being doing all this on just the OpenList if I don't want to use Binary Heaps.

b)Can anyone see anything obvious I'm doing wrong, here is the Pseudo code I'm following
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 20th Dec 2008 15:08


I'm still haven't cracked it, but bored of this now lol. I'll install a msgbox plugin and try again later. I have a feeling I am missing the point somewhere, so for now I'm just going to leave it. What I had so far is there if anyone thinks they can get it to work your welcome to try but for now I'm done with it.

*grumble* bloody A*, piece of sh$% *moan*
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 20th Dec 2008 18:38
After downloading a MsgBox Pluggin I managed to get it working. Although with problems.
Here is an example of what I mean:



Use mouse click (1) to set a Start
Use ShiftKey to set an End point
Use ControlKey to draw walls

Use Space to draw path.

The Numbers on the grid are the X:Y of the Parent Nodes. Which if I understand right when thrown into reverse order will give me my path. For some reason when you exit from the program it will just crash. Might have something to do with no clearing/resetting some var. I will clean it up and post something cleaning in the future but for now this hopefully will be useful to anyone reading in on this post trying to learn from it.

Thank you IanM for your help as well.
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 20th Dec 2008 22:35 Edited at: 28th Dec 2008 14:55
Cleaning up things now, seems to be working so here you go:



<ahref="http://dsarchy.deviantart.com/">My deviant page </a>
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Dec 2008 14:54
Well done. You've accomplished something that a lot of people here haven't.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Dec 2008 03:45
Maybe too late, but here's the page I used to learn A*. I made my working demo with java however.


http://www.gamedev.net/reference/articles/article2003.asp

Login to post a reply

Server time is: 2024-11-24 16:39:47
Your offset time is: 2024-11-24 16:39:47