乌龟死后如何跟踪它们的 parents?
How can I keep track of a turtle's parents once they die?
在我的模型中parents 产生后代。以下是雌性繁殖后代的过程,这里的后代会跟踪她们 parents 的身份。
to reproduce
if count mates > 0 [
hatch 3 [
set mother myself
set father one-of [mates] of mother
]]
不幸的是,他们的 parents 可能会死亡,因此 mother
和 father
变量变为 nobody
。有什么办法可以防止这些 ID 变成 nobody 吗?
这是使用 who
的(非常罕见的)情况之一。在你的情况下,每个 parent 我都会有两个变量 - 一个你已经有了,所以你可以很容易地做出像 face mother
这样的陈述,另一个存储 who
这样你就可以跟踪血统parent 死后。您的代码将如下所示:
to reproduce
if count mates > 0 [
hatch 3 [
set mother myself
set motherID [who] of mother
set father one-of [mates] of mother
set fatherID [who] of father
]]
在我的模型中parents 产生后代。以下是雌性繁殖后代的过程,这里的后代会跟踪她们 parents 的身份。
to reproduce
if count mates > 0 [
hatch 3 [
set mother myself
set father one-of [mates] of mother
]]
不幸的是,他们的 parents 可能会死亡,因此 mother
和 father
变量变为 nobody
。有什么办法可以防止这些 ID 变成 nobody 吗?
这是使用 who
的(非常罕见的)情况之一。在你的情况下,每个 parent 我都会有两个变量 - 一个你已经有了,所以你可以很容易地做出像 face mother
这样的陈述,另一个存储 who
这样你就可以跟踪血统parent 死后。您的代码将如下所示:
to reproduce
if count mates > 0 [
hatch 3 [
set mother myself
set motherID [who] of mother
set father one-of [mates] of mother
set fatherID [who] of father
]]