Netlogo:询问半径内的补丁而不是中心补丁本身

Netlogo: ask patches in-radius but not the center patch itself

我想用半径内的补丁制作东西,但不包括代理本身的补丁,中心补丁,所以我修改了模型库中的我自己的例子:

to splotch
  ask turtles [
    ask one-of patches in-radius 2 with [not any? turtles-here] [
      set pcolor [ color ] of myself
    ]
  ]
  tick
end

但此代码还排除了其他带有海龟的补丁,因此它应该类似于

to splotch
  ask turtles [
    ask one-of patches in-radius 2 [not self][
      set pcolor [ color ] of myself
    ]
  ]
  tick
end

但此代码无法正常工作,我不知道它应该如何工作。

您需要 other 原语。但是,other 排除了相同类型的代理,而您希望海龟排除补丁。因此,您需要获取 askother 补丁的相关补丁。这是一种方法:

to testme
  clear-all
  create-turtles 3 [setxy random-xcor random-ycor]
  splotch
end

to splotch
  ask turtles
  [ let mycolor color
    ask patch-here
    [ ask other patches in-radius 4
      [ set pcolor mycolor
      ]
    ]
  ]
end

如果你想要更像你这样做的方式,你可以创建一个局部变量来存储补丁,然后像这样排除它:

to splotch
  ask turtles
  [ let mypatch patch-here
    ask patches in-radius 4 with [self != mypatch]
    [ set pcolor [color] of myself
    ]
  ]
end