首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加来自两个种类的Netlogo的变量

添加来自两个种类的Netlogo的变量
EN

Stack Overflow用户
提问于 2021-11-15 22:54:14
回答 2查看 37关注 0票数 1

我正试图通过靠近花朵来陶醉蜜蜂。毒性是一个花朵本身的变量,然而,我想将上述毒性的数量添加到蜜蜂的既定死亡率中。我得到的错误是毒性不是蜜蜂变量,这是真的,但我如何添加这一点。这个想法是,这种花有一定的毒性,如果有人靠近它,它就会醉倒,让他们更快地死亡。提前感谢,代码应该可以复制过去。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2021-11-16 09:37:49

让我先“翻译”一下intoxicarse过程现在正在做的事情:

任何蜜蜂都会叫它。因此,假设它首先调用bee 1上的过程,然后查找半径为10的蜜蜂(ask bees in-radius 10)。对于每个接近的蜜蜂,它将在所有花朵(不仅仅是接近的花朵)的集合中搜索是否有灰色的花朵。如果世界上有任何灰色的花朵,所有接近蜜蜂1的蜜蜂都会增加它们的死亡率。

以下是关于如何更改代码的建议:

  1. 使用let创建一个代理集,其中包含所有灰色闭合的花朵。你可以将with.
  2. if和in-radius结合在一起,然后你可以用any?来观察它们的毒性。有一点,我不太清楚,当有不止一朵接近的花时,会发生什么。他们的毒性应该总结一下吗?还是应该只有一朵密密麻麻的花朵让蜜蜂陶醉?您可以使用sumone-of.

代码语言:javascript
复制
  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
  ] 
票数 2
EN

Stack Overflow用户

发布于 2021-11-16 17:24:35

我会让花儿叫醉鬼,写得更简单一些:

代码语言:javascript
复制
to intoxicarse
  ask bees in-radius 10 [set mortality mortality + toxicity]
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69981844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档