【问题标题】:How to randomly select two patches from neighbors4 in NetLogo如何在 NetLogo 中从邻居 4 中随机选择两个补丁
【发布时间】:2014-11-17 09:55:05
【问题描述】:

我正在尝试随机选择 2 个邻居,就像我们可以从 "neighbors" 命令中选择 8 个邻居,类似于我们使用 neighbors4 命令选择 4 个邻居,但是如果我们只想从8 个邻居。

我想做这样的事情:

ask n-of 2 patches from neighbors with [pcolor = white]
  [set pcolor blue]

但是,由于没有from 命令,所以我不知道它是如何工作的。

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    你很亲密!你想要的是:

    n-of 2 neighbors with [pcolor = white]
    

    但是如果白人邻居可能少于两个怎么办?在这种情况下,我建议使用at-most-n-of reporter defined in this answer

    【讨论】:

      【解决方案2】:

      这个问题你自己基本解决了:

      neighbors(或者在您的情况下为 neighbors with [condition])返回 n-of 期望的代理集,所以您只需要

      [
       ask n-of 2 neighbors with [pcolor = white] [ set pcolor blue ]
      ]
      

      .

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多