使用 NetLogo 6.2 在界面中查看海龟标签时的不同行为。为什么会发生这种情况以及如何解决?

Different behavior of the turtles when viewing their labels in the interface using NetLogo 6.2. Why does this happen and how to solve it?

我有一个 doubt/intrigued 的 NetLogo 情况。另外,不知道有没有解决办法,具体原因是什么。

我做了一个小代码来举例说明我的问题...

发生的情况如下:

  1. 当我点击设置按钮然后继续运行,例如让 20 个刻度通过时,我有以下海龟运动(见下图)

  1. 但是,如果你按下设置按钮,然后在界面中创建一个按钮来显示和消失海龟标签(turtle labels),然后按下 go 并离开 20 个刻度,海龟的另一个移动出现(见下图)

我想知道为什么会这样?是用one-of吗?

还有如果有什么解决方法,因为我需要在界面中看到海龟标签跟随模型,检查它的运行情况。

如果有人对如何解决这个问题以及为什么会发生这种情况有任何想法,我将不胜感激。

提前致谢:)

globals [ edge-size ValidHabs PatchSet  ] 
  
patches-own [ scale-patch ]

to setup
  ca
  random-seed 1 
  set ValidHabs [ [1] [2] [3] ] 
  set edge-size 60
  set-patch-size 20 
  let list1 ( list 4 8 )
  set PatchSet patches with [  
    ( pxcor mod ( 2 + 1 ) = 0 ) and ( pycor mod ( 2 + 1 ) = 0 ) ]
  (
    foreach ValidHabs [
      this-profile ->
      ask one-of PatchSet [ sprout 1 ]
  ]
  ) 
  ask patches [
    set scale-patch random 10
    set pcolor scale-color green scale-patch -8 12    
  ]
  reset-ticks 
end

to go 
  do-something 
  tick
end

to do-something 
  move-turtles  
end

to move-turtles
  ask turtles [
    rt random-normal 0 90      
    fd 3
    set color black
    pen-down
    set pen-size 2
  ]
end


;Interface button code (turtle labels)
;ask turtles [
;  ifelse label = "" [    
;    set label  ( who )
;    set label-color white
;  ] 
;  [    
;    set label ""
;  ]
;]

用最少的可重现示例做得很好,这真的很有帮助!如果我理解你的问题,你想知道为什么尽管设置了 random-seed,但你的两个 运行 之间还是有区别?如果是这样的话,我认为是因为你在做一个依赖随机性来操作的额外动作(ask turtles [...)。当你 ask 海龟时,海龟以随机顺序行动。因此,如果您需要海龟每次都以相同的方式移动,一种快速解决方法是在您尝试复制的动作之前设置随机数。例如,如果我将您的 move-turtles 更改为:

to move-turtles
  random-seed 123
  ask turtles [
    rt random-normal 0 90      
    fd 3
    set color black
    pen-down
    set pen-size 2
  ]
end

然后运行走4次,我得到了这个没有标签的运动模式:

如果我 setup -> label -> go x 4 则相同:

希望这能让您指明正确的方向!