用两个品种初始化 Netlogo 世界;每个补丁只有一只乌龟

Initialize Netlogo world with two breeds; only one turtle per patch

我正在尝试在 Netlogo 中建立一个世界,其中有两个品种,但每个补丁只有一只乌龟:

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 ]

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

  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"
  ]

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

  reset-ticks
end

to go

  ask turtles [
    fd 1
  ]

  tick
end

这似乎可行,但我无法确定它在技术上是否正确。编写什么测试可以确保我在初始化时没有包含多个海龟的补丁?

尝试将您的代码精简到完整示例所需的内容。

globals [num-turtles]
breed [supras supra]
breed [subs sub]

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

to setup
  clear-all
  set num-turtles 99
  ;; num-turtles patches will sprout one turtle each
  ask n-of (num-turtles / 2) patches [sprout-subs 1] 
  ask n-of (num-turtles / 2) patches with [not any? turtles-here] [
      sprout-supras 1
  ]
end

to test-setup
  if (int (num-turtles / 2) != count supras) [error "setup error: supras"]
  if (int (num-turtles / 2) != count subs) [error "setup error: subs"]
  if any? patches with [count turtles-here > 1] [error "setup error: patches"]
end

实际上我要建议一种不同的方法;与其随机 select 为一个品种设置一些斑块,为另一个品种设置一些斑块并试图相互避开,您可以只 select 最初发芽的全部斑块数量,然后将一半的海龟转化为另一个品种。

globals [num-turtles]
breed [supras supra]
breed [subs sub]

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

to setup
  clear-all
  set num-turtles 99
  ask n-of num-turtles patches [sprout-subs 1] 
  ask n-of (num-turtles / 2) subs [set breed supras]
  <procedures to set colours etc>
end