与邻居一起计算品种(绘制)

Counting breeds with neighbors (to plot)

我有两个品种:supras 和 subs。

我想画两条线:

我该怎么做?我试过这个:

每个人口的数量总是0,不应该是这样的。这是我的代码:

breed [supras supra]
breed [subs sub]

turtles-own [age]
subs-own [status]

to setup
  clear-all

  ;; Color the patches so they're easier to see
  ask patches [ set pcolor random-float 2 ]

  ;; 1/2 of num-turtles patches will sprout subs
  ask n-of (num-turtles / 2) patches [
    if not any? turtles-on patch-set self [
      sprout-subs 1
    ]
  ]

  ;; 1/2 of num-turtles patches will sprout supras
  ask n-of (num-turtles / 2) patches [
    if not any? turtles-on patch-set self [
      sprout-supras 1
    ]
  ]

  ;; Set breed colors and own-variables
  ask subs [
    set color blue
    set shape "dot"
    set age 0
    set status random 10
  ]

  ask supras [
    set color pink
    set shape "dot"
    set age 0
  ]

  reset-ticks
end

to go

  ask turtles [
    let empty-patches neighbors with [not any? turtles-here]
    if any? empty-patches[
      let target one-of empty-patches
      face target
      move-to target
    ]
  ]

  ;; Mating conditions
  ask supras [
    if any? subs-on neighbors [
      ;; Mate with highest status sub
      mate
    ]
  ]

  tick
end

to mate
  move-to max-one-of subs [status]
end

neighbors returns patches 的代理集,所以说 neighbors = supras 不会得到你需要的东西 - 没有补丁是 suprassubs。相反,您想检查是否有任何邻居有 supras-heresubs-here。这对我有用:

plot (count ( subs with [ any? neighbors with [ any? supras-here ] ] ) ) /  ( count turtles )

plot (count ( supras with [ any? neighbors with [ any? subs-here ] ] ) ) /  ( count turtles )

您可能希望将 Y 最大值缩小到 1 以便看到更多内容。