我认为以下示例可能会对您正在发生的事情有所了解:
to setup
clear-all
create-turtles 1 [
set xcor -0.5
set ycor -0.5
set heading 45
show (word "patch-here: " patch-here)
show (word "patch-ahead 1: " patch-ahead 1)
show (word "patch-ahead 1: " patch-ahead 1)
show (word
"not any? turtles-on patch-ahead 1: "
not any? turtles-on patch-ahead 1
)
show (word
"not any? other turtles-on patch-ahead 1: "
not any? other turtles-on patch-ahead 1
)
]
end
它正在创建一只海龟,将其放置在中央补丁的左下角并使其面向东北,然后再检查一些东西。如果你运行代码,你会得到:
observer> setup
(turtle 0): "patch-here: (patch 0 0)"
(turtle 0): "patch-ahead 1: (patch 0 0)"
(turtle 0): "patch-ahead 1: (patch 0 0)"
(turtle 0): "not any? turtles-on patch-ahead 1: false"
(turtle 0): "not any? other turtles-on patch-ahead 1: true"
关键是补丁的对角线长于一个(记住毕达哥拉斯定理)。这意味着它patch-ahead 1仍然可以是海龟所在的同一块!在这种情况下,not any? turtles-on patch-ahead 1将是错误的。由于您的海龟在世界各地随机移动,因此这最终一定会发生。
幸运的是,有一个简单的解决方案。只需使用other:
not any? other turtles-on patch-ahead 1