Netlogo 视线网络标志

Netlogo 视线网络标志,netlogo,Netlogo,如何在NetLogo中实现视线 海龟计算/计算它与视线上给定区域之间的所有海龟 谢谢 假设每只海龟都有一个名为target的海龟自己的,这是给定的补丁,您可以让每只海龟面对目标补丁,并计算它和给定补丁之间的所有海龟: ask turtles [ face target let n 1 let c 0 while [patch-ahead (n - 1) != target][ ask patch-ahead n [ if any? turtles-her

如何在NetLogo中实现视线

海龟计算/计算它与视线上给定区域之间的所有海龟


谢谢

假设每只海龟都有一个名为target的
海龟自己的
,这是给定的补丁,您可以让每只海龟面对目标补丁,并计算它和给定补丁之间的所有海龟:

ask turtles [
  face target
  let n 1
  let c 0
  while [patch-ahead (n - 1) != target][  
    ask patch-ahead n [
       if any? turtles-here [set c (c + 1)]
    ]
    set n (n + 1)
  ]
  print (word who " has " c " turtles on the line of sight")
]

在NetLogo中,while循环看起来不是很干净,但它可以工作。

与Dr_stein非常相似

To-report count-turtles-on-line-to[target]
 Let c 0
 Let d distance target
 Face target
 While d > 0
    [
    Let c c + count turtles-on patch-ahead d
    Let d d - 1
    ]
 Report c
End

请参阅NetLogo模型库的代码示例部分中的视线示例。

我建议使用前面的补丁程序reporter,其网址为:

您可以这样使用它:

to setup
  clear-all
  create-turtles 100 [ setxy random-xcor random-ycor ]
  ask turtles [
    let target one-of patches
    face target
    show (word
      count other turtles-on patches-ahead distance target 0.1
      " turtles between me and " target)
  ]
end

这是不对的。如果您尝试
ca crt 1[setxy-0.5-0.5设置目标补丁1]
然后运行代码,它会说视线上有一只乌龟。面片的对角线是√2,因此按1步可以将同一补丁计数两次。(它还可能错过某些面片的角点。)
to setup
  clear-all
  create-turtles 100 [ setxy random-xcor random-ycor ]
  ask turtles [
    let target one-of patches
    face target
    show (word
      count other turtles-on patches-ahead distance target 0.1
      " turtles between me and " target)
  ]
end