Netlogo Cyle使用turtle_index

时间:2017-03-25 16:06:22

标签: cycle

我正在使用turtle_index代码在Netlogo中创建一个循环。这个循环有效,但一次只使用一只乌龟。每只乌龟在下一只乌龟开始循环之前完成循环。我希望所有的乌龟同时参与这个循环。有没有比使用更快的方式实现这一点:

to go  
  ask turtle 1 [cycle-forward] 
  wait 0.5 
  ask turtle 2 [cycle-forward] 
  wait 0.5 
  ask turtle 3[cycle-forward] 
end

1 个答案:

答案 0 :(得分:0)

好的,你的评论我想我明白了。解决这个问题的一种方法是拥有turtles-own个变量,这样龟就知道他们做了什么步骤,以及他们是否对当前的滴答作出了反应。这样,他们就不会做出任何一步之遥。然后,您可以将周期分解为步骤并使用逻辑运算符,这样如果乌龟不符合您设置的某些条件,则不会采取措施。例如:

turtles-own [
  step1?
  step2?
  step3?
  acted?
]
to setup

  ca
  reset-ticks
  crt 10 [
    set step1? false
    set step2? false
    set step3? false
    set acted? false    
  ]

end

to go
  ask turtles [
    set acted? false
  ]
  cycle
  tick

end

to cycle
  let step1t one-of turtles with [ step1? = false ]
  if step1t != nobody [
    ask step1t [
      set step1? true
      set acted? true
      ;;; example step 1
      set color red
      set heading 45
      fd 3
    ]    
  ]

  let step2t one-of turtles with [step1? = true and step2? = false and acted? = false]
  if step2t != nobody [
    ask step2t [
      set step2? true
      set acted? true
      ;;; example step 2
      set size 1.5
      set heading 90
      fd 3
    ]
  ]

  let step3t one-of turtles with [step2? = true and step3? = false and acted? = false]
  if step3t != nobody [
    ask step3t [
      set step3? true
      set acted? true
      ;;; example step 3
      set color color + 2
      set heading 135
      fd 3
    ]
  ] 
end