【发布时间】:2021-10-01 17:35:40
【问题描述】:
我在以前的帖子中已经解决了这个问题,但我遇到了一个新问题。我试图放弃恢复过程。一开始橙色和蓝色的流动很快,但一旦它们相互作用就没有胜利,只是在它们之间一遍又一遍地变化。在代码中,我确定如果一个补丁是橙色并且它看到至少 3 个蓝色,它应该变成蓝色,我没有确定如果一个蓝色补丁被橙色包围它会改变,但是它会发生。这个想法是,在设置时我有 3 种颜色,并带有一些滑块(如果 reforestado >= 3 [如果随机 100
此代码可以复制和粘贴,它应该可以工作,忽略出现的红色补丁。请设置世界的垂直界限。
为什么橙色不输蓝色?
提前致谢。
patches-own
[bordear
abandono
reforestado
potrerizado
temperatura
humedad
dosel
]
breed [ potreros potrero ]
breed [ bordes borde ]
breed [ bosques bosque ]
to setup
resize-world 0 90 0 60
clear-all
ask patches with [
pxcor <= 30 and
pxcor >= min-pxcor and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 35
set temperatura 26.5
set dosel 1
set humedad 90.4
]
;Potrero
ask patches with [
pxcor <= 60 and
pxcor >= 30 and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 44
set temperatura 29
set dosel 84.3
set humedad 79.3;
]
;Borde
ask patches with [
pxcor <= 90 and
pxcor >= 60 and
pycor <= 60 and
pycor >= min-pycor ] [
set pcolor 66
set temperatura 26.3
set dosel 85.2
set humedad 94 ;
]
;Bosque
;se establece la forma de la rana
; Se establecen las condiciones de las ranas, tamaño color y lugar de aparicion. La energia sera igual en todas las ranas en el set up.
create-potreros 50
[ set size 3 ;; easier to see
set color yellow
setxy random xcor random ycor
move-to one-of patches with [pcolor = 35]
set heading random 45 + 45
set energia 50
] ;; red = not carrying food
;Potrero
reset-ticks
end
to go
ask potreros [
if energia < 50 [descansar-potrero]
if energia >= 50 and energia <= 80 [move-potrero]
if energia > 80 [ if ticks mod 50 = 0 [reproducirse]]
set heading random 270
fd 1
set energia energia - 2
morir]
ask patches [ restauracion ]
ask patches [ deforestacion ]
ask patches [abandonacion]
ask patches [borderizacion]
if ticks >= 500 [stop]
tick
end
to restauracion
if pcolor = 44 or pcolor = 25 or pcolor = 35[
set reforestado count neighbors with [pcolor = 66 or pcolor = 75] ]
if reforestado >= 3 [if random 100 <= 100 [
set pcolor 75
set temperatura 24.4 + random 3
set humedad 91 + random 9
set dosel 82 + random 5 ]
]
end
to deforestacion
if pcolor = 44 or pcolor = 25 or pcolor = 75 or pcolor = 66 [
set potrerizado count neighbors with [pcolor = 35] ]
if potrerizado >= 3 [if random 100 <= 0 [
set pcolor 35
set temperatura 22.7 + random 5
set humedad 84.5 + random 10
set dosel 0 + random 10]
]
end
to abandonacion
if pcolor = 35 [
set abandono count neighbors with [pcolor = 44 or pcolor = 25] ]
if abandono >= 3 [if random 100 <= 50 [
set pcolor 25
set temperatura 24.6 + random 8
set humedad 68 + random 14
set dosel 79 + random 9]
]
end
to borderizacion
if pcolor = 66 [
set bordear count neighbors with [pcolor = 44] ]
if bordear >= 3 [if random 100 <= 50 [
set temperatura 24 + random 6
set humedad 80 + random 20
set dosel 80 + random 5]
]
end
to move-potrero
ask neighbors in-radius 2
[if temperatura >= 28.6 or temperatura <= 22.6 or dosel >= 5 or humedad <= 84
[ set pcolor red
;facexy random 30 random 60
;fd 5
;set energia energia - 10]]
;[ask potreros [descansar-potrero]]
]]
end
to descansar-potrero
ifelse pcolor = 35 [
set energia energia + 6]
[set energia energia + 1]
end
to reproducirse
if energia > 80 [ if random 100 > 60 [set energia energia - 70
hatch 1 [ rt random-float 360 fd 2
set energia energia / 3]]]
end
to morir
if energia <= 1 [die]
end ```
【问题讨论】: