select 距离海龟 x 处的所有补丁

select all patches at distance x from turtle

我想 select 在模拟中与所有海龟随机生成距离为 eps 的所有补丁,并将它们的颜色重置为黄色。这实质上是在模拟中围绕每只海龟绘制了一圈补丁。我尝试了几种不同的选择但没有成功。通过仔细阅读这个论坛,我发现了一些看起来很有前途但仍然存在一些问题的代码(张贴在这里)。我感谢任何有关调整此代码或使用其他方法来解决此问题的建议。

let eps2 eps
foreach [ eps2 ]
  [
      ask patches with 
  [
        distance myself > eps2 - 0.5 and
        distance myself < eps2 + 0.5
  ]
  [
    set pcolor yellow
  ]
]

eps 是一个 turtle 变量,所以使用 let 命令可以避免在补丁上下文中使用 turtle 变量。

foreach 命令无法识别 eps,因为它不是常量,我可以在这里使用其他命令吗?

您可以使用 list(见下文),但是...为什么要列表?就目前而言,不需要使用列表。

to setup
  ca
  crt 1
  ask turtle 0 [test]
end
to test
let eps2 10
foreach (list eps2 )  ;you can use `list`
  [
      ask patches with 
  [
        distance myself > eps2 - 0.5 and
        distance myself < eps2 + 0.5
  ]
  [
    set pcolor yellow
  ]
]
end

附录:

由于您表示您实际上不需要该列表,您可以尝试以下操作:

to test2
  ca
  crt 1
  ask encirclingPatches turtle 0 10 1 [set pcolor yellow]
end

to-report encirclingPatches [#t #dist #width]
  let _w2 (#width / 2)
  report patches with [
    distance #t > #dist - _w2
    and
    distance #t < #dist + _w2
  ]
end