【问题标题】:Test if the nearest turtle is in-radius测试最近的海龟是否在半径内
【发布时间】:2014-11-07 18:01:28
【问题描述】:

我试着问我的海龟:如果最近的海龟的半径低于“距离-min”(全局),那就出去吧!

但是下面的代码不起作用,我真的不明白为什么。

to go
 ask boeufs [get-out]
 tick
end

to get-out
  let x min-one-of boeufs in-radius distance-min [distance myself]
  ifelse (x != nobody) [
    face x
    rt 180
    fd 1
    set color red
 ]     
 [
   wiggle
 ]
end

似乎如果:x 等于乌龟本身…… 条件总是正确的,即使世界上只有 1 只乌龟,为什么? :/

【问题讨论】:

    标签: netlogo turtle-graphics


    【解决方案1】:

    您想使用other。它所做的只是获取一个代理集并从中删除当前代理。所以你的代码变成了:

    let x min-one-of other boeufs in-radius distance-min [distance myself]
    

    other boeufs 不会包含海龟本身,所以它永远不会被报告。

    【讨论】:

    • 太棒了!谢谢(再次)。
    • 也就是说,当我们使用“min-one”时,我们必须始终使用“other”。否则他总是回来的现任特工,对吧?
    • 这取决于你在为min-one-of做什么。例如,如果您正在执行min-one-of [ energy ] 或其他操作,您可能想知道当前代理的能量是否最低。但是,如果您的 min-one-of 引用 myself,那么您很可能想要使用 other
    • 好的,我明白了。谢谢。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多