我目前正在开始学习NetLogo,我正在尝试让四只乌龟从地面的顶部到底部进行比赛。我正在尝试使用 while 命令,但检查没有检测到任何问题。但是,当我单击按钮时,海龟不会移动。
to setupTurtles
ca
crt 4
ask turtles [set shape "turtle" set heading 180]
ask turtle 0 [set xcor 8 set ycor 16]
ask turtle 1 [set xcor 4 set ycor 16]
ask turtle 2 [set xcor -4 set ycor 16]
ask turtle 3 [set xcor -8 set ycor 16]
end
to moveTurtles
while [all? turtles [ycor != 16]] [
ask turtles [fd random 5]
]
end
它们不会移动,因为它们在 ycor = 16
开始。
[all? turtles [ycor != 16]]
条件的意思是:“
ycor
上的每只乌龟都与 16 不同吗?”。由于它们从 ycor = 16
开始,因此条件评估为 FALSE
。
将条件更改为
[not any? turtles with [ycor = -16]]
读作:“(同时)在 -16 的
ycor
上,即底部,没有海龟,(做一些事情)”。