【问题标题】:Netlogo: ask patches in-radius but not the center patch itselfNetlogo:询问半径内的补丁,而不是中心补丁本身
【发布时间】:2020-02-06 05:11:13
【问题描述】:

我想用半径内的补丁制作东西,但不包括代理本身的补丁,中心补丁,所以我修改了模型库中的 Myself 示例:

to splotch
  ask turtles [
    ask one-of patches in-radius 2 with [not any? turtles-here] [
      set pcolor [ color ] of myself
    ]
  ]
  tick
end

但是这段代码也排除了其他带有海龟的补丁,所以它应该是这样的

to splotch
  ask turtles [
    ask one-of patches in-radius 2 [not self][
      set pcolor [ color ] of myself
    ]
  ]
  tick
end

但是这段代码不起作用,我不知道它是怎么回事。

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    您需要other 原语。但是,other 排除了相同类型的代理,并且您希望海龟排除补丁。因此,您需要获取ask 的相关补丁other 补丁。这是一种方法:

    to testme
      clear-all
      create-turtles 3 [setxy random-xcor random-ycor]
      splotch
    end
    
    to splotch
      ask turtles
      [ let mycolor color
        ask patch-here
        [ ask other patches in-radius 4
          [ set pcolor mycolor
          ]
        ]
      ]
    end
    

    如果你想要更像你做的方式,你可以创建一个局部变量来存储补丁,然后像这样排除它:

    to splotch
      ask turtles
      [ let mypatch patch-here
        ask patches in-radius 4 with [self != mypatch]
        [ set pcolor [color] of myself
        ]
      ]
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多