我正在尝试在Netlogo中编写一个程序,该程序首先识别红色补丁的两个随机邻居,然后将这两个补丁更改为蓝色。网格上的补丁可以是红色,蓝色或白色。Netlogo Procedure n-of 2 neighbors
我把这段代码放在“去”部分,它使“tick”无效。它也似乎不在任何地方运行。
to run-2-neighbors-people
if all-voters-talked-2-people
[ ask n-of 2 neighbors with [ pcolor = red ]
[ set pcolor blue]
]
end
下面是完整的代码:
patches-own
[
vote ;; my vote (0 or >= 1)
total ;; sum of votes around me
]
to setup
clear-all
ask n-of (percentage-of-voters/100 * count patches) patches [
set vote 1 ]
ask patches [set-color]
ask patches [set initial-voters count patches with [ pcolor = red ] ]
ask patches [set non-voters count patches with [pcolor = white] ]
reset-ticks
end
to go
ask patches
[ set total (sum [vote] of neighbors) ]
ask patches [if pcolor = white
[if total >= 4 [set pcolor blue ] ] ]
ask patches [if pcolor = white
[if total < 4 [ set vote 0 ] ] ]
run-all-voters-talked-2-people
run-share-on-social-media
tick
end
to run-share-on-social-media
if share-on-social-media
[ask patches with [pcolor = red] [
sprout 1 [
set shape "arrow"]
]]
end
to run-all-voters-talked-2-people
ask patches with [pcolor = red] [
ask n-of 2 neighbors with [ pcolor = red ]
[set pcolor blue] ]
end
to set-color ;; patch color procedure
ifelse vote >= 1
[ set pcolor red ]
[ set pcolor white ]
end
这是什么“它使'剔'失效”是什么意思? –
@SethTisue它可能意味着当他添加了这段代码时,程序没有打勾,这可能是因为它没有终止。 –
我认为我们需要看到更多的代码,例如“所有选民说话的2人”程序是做什么的? –