NetLogo:如何在正确的上下文中使用tick

时间:2016-02-23 17:53:11

标签: netlogo

我对NetLogo比较陌生,并且已经试图解决这个问题很长一段时间了。我有一个搜索路径算法,确定我的模型中每个乌龟(船)的最佳路径,将每个路径存储为单独的补丁列表。目标是让海龟沿着补丁列表遍历,同时让蜱计数器增加龟的每一步(即每次所有海龟从一个补丁移动到下一个补丁时都打勾) - 直到它到达目的地。看起来很简单,但出于某种原因,我似乎无法找出使用' tick'的正确方法。

这是我的代码对应于移动部分的示例(一旦已生成路径列表)。

to move
  tick
  ask-concurrent ships
    [
      while [length current-path != 0]
      [ 
        face first current-path
        move-to first current-path
        set current-path remove-item 0 current-path
        wait 0.08
      ]
    ]

end

目前,滴答计数器仅对整个模拟进行一次滴答。任何人都可以帮助我以不同的方式对此进行编码,以便每次乌龟(统称)从补丁移动到补丁时都会增加勾号吗? 任何帮助将不胜感激。

以下是调用move的代码部分

  to find-shortest-path-to-destination
  place-turtles
  label-destination
  foreach sort ships
 [ ask ? 
  [ 
    set path find-a-path current-waypoint target-waypoint
    set optimal-path path
    set current-path path  
  ]
 ]
  move
end

1 个答案:

答案 0 :(得分:2)

我会将您的代码更改为以下内容并将其移至重复块内。基本上,每个人一次移动1个路径单元,然后再次调用移动,然后调用下一个滴答事件

to move
     tick
     ask-concurrent ships with [length current-path != 0]
     [
        face first current-path
        move-to first current-path
        set current-path remove-item 0 current-path
        wait 0.08
     ]

end
to go
    while [any? ships with [length current-path != 0]] [move]
end