我的补丁以绿色(65),黑色(0)或随机基色开始。每5个勾号,我希望将绿色的勾号更改为随机基色,将黑色的勾号保留为黑色,并将希望变成绿色的随机彩色勾号变为绿色(65)或更改为另一种随机色(其中一个除去55)。基本颜色)。
我正在努力实现最终功能(使用现有的随机彩色补丁的子集)。
我尝试了ifelse和不同的if语句,指定了问号中的n个补丁使绿色变为绿色,其余的变为随机颜色。这没有用。
to setup-patches ;;PATCHES
ask n-of 400 patches [ set pcolor 65]
ask n-of 600 patches [ set pcolor one-of remove 55 base-colors ]
end
......
to vary-patches
if ticks > 0 and ticks mod 5 = 0 [
ask patches [
if pcolor = 65 [
set pcolor one-of remove 55 base-colors ]
if pcolor = black [
set pcolor 0 ]
if pcolor = one-of remove 65 base-colors [
set pcolor ............................................. ]
end
答案 0 :(得分:0)
我认为您或多或少都在那儿,只是if pcolor = one-of remove 65 base-colors
有问题。每次评估该语句时,都会将pcolor
与one-of
生成的随机remove 65 base-colors
进行比较-不会检查是否在该组中找到了pcolor
。为此,您需要member?
原语。例如,下面的微小修改应该可以满足您的需求:
to setup-patches ;;PATCHES
ca
ask n-of 400 patches [ set pcolor 65]
ask n-of 600 patches [ set pcolor one-of remove 55 base-colors ]
reset-ticks
end
to vary-patches
if ticks > 0 and ticks mod 5 = 0 [
ask patches [
if pcolor = 65 [
set pcolor one-of remove 55 base-colors ]
if member? pcolor remove 65 base-colors [
set pcolor one-of base-colors
]
]
]
tick
end
编辑:
to vary-patches
if ticks > 0 and ticks mod 5 = 0 [
ask patches [
ifelse pcolor = 65 [
set pcolor one-of remove 55 base-colors
] [
if member? pcolor remove 65 base-colors [
ifelse random-float 1 < ( 1 / 3 ) [
set pcolor one-of base-colors
] [
set pcolor 65
]
]
]
]
]
tick
end