我想请一只乌龟移动到距离另一只乌龟至少x距离的任何补丁。因此,在NetLogo和英语的组合中,它应该是:如何移动到距离乌龟至少x距离的补丁
move-to one-of patches with [distance to nearest turtle > 4]
请问这怎么办?
我想请一只乌龟移动到距离另一只乌龟至少x距离的任何补丁。因此,在NetLogo和英语的组合中,它应该是:如何移动到距离乌龟至少x距离的补丁
move-to one-of patches with [distance to nearest turtle > 4]
请问这怎么办?
你找到最近的龟使用min-one-of
+ [distance myself]
记者。你还需要确保你只看到other turtles
,因为一只乌龟永远是最靠近自身的乌龟。
的代码可以被分解如下:
let nearest-turtle min-one-of other turtles [distance myself]
move-to one-of patches with [distance nearest-turtle > 4]
对于(可以说)更好的可读性。
编辑:谢谢尼古拉斯的更正。你是完全正确的。
不仅仅是可读性:如果你在'with'块中附加'other',它就是指调用补丁。每个人都会因此被咬伤。它可以导致非常微妙的错误... –
我认为你在long表达式中使用'myself'也是错误的:它指的是调用补丁,而不是你想要的调用龟。 –
这是问题开始的地方!它应该是距离另一只乌龟最小距离的补丁,而不是正在进行移动的乌龟。 “补丁与”的使用我认为这样可以让正确的代理人进行呼叫。我明天会试一试。感谢所有评论和回复。 – ThomasC
使用上述所有的,这里是一个解决方案:
to go
ask patches [set nearest-turtle min-one-of turtles [distance myself]
set distance-turtle distance nearest-turtle
]
crt 1 [
set color blue
move-to one-of patches with [distance-turtle > 4]]
end
你想要做的,如果没有这样的补丁呢? – Alan
我总是在围绕这一点与SO斗争 - 我想尽可能具体地向我提出我的问题,通过足够的通用性来有用。事实上,我认为我可以处理这一点 - 整个事情将成为一系列if语句的一部分。 – ThomasC