为什么plabel在这个netlogo模型中取代以前的plabel来显示补丁和海龟协调?

为什么plabel在这个netlogo模型中取代以前的plabel来显示补丁和海龟协调?,netlogo,Netlogo,我写了一个代码来帮助理解补丁和海龟的协调。代码附在末尾 然而,我注意到了一个错误:我构建了两个按钮setup和test,在点击setup然后点击test几次之后,我们会注意到海龟1的一些格子将替换以前的格子,这完全不是我们想要的,也不应该发生;然而,海龟0似乎没有这样的问题 to setup clear-all create-ordered-turtles 2 [ ifelse (who mod 2) = 0 [ set heading headin

我写了一个代码来帮助理解补丁和海龟的协调。代码附在末尾

然而,我注意到了一个错误:我构建了两个按钮
setup
test
,在点击
setup
然后点击
test
几次之后,我们会注意到海龟1的一些格子将替换以前的格子,这完全不是我们想要的,也不应该发生;然而,海龟0似乎没有这样的问题

to setup
  clear-all
  create-ordered-turtles 2 
  [ 
    ifelse (who mod 2) = 0 
    [
      set heading heading + 15 
    ]
    [
      set heading 135
    ]
    pen-down
;    forward 1
  ]

end

to test
  ask turtles [   ;; for each turtle
    fd 1

    ;; get patch corrdination 
    let patch-cor (word "px" pxcor ":" "py" pycor)
    ;; get turtle corrdination
    let turtle-cor (word "x" (precision xcor 2) ":" "y" (precision ycor 2))
    ;; get distance between current and previous turtle corrdinations

    ;; get distance between current and origin turtle corrdinations
    let distanceTurtle precision (distancexy 0 0) 1

    let patch-color color                               ;; get turtle's color


    set label patch-cor                                 ;; let this turtle's label show current patch-corrdination
    set label-color patch-color

    ask patch-at -1 0                                   ;; focus on patch 1 unit left to where this turtle is on
    [
      set plabel patch-cor                              ;;  let this patch label show turtle's patch corrdination
      set plabel-color patch-color
    ]

    ask patch-at 4 0                                    ;; focus on patch 4 unit right to where this turtle is on
    [
      set plabel turtle-cor                             ;;  let this patch label show turtle's own corrdination
      set plabel-color patch-color
    ]

    ask patch-at 5 0                                    ;; focus on patch 5 unit right to where this turtle is on
    [
      set plabel distanceTurtle               ;;  let this patch label show distance between current turtle and origin
      set plabel-color patch-color
    ]
  ]

end

我不完全确定我是否理解这个问题,所以如果我告诉你你已经知道的事情,我向你道歉。有时海龟不会用
前进1
改变补丁。在不改变补丁的情况下,它可以行驶的最长距离是1.41。。。(sqrt(2))因为这是边长为1的正方形的对角线。如果海龟没有改变补丁,那么如果dx和dy是整数,那么dx dy处的补丁也不会改变。尝试使用
forward 1.5
,这样海龟们总是会更改补丁。是的,你说得对,有时候它们不会更改补丁,xcor和pcor值实际上解释了原因。@Kenny请每次问一个问题。这就是我们处理堆栈溢出的方法。关于自由调整标签位置的问题应该是一个单独的问题。我已经把它从这个问题上删除了。@SethTisue我明白了,下次我会这么做的。谢谢我不完全确定我是否理解这个问题,所以如果我告诉你你已经知道的事情,我向你道歉。有时海龟不会用
前进1
改变补丁。在不改变补丁的情况下,它可以行驶的最长距离是1.41。。。(sqrt(2))因为这是边长为1的正方形的对角线。如果海龟没有改变补丁,那么如果dx和dy是整数,那么dx dy处的补丁也不会改变。尝试使用
forward 1.5
,这样海龟们总是会更改补丁。是的,你说得对,有时候它们不会更改补丁,xcor和pcor值实际上解释了原因。@Kenny请每次问一个问题。这就是我们处理堆栈溢出的方法。关于自由调整标签位置的问题应该是一个单独的问题。我已经把它从这个问题上删除了。@SethTisue我明白了,下次我会这么做的。谢谢