首页 > 解决方案 > 乌龟的父母死后如何追踪他们?

问题描述

在我的模型中,父母产生后代。以下是雌性产仔的程序,在这里,幼仔跟踪父母的身份。

  to reproduce
  if count mates > 0 [
    hatch 3 [
     set mother myself
     set father one-of [mates] of mother
]]

可悲的是,他们的父母可能会死,所以motherfather变量变成了nobody。有什么办法可以防止这些 ID 变成任何人吗?

标签: netlogo

解决方案


这是(非常罕见的)使用who. 在您的情况下,我将为每个父母提供两个变量 - 一个您已经拥有,这样您就可以轻松地做出类似face mother的声明,另一个存储who您可以在父母去世后跟踪血统。您的代码将如下所示:

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

推荐阅读