【问题标题】:Two turtles running 'similar' code at the same time两只海龟同时运行“相似”代码
【发布时间】:2016-02-05 14:39:30
【问题描述】:

我的代码运行时遇到了这个奇怪的问题。

在我的模型中,我有女性(将女性设为真)和男性(将男性设为真)。

在特定的触发条件下,每个人都会“变成”一个分散器(设置分散器为真)。

分散剂和非分散剂具有非常不同的行为。

我尝试用代表这两个类别的不同品种来解决这个问题,但这也没有奏效。

问题是其中一只乌龟,例如雄性,会在遇到对面的乌龟时进行相应的操作并将分散器设置为“假”。但是另一个不会,并且会继续分散器设置为“真”

我确定这是因为一旦其中一只海龟操作代码,它就不再是“分散器”,因此不再适用于后来海龟的搜索条件,但我尝试过的每一项工作都导致了同样的问题或者没有人出错。

to search-for partner
    if male = true [ set potential-mates other turtles with [female = true
    and disperser = true]
    if female = true [ set potential-mates other turtles with [male = true
    and disperser = true]

    let chosen-mate min-one-of potential-mates [distance myself]

    if any? potential-mates [
        set heading towards chosen-mate]

    if male = true [ if any? other turtles-here with [female = true and
        disperser = true] [set disperser false]

    if female = true [ if any? other turtles-here with [male = true and
        disperser = true] [set disperser false]
end

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    我并不完全相信我知道你想做什么,但我认为你要求将两只海龟的 disperser 设置为 false。在这种情况下,您需要看起来像这样的代码(未经测试):

    if male
    [ let my-partner one-of other turtles-here with [female and disperser ]
      if my-partner != nobody
      [ set disperser false
        ask partner [ set disperser false ]
      ]
    ]
    

    您可能还应该考虑将“搜索合作伙伴”代码与“找到合作伙伴”代码分开。此外,您最好让他们检查他们是否有合作伙伴,然后通过将标题设置为最近并向前移动来搜索合作伙伴。目前他们环顾四周,但哪里也不去。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2020-09-15
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多