|
-
Jul 8th, 2003, 06:50 AM
#1
Thread Starter
Not NoteMe
Path-Finding
Hi all, here's the situation: (if you just want to get to my problem scroll down to the code listing)
I'm making a 2d tile-based game. All is going well, i have inhabited it with various monsters, created lots of maps etc. I'm now trying to expand the possibilities by adding a general path finding function to get from A to B in my map.
I have managed to use the A* algorythm in one type of my monsters fine. The only trouble is that on big maps it noticably slows down my game.
What i thought i could do is pre-calculate the direction to move to get from A to B.
This I have also managed to do, using the A* algorythm. However, as each calculation of a path is independent of the other this creates a huge pause when calculating all the paths (as the # of calculations required is GridWidth^2*gridheight^2).
My thought was that i could adapt the A* algorythm so that i didn't need to do similar calculations more than once.
Below is the algorythm i devised.
Create a closed list and an open list, for storing nodes
Code:
Loop through each node that the destination can see, adding them onto the open list
While the open list is not empty:
Get a node from the open list, then remove it from that list
If this node is in the closed list ignore it
For each node that this node can see:
If it's not on the open list then calculate it's distance from the destination via 'thisnode'
If it is on the open list check it's distance, and if it's better to go via 'thisnode' then update the distance
'At this point each node as its distance from the destination (i hope)
For each possible position on the grid:
Loop through each node that this position can see, finding the one with the shortest distance to the destination
Once we have the best node (shortest distance), store the direction we need to move in to get from our position to that node and store it
I hope you're still with me here. The implimentation i've put below doesn't work. I was just wondering if anyone could see anything wrong with the above algorythm, or my implimentation. FYI, everything is syntactically correct and the algorythm runs, it just doesn't work correctly.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|