视线NetLogo

时间:2014-10-30 22:34:00

标签: netlogo

如何在NetLogo中实现视线

  

乌龟计算/计算它与视线上给定斑块之间的所有海龟。

感谢。

4 个答案:

答案 0 :(得分:1)

让我们说每只乌龟有一个turtles-own被叫目标,这是给定的补丁,你可以让每只海龟面对目标补丁并计算它与给定补丁之间的所有乌龟:

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循环看起来不是很干净但是有效。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

与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

答案 3 :(得分:0)

我建议使用this answer中的patches-ahead记者:

to-report patches-ahead [ dist step ]
  report patch-set map patch-ahead n-values (dist / step) [ step + ? * step ]
end

你可以像这样使用它:

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
相关问题