我可以根据比较它们的变量值的结果将海龟引导到特定的补丁吗?

Can I direct a turtle to a specific patch based on the result of comparing their variable values?

我有 N 组海龟,它们拥有变量 group-id(1 到 N,N 在设置时定义,每组有 25 只海龟)。

开始时,每组海龟都会生成一个随机补丁,变量 patch-group-id 与海龟 group-id 匹配,如下所示:

let i 0
while [ i < n_groups ] [
    let x random 100
    let y random 100
    ask patch x y [ set patch-group-id i set pcolor gray ]
    create-turtles 25 [
      set group-id i
      setxy x y
    ]
    set i i + 1
  ]

海龟会四处走动,但在这个过程的稍后步骤中,我希望它们能搬回它们的“家”补丁。其他海龟也可能会改变它们的 group-id 和它们的家园补丁,我希望它们也搬到那里。

有什么方法可以按照…

Ask turtles [
Let target one-of patches with [patch-group-id = group-id]
]

然后问乌龟move-to还是跳到目标?

NetLogo 不喜欢这个 (‘Min-one-of expected this input to be a number block, but got a true/false block instead’),我认为可能还有其他问题。

patch-group-id是patches拥有的变量,group-id是turtles拥有的变量。所以你需要告诉 NetLogo group-id 补丁试图匹配到哪个。试试这个:

ask turtles
[ let target one-of patches with [patch-group-id = [group-id] of myself]
]

另一种方法是放弃 group-id 的想法,让每只海龟记住它的家园补丁。从概念上讲,这实现了一个组完全由其主补丁定义的想法。所以你的设置看起来像:

turtles-own
[ my-home
]

to setup
  clear-all
  ask n-of n-groups patches
  [ sprout turtles 25
    [ set my-home patch-here
    ]
    set pcolor gray
  ]
end

那么你永远不需要构建目标,你只需转到他们的变量 my-home。

如果您走这条路,您还需要更改使用 group-id 的代码。例如,你说有时海龟会改变它们的 group-id,而不是 set group-id [group-id] of ... 你会 set my-home [my-home] of ...