如何将链接的海龟移动到 Netlogo 中链接的海龟之一的位置?
How can I move linked turtles to the location of one of the linked turtles in Netlogo?
我用海龟创建了一个模型,这些海龟被组织成带有链接的组。
现在我想将这个“组”的所有链接海龟移动到组中一个成员(可以是随机的)的位置。
我尝试了不同的方法,但结果不是我想要的。这是我试过的:
breed [AT1 AT1_1]
turtles-own [home-location]
to meet
ask AT1 [
let group-home one-of [home-location] of link-neighbors
move-to get-home
是否可以使用链接或 should/can 我还生成了 turtles-own 组?
除非你做的事情真的很花哨,否则每只海龟的位置已经始终作为变量 xcor 和 ycor 拥有。您不需要创建新的变量 home-location。
因此,如果您只想让 AT1 中的所有海龟都聚集到其中一只海龟现在所在的位置,这会起作用:
to meet
let target one-of AT1
ask AT1 [
move-to target
]
end
请注意,设置目标是在“询问 ATI”循环之外进行的,否则您将无法获得想要的结果。
如果你真的有每只乌龟的“家位置”可能与它现在所在的位置不同,那么它需要是 x 坐标和 y 坐标的列表,或者你需要两个变量像 home-location-x 和 home-location-y .
如果你这样做,那么这将作为满足代码工作;
to meet2
let target one-of AT1
let tx [home-location-x] of target
let ty [home-location-y] of target
ask AT1 [ setxy tx ty ]
end
我用海龟创建了一个模型,这些海龟被组织成带有链接的组。
现在我想将这个“组”的所有链接海龟移动到组中一个成员(可以是随机的)的位置。
我尝试了不同的方法,但结果不是我想要的。这是我试过的:
breed [AT1 AT1_1]
turtles-own [home-location]
to meet
ask AT1 [
let group-home one-of [home-location] of link-neighbors
move-to get-home
是否可以使用链接或 should/can 我还生成了 turtles-own 组?
除非你做的事情真的很花哨,否则每只海龟的位置已经始终作为变量 xcor 和 ycor 拥有。您不需要创建新的变量 home-location。
因此,如果您只想让 AT1 中的所有海龟都聚集到其中一只海龟现在所在的位置,这会起作用:
to meet
let target one-of AT1
ask AT1 [
move-to target
]
end
请注意,设置目标是在“询问 ATI”循环之外进行的,否则您将无法获得想要的结果。
如果你真的有每只乌龟的“家位置”可能与它现在所在的位置不同,那么它需要是 x 坐标和 y 坐标的列表,或者你需要两个变量像 home-location-x 和 home-location-y .
如果你这样做,那么这将作为满足代码工作;
to meet2
let target one-of AT1
let tx [home-location-x] of target
let ty [home-location-y] of target
ask AT1 [ setxy tx ty ]
end