NetLogo:移动乌龟,直到找到最后一个补丁?

时间:2015-09-02 16:45:28

标签: debugging while-loop netlogo repeat do-while

我想让我的乌龟徘徊到energy级别< [totalattract] of patch-here。这里的代码工作正常:

to move-turtles
  ifelse ([totalattract] of patch-here < energy)
  [ rt random 90 lt random 90
    jump random 3
  ]
  [move-to max-one-of patches in-radius 3 [totalattract]
    ]
  if energy = 0 [die]
end

然而,我想让它在1个刻度内徘徊 - 从徘徊(跳跃)开始到跳跃结束时(当它的energy < [totalattract]补丁时){ {1}}在splotch in-radius X中修补最高move-it值。我正在尝试实施[totalattract]条件或while,但对于repeat我需要特定数量的移动,这个移动取决于乌龟的repeat和补丁的energy。我该怎么处理?我真的很感激每一个帮助或建议!!

1 个答案:

答案 0 :(得分:1)

如果您希望所有的海龟在1个刻度中执行他们的程序,您希望将tick语句放在go程序中。像这样:

to go
   ask turtles [move-turtles]
   ;Some other code here...
   tick
end

如果您只想让一只乌龟在1个勾号中执行其程序,则需要将tick语句放在move-tutle程序中。像这样:

to move-turtles
  ifelse ([totalattract] of patch-here < energy)
  [ rt random 90 lt random 90
    jump random 3
  ]
  [move-to max-one-of patches in-radius 3 [totalattract]
    ]
  if energy = 0 [die]
  tick 
end