如何要求乌龟移到最近的同一类别的斑块?

问题描述 投票:1回答:1

如果警察来访,我正在尝试改变有问题的年轻人的位置。该模型的设计是我设置了不同类别的补丁,有问题的年轻人(乌龟)占有“学校”或“超市”类别的补丁,如果警察(龟)访问此补丁,则有问题的年轻人应将其位置更改为类别为“学校”或“超市”的最近的补丁。我写的代码不起作用,它表明在警察拜访时年轻人不动的问题,它仍然占据着相同的位置。

任何帮助将不胜感激。

to change-location
  let nearest-police min-one-of police [distance myself]
  if distance nearest-police = 0 [
    let target-patch one-of patches with [category = "school" or category = "supermarket"]
    if  target-patch != one-of patches with [[category = "school"] of myself or [category = "supermarket"] of myself] and distance target-patch > 0 [
      go-to target-patch
    ]
  ]
end
netlogo
1个回答
2
投票

如果我正确解释了您的问题,则名为“ category”的补丁变量将使用“ school”,“ supermarket”和其他可能的选项的值。您想要的是将选择限制在与要求乌龟已经在其中的补丁具有相同类别的补丁中。

您的代码one-of patches with [[category = "school"] of myself or [category = "supermarket"] of myself]确实没有意义。如果这是应该选择具有正确类别的补丁的位,则将其替换为:one-of other patches with [category = [category] of myself]

© www.soinside.com 2019 - 2024. All rights reserved.