View Single Post
 
Reply
Posted 2006-02-11, 10:15 AM in reply to Medieval Bob's post starting "When the function calls itself, how do..."
Medieval Bob said:
When the function calls itself, how do you make sure it's not going back to the same place? What if you had a circle of them? That would infinite loop...

*thinks* I guess I could get an array of grid locations and use it like a stack.

Start at 0,1: Store 0,1 in 'stack'
Find next at 1,1: Store 1,1 in 'stack'
Find next at 1,2: Store 1,2 in 'stack'
Find next at 2,2: Store 2,2 in 'stack'
Find next at 2,1: Store 2,1 in 'stack'
Find next at 1,1: 1,1 already exists in 'stack' do not take.

And then when I fall out of an iteration, I can set the most recent location in the 'stack' back to -1,-1. That may be hard to code correctly...

I suppose if I sat down and worked on it, I might find out... but meh. I'll do it later.
Yea, I ran across a problem with it bouncing between two spots. It wasn't a very elegant method to solve it, but I passed two more arguments to the function: the old r and the old c values, and made sure it didn't go back to that location. That made it work for me.

I guess you could have a parallell boolean grid and mark true false for spots you've been also . . . I haven't tried that though.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes