如何在NetLogo中实现视线
一只海龟计算/计数它和视线上给定的补丁之间的所有海龟。
谢谢。
发布于 2014-10-31 02:04:29
假设每个海龟都有一个名为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")
]while循环在NetLogo中看起来不太干净,但它可以工作。
发布于 2014-11-03 15:57:26
请参阅NetLogo模型库的代码示例部分中的视线示例。
发布于 2014-10-31 02:38:21
非常类似于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
Endhttps://stackoverflow.com/questions/26664511
复制相似问题