|
-
Apr 4th, 2001, 02:59 PM
#3
Frenzied Member
I didn't read your code too carefully because I don't really understand your situation, but if I understand what you are doing it's this:
Given a start and a destination, find all possible paths between them and return the shortest path.
Is that what you are doing?
If it is, this may be a little faster:
Create two global variable that contain 1)the number of steps used in a complete path from start to destination, and 2) an array of those steps that represent the path.
Find the first path from Start to Dest, and put number of steps it took in the first variable and the path itself in the array.
When searching the next path, along the way (for each step you take) compare the number of steps used so far to the number of steps in the global variable. As soon as the number of steps used in the current path equals the number of steps in the global variable, you can quit searching the current path and start searching the next path. If, however, you reach the destination before the steps equal the number in the variable, you have found a shorter path! So save the new number of steps in the variable and the path in the array. As you find shorter paths, the function will take less time to run (will quit when steps = GlobalSteps).
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
|