Netlogo:设置一个变量为某一颜色的邻居个数



我只是想计算具有特定颜色的补丁并将该计数数添加到变量中。然后,如果邻居的数量超过阈值,补丁会改变颜色,但我得到一个预期2个输入的集合。我认为这是一个基本的问题,但阅读后我没有得到我需要的结果。

patches-own
[reforestar
;deforestar
;temperatura
;humedad
;dosel
]
to setup
clear-all
set-default-shape turtles "frog top"
ask patches with [
pxcor <= 30 and
pxcor >= min-pxcor and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 35 ;
]
;potrero
ask patches with [
pxcor <= 60 and
pxcor >= 30 and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 44 ;
]
;borde
ask patches with [
pxcor <= 90 and
pxcor >= 60 and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 66 ;
]
end
to go
ask patches [ deforestacion ]
end
to potrerizar
if pcolor = 44 [
ask patches [ set potrerizado count neighbors with [pcolor = 35] ]]


end
to deforestacion 
if potrerizado >= 3 [if random 100 <= tasa-deforestacion 
[set pcolor = 35]]

Thanks in advance

关于set,这确实是因为set期望两个输入:要设置的变量和它的新值,这两个输入之间没有任何其他符号-见这里。您在to setup中也正确使用了它。

在NetLogo中,=被用来评估条件(即它期望两个输入,一个在右边,一个在左边,并且它返回truefalse)。因此,写作

set pcolor = 35

相同
set true   ; if the patch has pcolor = 35, or
set false  ; if the patch has pcolor != 35.

这些在NetLogo中都没有意义。


至于其余的:目前,你的代码完全取决于在接口中设置的potrerizado的值:

  1. 如果小于3,什么都不发生;
  2. 如果它至少是3,补丁将有一定的机会变成棕色(set pcolor 35)。这意味着,它们迟早都会变成棕色。

在代码中,目前,to potrerizar从未使用过。

无论如何,我可以看到to potrerizar要求补丁更改potrerizado,这是global变量。

可能你想要的是potrerizado作为patches-own,而不是global,但这只是我的猜测基于我在这里看到的。


不那么重要的是,你有一些多余的条件:每个补丁都会有pxcor >= min-pxcor(以及你在to setup中拥有的类似条件)。

最新更新