【问题标题】:Netlogo: Turtles inherit event from other turtlesNetlogo:海龟从其他海龟继承事件
【发布时间】:2014-01-30 14:37:31
【问题描述】:

如何让其他乌龟继承其他乌龟的事件?在我的代码中,我有一个简单的设置,它有 50 只海龟。我还有一个恐慌按钮,如果点击它,一些乌龟会将他们的情绪设置为恐慌并将颜色设置为橙色。

我对此进行了一些更改。忽略百分比。现在所有的海龟都会在他们周围检查,如果他们发现/看到了情绪 = 恐慌和橙色的海龟,它们也会恐慌并涂成橙色。

turtles-own[
 mood
]


to setup
  __clear-all-and-reset-ticks
  create-Humans
end


to create-humans
  crt 50[
    setxy random-pxcor random-pycor
    set color blue 
    set mood "calm"
  ]
end


to panic
  ask n-of initial-panic turtles [
    set mood "panic"
    set color orange
  ]

end

我试过了。

to go
  ask turtles[
    fd 1
    lt random 90]

  ask turtles[ 
    ask turtles in-cone 3 60
    [ if any? turtles with [ color orange]
        set mood "panic"] ]  

end

但它不起作用。

【问题讨论】:

  • “继承恐慌事件”是什么意思?您是否只希望 5% 的其他海龟将他们的情绪设置为“恐慌”并涂成橙色?您希望如何选择这 5%?
  • 是的,我希望他们设置为“恐慌”并且颜色为橙色。它们必须是随机选择的。
  • 你的意思是?询问 n-of (percent-of-affected * count turtles ) 海龟 [ set color orange ]
  • 我对这个做了一些改动。忽略百分比。现在所有的海龟都会检查他们是否发现/看到了情绪 = 恐慌和橙色的海龟,它们也会恐慌并涂上橙色。

标签: netlogo


【解决方案1】:

欢迎使用 StackOverflow,你可以试试这个:

turtles-own[
 mood
]


to setup
  __clear-all-and-reset-ticks
  create-Humans
  panic
end


to create-humans
  crt 50[
    setxy random-pxcor random-pycor
    set color blue 
    set mood "calm"
  ]
end


to panic
  ask n-of initial-panic turtles [
    set mood "panic"
    set color orange
  ]

end


to go


  ask turtles[ 

    fd 1
    lt random 90

    if any? turtles in-cone 3 60 with [ color =  orange]
      [set mood "panic"
        set color orange
      ]
  ] 

end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多