首页 > 解决方案 > 如何在 Netlogo 中创建与海龟列表的链接

问题描述

我想用特殊的海龟列表从海龟 0 创建链接,例如 [2 7 6 5] 。此列表包含谁的海龟

ask turtle 0 [
create-link-with [2 7 6 5]

let result requester-list 
ask turtle 0 [
create-links-to result

标签: netlogo

解决方案


作为一般经验法则,不要who在 NetLogo 中使用。您不提供生成该who数字列表的代码,但最好有海龟列表,而不是海龟标识符列表。

这是一种方法(未经测试)。有更好的方法,但我认为这更具可读性:

foreach [2 7 6 5]
[ this-turtle ->
  ask turtle 0 [create-link-with turtle this-turtle ]
]

如果您改为使用代理集,您的代码将看起来更像这样:

let targets n-of 4 turtles
ask turtle 0 [create-links-with targets]

推荐阅读