Search code examples
netlogo

Face the nearest empty patch netlogo


I want to move some fish to the edge of a lake. The lake´s name is mallor so i established the edge like

set edge patches with [mallor = 1 and any? neighbors with [mallor = 0]]

Then

I have :

ask fish [face min-one-of edge[distance myself] fd 1

However, im noticing that alot of my fish are going to the same spot. To stop this i wanted to use

ask fish [face min-one-of edge[distance myself] with [not any? turtles] fd 1

but its not working, and i dont know whats the correct order to solve it

How would you do this?


Solution

  • The primitive you're looking for is turtles-here, not turtles

    Furthermore, you placed your with in the wrong location. It should come right after the patch-set to which it applies.

    Sometimes you might need brackets when combining with with other primitives. I don't know exactly when and where but Netlogo always corrects me with an error warning after which I can fix it, so for this specifically it's not too big of a deal.

    ask fish [face min-one-of edge with [not any? turtles-here] [distance myself] fd 1]

    Do keep in mind that your fish will be moving around while on the edge.