Netlogo 龟在 14 天后停止传染,并在被感染后开始传染

Netlogo turtle stops being infectious after 14 days and starts after being infected

问乌龟感染了[?并滴答 <= 14 ] [ 感染 ]

这是我的代码,一只乌龟被感染后?他也会感染。但我希望它只在 14 天内感染。发生的情况是它仅在前 14 个刻度上感染并停止。例如,我想做的是,一只乌龟在第 5 滴答时被感染,然后它会在第 19 滴答停止感染。提前谢谢你

ticks 是全局时间步长计数器,因此它从 0 开始递增(当您使用 reset-ticks 开始模拟时)。您要做的是让每只海龟知道自己何时被感染,然后在接下来的 14 个蜱虫中具有传染性。所以你必须创建一个 turtle 变量来跟踪它何时被感染,并将其用作条件。类似于:

turtles-own
[ infected?
  when-infected
]

to infect
  ask turtles
  [ if < whatever code you have that exposes them >
    [ set infected? true                  ; you must have this already
      set when-infected ticks
    ]
  ...
end

to ???
  ask turtles with [ infected? and when-infected >= ticks - 14 ] [ infect ]
  ...
end

您可以看到替换行将海龟的新 when-infected 变量的特定值与 ticks

的当前值进行了比较