使用help of @JenB我编写了一个代码来帮助理解forward 1
,补丁和乌龟协调。代码附在最后。
但是,我发现了一个错误:我在点击setup
然后点击test
几次后,构建了两个按钮setup
和test
,我们会注意到一些龟1号的脚will将取代以前的脚,,这根本不是预期的,不应该发生;然而,乌龟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