I am new to both, Netlogo and stackoverflow, but your other posts have already helped me a lot.
I am currently trying to program a model, where agents randomly wander a space and have them stop whenever they meet. "Meeting" here means "passing each other in-radius 2
". They should face
each other, wait for 2 ticks and then keep moving until they find the next agent.
I tried to use NzHelen's question on a timer, but did not really succeed.
So far, I managed to have them face each other. I have trouble putting the tick
-command at the right place in my code. (EDIT: This got solved by taking out the wait
-command, thanks to Seth. --> And I don't want all turtles to stop moving, but only the ones which are meeting each other).
One other thing which I am striving for is some kind of visual representation of them meeting, for instance have the patch blink for the time when they are meeting or a circle which shows up around them when they meet. With the wait
-command, everything stops again, which I want to prevent.
Below the code so far.
to go
tick
ask turtles
[
wander
find-neighbourhood
]
ask turtles with [found-neighbour = "yes"]
[
face-each-other
]
ask turtles with [found-neighbour = "no" or found-neighbour = "unknown"]
[ wander ]
end
;-------
;Go commands
to wander
right random 50
left random 50
forward 1
end
to find-neighbourhood
set neighbourhood other turtles in-radius 2
if neighbourhood != nobody [wander]
find-nearest-neighbour
end
to find-nearest-neighbour
set nearest-neighbour one-of neighbourhood with-min [distance myself]
ifelse nearest-neighbour != nobody [set found-neighbour "yes"][set found-neighbour "no"]
end
to face-each-other ;;neighbour-procedure
face nearest-neighbour
set found-neighbour "no"
ask patch-here [ ;; patch-procedure
set pcolor red + 2
;wait 0.2
set pcolor grey + 2
]
if nearest-neighbour != nobody [wander]
rt 180
jump 2
ask nearest-neighbour
[
face myself
rt 180
jump 2
set found-neighbour "no"
]
end