【发布时间】:2021-08-13 14:57:47
【问题描述】:
因此,我之前曾询问过补丁不存储某个邻居值的问题,多亏了 Matteo、JenB 和 Lena,我才得以进一步发展。 Sicen 那么代码已经进步了一点,因此我遇到了一个新错误。
首先,如果复制和粘贴,代码可以工作,但有两件事是必要的,我没有底片,所以有必要将中心更改为角落,我不知道如何不创建设置按钮,所以需要它.
现在,代码生成了 3 种颜色的 3 个区域,每个边框根据随机数移动。这样,靠近边界的海龟应该同时改变补丁的颜色和它自己的颜色,同时随机转动和移动。
问题是我不知道我错过了什么,但补丁确实改变了颜色,但乌龟没有改变或移动,说指令正在被补丁和补丁不移动,这是有道理的。但为什么?我设置了条件,如果海龟有一定的能量,那么他们应该做我要求的事情。
问题再次在于,将分号中的部分移动到 move-potrero。
turtles-own [energia]
patches-own
[bordear
abandono
reforestado
potrerizado
temperatura
humedad
dosel
]
breed [ potreros potrero ]
breed [ bordes borde ]
breed [ bosques bosque ]
to setup
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 [ reforestacion ]
ask patches [ deforestacion ]
ask patches [abandonacion]
ask patches [borderizacion]
if ticks >= 500 [stop]
tick
end
to reforestacion
if pcolor = 44 [
set reforestado count neighbors with [pcolor = 66] ]
if reforestado >= 3 [if random 100 <= 50 [
set pcolor 66
set temperatura 27 + random 3
set humedad 90 + random 5
set dosel 70 + random 10 ]
]
end
to deforestacion
if pcolor = 44 [
set potrerizado count neighbors with [pcolor = 35] ]
if potrerizado >= 3 [if random 100 <= 50 [
set pcolor 35
set temperatura 26.5 + random 3
set humedad 80 + random 10
set dosel 40 + random 10]
]
end
to abandonacion
if pcolor = 35 [
set abandono count neighbors with [pcolor = 44] ]
if abandono >= 3 [if random 100 <= 50 [
set pcolor 44
set temperatura 26.5 + random 3
set humedad 80 + random 10
set dosel 40 + random 10]
]
end
to borderizacion
if pcolor = 66 [
set bordear count neighbors with [pcolor = 44] ]
if bordear >= 3 [if random 100 <= 50 [
set pcolor 44
set temperatura 27 + random 3
set humedad 90 + random 5
set dosel 70 + random 10]
]
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
【问题讨论】: