我試圖靠靠近花朵來使蜜蜂陶醉。毒性是花自身的變數,但是,我想將所述毒性的數量添加到蜜蜂的既定死亡率中。我得到的錯誤是毒性不是蜜蜂變數,這是真的,但我如何添加它。這個想法是,這種花有一定的毒性,如果有人靠近它,它就會陶醉,使它們死得更快。提前致謝,代碼應該可以復制過去。
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
uj5u.com熱心網友回復:
讓我先“翻譯”一下intoxicarse程式現在在做什么:
它被稱為任何蜜蜂。所以假設首先它呼叫蜜蜂 1 上的程序。然后,它尋找半徑 10 ( ask bees in-radius 10)內的蜜蜂。對于每一個接近的蜜蜂,如果有灰色的,它會在所有的花(不僅僅是接近的)中搜索。如果世界上有任何花是灰色的,那么所有接近蜜蜂 1 的蜜蜂都會增加它們的死亡率。
以下是有關如何更改代碼的建議:
- 創建一個帶有 的代理集
let,其中包含所有帶有灰色的關閉的花朵。您可以組合in-radius和with。 - 如果有接近的花 (
any?) 那么你可以得到它們的毒性of。有一點,我不清楚的是,當有不止一朵靠近的花時會發生什么。他們的毒性應該總結嗎?還是應該只有一朵接近的花朵才能使蜜蜂陶醉?您可以使用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
]
uj5u.com熱心網友回復:
我會讓花叫 intoxicarse 寫得更簡單
to intoxicarse
ask bees in-radius 10 [set mortality mortality toxicity]
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358053.html
