Python Walker - no retracing steps

How do I prevent a basic GHPython walker script from using the same points to walk?
I’m guessing the script would have to somehow create a point after comparing it to all previous points, which means that recursion would probably be better in formatting the walker right?

This is just pseudo-code, but a quick idea would be to have a class managing your agents’ visited points. Maybe something like this:

class Agent(Object):
    # list where visited points are stored
    VISITED_LOCATIONS = []
    
    # checking routine
    def location_visited(self, pt):
        if pt in VISITED_LOCATIONS:
            return True
        else:
            return False

    def do_walk(self, pt):
        #some walker routine....
        self.VISITED_LOCATIONS.append(pt)

    def request_new_point(self):
        # some routine that gets a new point for the agent

Then in the main-code you could do something like this:

if My_instantiated_agent.location_visited(pt) == True:
    # get new point...
    My_instantiated_agent.request_new_point()
else:
    # do normal walker routine...
    My_instantiated_agent.do_walk()

Again, just very basic pseudo code. I just got out of bed, please be gentle on me :wink:

M.

1 Like

Hmm I’m super new to ghpython coding,and I’m really not too sure how class structures work - can you walk me through how it’s working to store points into a list and comparing a point to all previously made points on a list?