如何记录另一只海龟与之互动的海龟的身份?

How can I record the identity of turtles another turtle interacts with?

我的模型涉及一只海龟调查该区域,它应该跟踪它撞到的海龟的 ID/'who'。重要的是,测量员可能会记录相同的 ID/'who' 两次,但我不确定如何实现记忆方面的事情。

breed[boats boat]

boats-own [
  my-neighbors
  num-neighbors
count-neighbors]


to setup
  clear-all
  crt 100 [
    move-to one-of patches with [ not any? turtles-here ]
    
  ]
  
  crt 1 [set breed boats
  set count-neighbors 0
  ]

  reset-ticks
end

to go 
  ask turtles [
    fd 1
  ]
  
  ask boats [
    survey
  ]
  tick 
end 

to survey
 
    set my-neighbors (other turtles) in-radius 3
    set num-neighbors count my-neighbors
    set count-neighbors [who] of my-neighbors
   
end 

更新 根据下面的答案,我想出了以下内容,它还通过创建一个新的时间变量来记录交互发生的时间。

breed[boats boat]

boats-own [
  my-neighbors
  num-neighbors
id-neighbors
survey-time]

turtles-own [
  time
]


to setup
  clear-all
  crt 10 [
    move-to one-of patches with [ not any? turtles-here ]
    
  ]
  
  crt 1 [
    set breed boats
    set shape "circle"
    set id-neighbors []
    set survey-time []
  ]

  reset-ticks
end

to go 
  ask turtles [
    fd 1
    set time ticks 
  ]
  
  ask boats [
    survey
  ]
  tick 
end 

to survey
 
    set my-neighbors (other turtles-here )  
    set num-neighbors count my-neighbors
    set id-neighbors (sentence id-neighbors [who] of my-neighbors )
    set survey-time (sentence survey-time [time] of my-neighbors )
   
end 

目前,您总是将 count-neighbors 设置为其所有当前邻居的列表,但此列表会随着每个 tick 被清除并重新生成。取而代之的是,您可以使用像 sentence 这样的基元将 count-neighbors 的旧列表与您正在生成此迭代的新列表组合起来,并将 count-neighbors 的新列表设置为这个组合列表.

  set count-neighbors (sentence count-neighbors [who] of my-neighbors )

我还将你的 count-neighbors 初始化为一个空列表而不是 0,因为 0 已经是一只乌龟,所以它会给你错误的信息

  crt 1 [set breed boats
    set count-neighbors []
  ]

要检查内存是否按预期工作,您可以在命令中心使用 inspect one-of boats 并查看每个新条目如何添加到列表末尾。


编辑后续问题

您的解决方案绝对有效。请允许我对此提出一些建议:

不需要创建time变量,每只海龟已经可以访问ticks全局变量

  set id-neighbors (sentence id-neighbors [who] of my-neighbors )
  set survey-time (sentence survey-time [ticks] of my-neighbors )

作为替代方案,这创建了一个列表列表,其中每个项目都包含遇到的乌龟和遇到它的时间。使用起来稍微困难一些,但一目了然哪些值属于一起。

set id-neighbors (sentence id-neighbors [list who ticks] of my-neighbors )