ThomasC
ThomasC

Reputation: 881

How to move to a patch that is at least x distance from a turtle

I'd like to ask a turtle to move to any patch that is at least a distance of x away from another turtle. So in a mix of NetLogo and English it would be:

move-to one-of patches with [distance to nearest turtle > 4] 

How can this be done please?

Upvotes: 0

Views: 488

Answers (2)

ThomasC
ThomasC

Reputation: 881

Using all of the above, here is a solution:

to go
  ask patches [set nearest-turtle min-one-of turtles [distance myself]
    set distance-turtle distance nearest-turtle
    ]

  crt 1 [
    set color blue
    move-to one-of patches with [distance-turtle > 4]]

end

Upvotes: 0

Arthur Hjorth
Arthur Hjorth

Reputation: 889

You find the nearest turtle using the min-one-of + [distance myself] reporter. You also need to make sure that you only look at other turtles since a turtle will always be the turtle that is closest to itself.

The code can be broken up like this:

let nearest-turtle min-one-of other turtles [distance myself]
move-to one-of patches with [distance nearest-turtle > 4]

For (arguably) better readability.

edit: thanks Nicolas for the correction. You are totally right.

Upvotes: 1

Related Questions