【发布时间】:2018-10-31 12:55:04
【问题描述】:
我对海龟/补丁上下文和观察者上下文之间的差异有疑问。 问题出现在我的代码的最后一行。我想要一定数量的补丁来做某事,这个数量由我在上面定义的变量定义。当我使用 ask n-of 5 个补丁时,它工作正常,但是当我用变量替换 5 时,它会给出一条错误消息(你不能在海龟/补丁上下文中使用 tick,因为 TICK 是仅观察者)。 有谁知道为什么它不起作用?
patches-own [kans-op-ontbossing]
to setup
clear-all
ask patches [if (random 100) < bosdensiteit [set pcolor green]]
ask n-of world-height patches with [pxcor = pycor][set pcolor blue]
ask n-of world-height patches with [pxcor = max-pxcor / 2] [set pcolor grey]
ask n-of aantal-nederzettingen patches with [pcolor != blue and pcolor != grey] [set pcolor white]
reset-ticks
end
to go
if ticks = 75 [stop]
ask patches [set kans-op-ontbossing ontbossingsgevoeligheid + houtprijs + vraag-naar-landbouwgrond]
ontbos
tick
end
to ontbos
ask patches with [pcolor = green and (pxcor > 30 or pycor > 30)]
[if count (neighbors4 with [pcolor = grey]) >= 1 or count (neighbors4 with [pcolor = blue]) >= 1 or count (neighbors with [pcolor = white]) >= 1
[if random 300 < kans-op-ontbossing [set pcolor brown]]]
ask n-of (kans-op-ontbossing / 10) patches with [pcolor = grey and pxcor = ((max-pxcor / 2) + ticks)][ask patch-at 1 0 [set pcolor grey]]
end
谢谢!
【问题讨论】:
标签: netlogo