我正试图通过靠近花朵来陶醉蜜蜂。毒性是一个花朵本身的变量,然而,我想将上述毒性的数量添加到蜜蜂的既定死亡率中。我得到的错误是毒性不是蜜蜂变量,这是真的,但我如何添加这一点。这个想法是,这种花有一定的毒性,如果有人靠近它,它就会醉倒,让他们更快地死亡。提前感谢,代码应该可以复制过去。
breed [flowers flower]
breed [bees bee]
turtles-own
[
mortality
tipo_exposicion
t_supervivencia
]
flowers-own [toxicity]
to setup
clear-all
create-flowers 5
[
set shape "flower"
set color red
set size 4
move-to one-of patches
]
ask patches [set pcolor 63]
create-bees 100
[
setxy random-xcor random-ycor
]
ask bees
[
set shape "person"
set size 1
set color yellow
set t_supervivencia 0
]
ask flowers [set color gray]
reset-ticks
end
to go
ask bees [
move-bees
]
ask bees[intoxicarse]
ask flowers [ morir_bees_eating]
tick
end
to move-bees
right random 60
forward 1
set t_supervivencia t_supervivencia + 1
set mortality mortality + 1
end
to intoxicarse
ask bees in-radius 10 [if any? flowers with [color = gray][
set mortality mortality + toxicity]]
end
to morir_bees_eating
if color = gray [set toxicity 34]
end发布于 2021-11-16 09:37:49
让我先“翻译”一下intoxicarse过程现在正在做的事情:
任何蜜蜂都会叫它。因此,假设它首先调用bee 1上的过程,然后查找半径为10的蜜蜂(ask bees in-radius 10)。对于每个接近的蜜蜂,它将在所有花朵(不仅仅是接近的花朵)的集合中搜索是否有灰色的花朵。如果世界上有任何灰色的花朵,所有接近蜜蜂1的蜜蜂都会增加它们的死亡率。
以下是关于如何更改代码的建议:
let创建一个代理集,其中包含所有灰色闭合的花朵。你可以将with.in-radius结合在一起,然后你可以用any?来观察它们的毒性。有一点,我不太清楚,当有不止一朵接近的花时,会发生什么。他们的毒性应该总结一下吗?还是应该只有一朵密密麻麻的花朵让蜜蜂陶醉?您可以使用sum或one-of. let close_flowers flowers in-radius 10 with [color = gray]
if any? close_flowers
[
let this_toxicity [toxicity] of one-of close_flowers ;get toxicity from one close flower
let this_toxicity sum [toxicity] of close_flowers ;sum of toxicity
set mortality mortality + this_toxicity
] 发布于 2021-11-16 17:24:35
我会让花儿叫醉鬼,写得更简单一些:
to intoxicarse
ask bees in-radius 10 [set mortality mortality + toxicity]
endhttps://stackoverflow.com/questions/69981844
复制相似问题