0

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   
Community
  • 1
  • 1
T-Saurus
  • 29
  • 4
  • it's really hard to read code when there's a bunch of commented out code in it and the indentation is all over the place. that might be why no one has tried to answer this — it's a lot of code to read and you're not making it easy. – Seth Tisue Mar 08 '14 at 06:42
  • One thing that jumps out at me is that you definitely don't want to be using `wait` at all. Everything stops while even one turtle does `wait`. – Seth Tisue Mar 09 '14 at 02:59
  • Those are both very helpful comments, thank you very much. I try to edit it accordingly. – T-Saurus Mar 09 '14 at 09:57
  • Much clearer now, thanks. – Seth Tisue Mar 09 '14 at 13:31

2 Answers2

1

With the help of a colleague I managed to solve my timer-issue. As Seth pointed out wait was not the right command and too many to-end-loops confused my turtles as well. The code now looks like the following and works. The turtles get close to each other, face each other, change their shape to stars, wait three ticks and then jump in the opposite directions.

to setup

  clear-all 
 ask turtles 
   [
     set count-down 3
     ]
reset-ticks

end 
;---------
to go

 ask turtles 
  [    
   if occupied = "yes" [
     ifelse count-down > 0 
[
       set count-down (count-down - 1)
       set shape "star"
     ][
       set shape "default"
       rt 180
       fd 2
       set occupied "no"
       set count-down 3
     ] 
   ]

   if occupied = "no" [
     ; Wandering around, ignoring occupied agents

     set neighbourhood other turtles in-radius 2

     ; If someone 'free' is near, communicate!

     set nearest-neighbour one-of neighbourhood with-min [distance myself]
     ifelse nearest-neighbour != nobody [
         if ([occupied] of nearest-neighbour = "no") [
            face nearest-neighbour            
            set occupied "yes"
            ask nearest-neighbour [ 
              face myself              
              set occupied "yes"
           ]]
     ][
       ; No one found, keep on wandering
       wander
     ]]] 
   tick 
   end
;-------
;Go commands      

to wander
      right random 50
      left random 50
      forward 1   
end 
T-Saurus
  • 29
  • 4
0

You're right to link to Nzhelen's question. Essentially the answer to your question is that you need to do the same thing. When you tried to do that, you were on the right track. I'd suggest taking another stab at it, and if you get stuck, show us exactly where you got stuck.

Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
  • I had some help from a colleague and we managed to solve the issue. Not that I am not stuck at the next step now, but I think I can close this question... How can I do that? – T-Saurus Mar 10 '14 at 15:00
  • You can answer your own question and post your code, since the solution might be helpful to others. Or for closing, see http://meta.stackexchange.com/questions/37752/how-do-i-close-my-own-question – Seth Tisue Mar 10 '14 at 16:36