如何每10个蜱虫创造新一代的海龟?

时间:2016-06-06 20:38:34

标签: netlogo

我正在尝试在NetLogo中执行以下操作:

  1. 我使用每个品种的滑块创建100只带有品种A的海龟和100只带有品种B的海龟
  2. 询问有品种A的龟和品种B随机移动等等。
  3. 10个蜱虫后,A和B品种的海龟死亡(成功完成这项工作)
  4. 创建/生成具有品种A和B的新100只龟,随机移动等等。
  5. 重复步骤3
  6. 基本上,我想问老一代的海龟在10个蜱虫后死亡并创造新一代的100只海龟品种A和100​​只海龟品种B.如何在每10个蜱虫中自动重复多次蜱虫(例如3000)?

    非常感谢您的帮助。

    以下是代码的一部分:

    breed [ honest-citizen honest-citizens ]
    breed [ potential-offender potential-offenders  ]
    
    …
    
    to setup
      clear-all
      reset-ticks
      ask patches [ set pcolor black ]
    
      set-default-shape honest-citizen "circle"
      create-honest-citizen initial-number-honest-citizens ;;create honest citizens then initialise their variables
      [
        set color white
        set size 0.2
        set income income-from-work
        setxy random-xcor random-ycor
        set birth-tick ticks
      ]
    
      set-default-shape potential-offender "circle"
      create-potential-offender initial-number-potential-offenders
      [
        set color red + 1
        set size 0.2
        ;; set income a random number between two extremes using formula
        ;; random (max-extreme - min-extreme + 1) + min-extreme
        set income random ((income-from-work + alfa-constant) - (income-from-work - alfa-constant) + 1) + (income-from-work - alfa-constant)
        setxy random-xcor random-ycor
        set birth-tick ticks
      ]
    
      set-default-shape government-agent "circle"
      create-government-agent initial-number-law-enforcement-agents
      [
        set color yellow + 1
        set size 0.2
        setxy random-xcor random-ycor
      ]
    
    end
    
    to go
     if not any? turtles [ stop ]
     if ticks > 3000 [ stop ]
    
    
     ask government-agent [
        count-number-of-workers
        count-number-of-criminals
        calculate-tax-per-worker
        calculate-probability-of-conviction
        move
      ]
    
      ask potential-offender [
        move
        set net-income income
        ;; if decide to become criminal then commit crime, else work legally and pay tax
        decide-commit-crime
        death ;; occurs when arrested and after 10 periods of time
      ]
    
      ask honest-citizen [
        move
        set net-income income-from-work
        pay-tax
        death ;; after 10 periods of time
      ]
    
      tick
    end
    
    …
    
    to move
      rt random 50
      rt random 50
      fd 1
    end
    
    to death
      if ticks - birth-tick > 10 [
      die
      ]
    end
    

1 个答案:

答案 0 :(得分:1)

如果您想要发生某些事情"每个 n 打勾",您通常可以使用mod。这是一个完整的例子:

breed [ as a ]
breed [ bs b ]

globals [
  ; those would be sliders in your model
  number-of-as
  number-of-bs
]

to setup
  clear-all
  set number-of-as 100 
  set number-of-bs 100
  create-as number-of-as 
  create-bs number-of-bs
  reset-ticks
end

to go
  if ticks > 0 and ticks mod 10 = 0 [ ; <--- this is the important line
    ask as [ die ]
    ask bs [ die ]
    create-as number-of-as 
    create-bs number-of-bs
  ]
  ask as [ move ]
  ask bs [ move ]
  tick
end

to move
  rt random 50
  lt random 50
  fd 1
end

我添加了一个ticks > 0条款,这样龟就不会在第一个滴答声中被杀死/重生,但你可以随意调整它。