A few points, which should help you but do not necessarily solve all your problems:

1) In the outer loop condition,
Quote:
while (%current.x != %d.x && %current.y != %d.y) {

I'm sure you'll want to use OR instead of AND here, otherwise the algorithm will stop as soon as it hits the row or column that the end position is in (as opposed to the end position itself).

2) I think you moved around the test,
Quote:
if ($calc(%current.x + %a) == %d.x && $calc(%current.y + %b) == %d.y) { return 1 }

since you first posted the algorithm; it is now in the incorrect place, it should be in the most inner loop, for example right before the $clistexists test.

3) You're using %current.px and %current.py in /findpath, but these aren't set anywhere. Also, you're not moving the .px and .py variables along with the rest in /setcurrent. Both of these things will make it impossible to find out which path you actually took, when the algorithm is done (I assume that the code for that is not part of what you posted here).

4) In general, adding alot of /echo statements to see what's going on exactly, will help tremendously in the debugging process.

5) Use of hashtables will most likely speed up the whole algorithm considerably, although that will only be effective if you redesign the helper functions a bit.


Saturn, QuakeNet staff