Laff. I was musing on exactly that the other day... trying to see if I could reliably limit the size of the array w/ avoids. I couldn't do it in any way that would save time. Maybe we can get a "max stack size" option variable here? Not sure if that'd really save time tho, it might be the variable inits that take the most time.
Anyway...
I thought of the course to terra thing and I don't think so. Why? Because as the number of avoids grows, the path to terra will increase and more sectors will need to be checked for the course to be found. Still there's only 1 way to know for sure, and that's to test both variations. I don't know how efficient getCourse is w/ all of this under such conditions. The above variation is the one that EP proposed a while back.
I was hoping that 2.04 would have the ability to get the bubbles from twx into an array. That would greatly simplify this and speed it up. But oh well... laff. Can't have everything. Put that on my 2.05 wishlist tho! =)
If you have a gate already then yea, avoiding the first hop out in all paths to terra until there is none out, followed by a BFS, would pull up all of the sectors in the bubble. This could then, for instance, give you a grid list. Now that getCourse is fast, it would probably be the optimal way of doing that.
As for all hops within 2 distinct sectors, you can do it a lot of ways. For simplicity I'd do a getAllCourses from each target sector (like dock, terra, etc) and just test against that. But really only if I'm planning to test a lot of sectors. On my tests it takes like 500ms to do a getAllCourses... and a getCourses only takes about 1ms. So there's no doubt that if you're only doing 10 sectors, that'd not be very effective compared to just getCourses.
One of the nice things about the way the stack is set up is that once you've gone over the max hop distance, you're past the max hop range for all sectors. That can cut out a lot of work.
On the fly...
Code:
getAllCourses $distances 1
getNearestWarps $stack 1
setVar $pointer 1
while ($pointer <= $stack)
if ($distances[$stack[$pointer]] > 10)
subtract $pointer 1
goto :turtle
end
add $pointer 1
end
:turtle
Now you've got a $pointer, from 1 to $pointer you've got a list of sectors within 10 hops. Don't even need to rewrite the list.
There is another way. That's what's called a "binary chop" search. I'll type up some code on that later but what it does is pick a midpoint in a list, test it, and adjust the midpoint. This way you can find a target in log time. I'm pretty sure I could find a target hop distance in under 500 searches that way, which means I could probably shave off quite a bit of time if I'm just looking to cull a getNearestWarps list down the "all hops within X."
Oh, you'll notice in my parms list that some stuff, dist to/from terra and stock and the like, I tend to store as parms. I'm getting concerned about the size of my DB tho and might go back to storing that as a file (similar to CK's figfile approach) if it'll trim it down. You could cache a bunch of key sectors as a file that way, just do the search once, and then call it up as needed.