0

私は Netlogo と stackoverflow の両方に不慣れですが、あなたの他の投稿はすでに私を大いに助けてくれました。

私は現在、エージェントが空間をランダムにさまよい、出会うたびにエージェントを停止させるモデルをプログラムしようとしています。ここでの「会う」とは「すれ違うこと」を意味しin-radius 2ます。彼らはfaceお互いに、2 ティック待ってから、次のエージェントを見つけるまで動き続けます。

タイマーで NzHelen の質問を使用しようとしましたが、実際には成功しませんでした。

ここまでで、なんとか顔を合わせることができました。tick-command をコードの正しい場所に配置するのに問題があります。(編集: waitSeth のおかげで、これは -command を削除することで解決されました。 --> そして、すべてのタートルの動きを止めるのではなく、お互いに会っているタートルだけを動かしたくないのです)。私が目指しているもう 1 つのことは、彼らが会っている様子を視覚的に表現することです。たとえば、会っているときにパッチを点滅させたり、会ったときに彼らの周りに円を表示したりします。- コマンドを使用するwaitと、すべてが再び停止しますが、これを防止したいと考えています。

これまでのコードの下。

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   
4

2 に答える 2

1

同僚の助けを借りて、タイマーの問題を解決することができました。Seth が指摘したようwaitに、これは正しいコマンドではなく、あまりにも多くのto-endループが私のタートルを混乱させました。コードは次のようになり、機能します。亀は互いに近づき、向かい合い、形を星に変え、3 ティック待ってから反対方向にジャンプします。

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 
于 2014-03-10T17:49:50.250 に答える