Netlogo 如何让两个品种的海龟在同一窝中交替出没

Netlogo 如何让两个品种的海龟在同一窝中交替出没,netlogo,Netlogo,在这个蚂蚁模型中,我有两种海龟:未成年海龟和觅食海龟。现在所有的觅食者都会排成一列出来,后面跟着所有的未成年人(这是通过推迟最初的出发时间来完成的。我希望他们在出来时轮流出来,直到我的觅食者或未成年人用完为止 我曾尝试将询问海龟[if who>=ticks[stop]]作为围棋程序的第一步,但这使得所有海龟都从巢穴中爆炸出来,而不是只留下一个文件 to go ask foragers [ if who >= ticks [ stop ] ;; delay initial dep

在这个蚂蚁模型中,我有两种海龟:未成年海龟和觅食海龟。现在所有的觅食者都会排成一列出来,后面跟着所有的未成年人(这是通过推迟最初的出发时间来完成的。我希望他们在出来时轮流出来,直到我的觅食者或未成年人用完为止

我曾尝试将询问海龟[if who>=ticks[stop]]作为围棋程序的第一步,但这使得所有海龟都从巢穴中爆炸出来,而不是只留下一个文件

to go 
  ask foragers
  [ if who >= ticks [ stop ]  ;; delay initial departure
    wiggle
    fd 1 ]
  ask minors
  [ if who >= ticks [ stop ]  ;; delay initial departure
    ifelse color = white
    [ look-for-transporter ]
    [ hitchhike ]]
  tick
end

我希望觅食者和未成年者在离开巢穴时交替。现在所有的觅食者都会在未成年者离开巢穴之前离开。

who
在每只海龟被创造出来时,都会被分配到编号,并且与品种无关。因此,如果你创造10只觅食者,然后创造10只未成年者,你的觅食者将拥有
who
值s从0到9,您的未成年人的
who
值从10到19。因此,无论您先创建哪个品种(因此具有最小的
who
数字范围)将根据您的
开始移动,如果who>=滴答声…
代码。要使基于
who
的代码满足您的需要,您必须交替创建您的觅食者和未成年人

然而,一般来说,使用
数字有点限制-你可能会发现自己的变量更容易,或者用其他方式控制。例如,下面的设置在世界最左边创建了一个
巢穴补丁
,并将一些觅食者和未成年者移动到该补丁。海龟有一个名为的布尔变量de>在巢穴?可用于控制哪些海龟可以移动:

breed [ foragers forager ]
breed [ minors minor ]

globals [ last-left nest-patch ]
turtles-own [ at-nest? ]

to setup
  ca
  create-foragers 10 [ set color red ]
  create-minors 20 [ set color blue ]
  set nest-patch patch min-pxcor 0
  ask nest-patch [ set pcolor yellow ]
  ask turtles [
    move-to nest-patch
    set heading 90
    set at-nest? true
    pd
  ]
  set last-left minors
  reset-ticks
end
最初,所有海龟的
在巢?
设置为true。然后,您可以在您要求将其
在巢?
设置为
true
的每个品种的个体之间进行交替。请查看下面的示例,该示例在注释中有一些更详细的说明:

to go
  ; If there are any turtles on the nest patch with at-nest? set to true
  if any? ( turtles-on nest-patch ) with [ at-nest? ] [
    ; If both breeds are present on the nest patch, alternate back and forth
    ; between breeds to set at-nest? to false
    ifelse ( length remove-duplicates [breed] of turtles-on nest-patch = 2 ) [
      set last-left ifelse-value ( last-left = minors ) [ foragers ] [ minors ]
      ask one-of last-left with [ at-nest? ] [
        set at-nest? false
      ]
    ] [
      ; Otherwise, just ask one-of whichever breed is left to set at-nest? to false
      ask one-of turtles-on nest-patch [
        set at-nest? false
      ]   
    ]
  ]

  ; Ask any turtles who have at-nest? set to false to move
  ask turtles with [ not at-nest? ] [
    if heading != 90 [
      rt ifelse-value ( breed = minors ) [ 12 ] [ -12 ]
    ]
    if xcor > 0 and heading = 90 [
      rt ifelse-value ( breed = minors ) [ 12 ] [ -12 ]
    ]
    fd 1
  ]      
  tick
end
该代码输出如下内容: