Reputation: 37
I am creating a code where turtles need to find partners. This is the procedure:
patches-own [occupied?]
turtles-own [partner fed?]
to find-partners
let singles turtles with [partner = nobody]
if not any? singles [ stop ]
ask singles
[ lt random 50
rt random 50
fd 1 ]
ask turtles
[
if (partner = nobody) and (any? other turtles in-radius 1 with [partner = nobody])
[ set partner one-of other turtles in-radius 1 with [partner = nobody]
ask partner [
set partner myself
]]]
end
I want this procedure to take place in 1 tick, but it takes ~500. How can I correct this?
Upvotes: 0
Views: 196
Reputation: 10291
Hard to say exactly without your setup, but it seems like while
is what you want. Try replacing if not any? singles [stop]
with while any? singles [
The idea is that while there are any singles around, keep running this loop. Be careful, because if the "while" condition is never satisfied, the model will be stuck in the while
loop. Therefore, you also need to include the line set singles turtles with [ partner = nobody ]
within the while loop. So all together, something like
to find-partners
let singles turtles with [partner = nobody]
while [ any? singles ] [
ask singles
[ lt random 50
rt random 50
fd 1 ]
ask turtles
[
if (partner = nobody) and (any? other turtles in-radius 1 with [partner = nobody])
[ set partner one-of other turtles in-radius 1 with [partner = nobody]
ask partner [
set partner myself
]]]
set singles turtles with [partner = nobody]
]
end
Upvotes: 1