如何找到两个补丁之间的距离?
How to find the distance between two patches?
我试图让特工以最有效的路线到达目的地(从 10 个补丁中随机选择)。问题是,distance 似乎是一个仅限代理的命令,而且我发现的唯一执行类似操作的代码似乎可以通过 运行 带有补丁的 distance 命令工作,这会产生错误。
这是麻烦的程序:
to-report best-route
let visible-patches patches in-radius turtles-vision-dist
let visible-routes visible-patches with [ pcolor = gray ]
let routes-that-take-me-closer visible-routes with [
;;THIS IS THE PROBLEM LINE RIGHT BELOW HERE
[ distance visible-routes] of destination < [ distance destination - 1 ] of myself
]
在我找到的示例 Paths 中,代码如下:
to-report best-way-to [ destination ]
let visible-patches patches in-radius walker-vision-dist
let visible-routes visible-patches with [ pcolor = gray ]
let routes-that-take-me-closer visible-routes with [
distance destination < [ distance destination - 1 ] of myself
]
ifelse any? routes-that-take-me-closer [
; from those route patches, choose the one that is the closest to me
report min-one-of routes-that-take-me-closer [ distance self ]
] [
; if there are no nearby routes to my destination
report destination
]
end
我本来有一个更相似的东西,但它没有用,所以我一直在玩它,但没有运气,我的同学和我的教授也是如此。
我不知道你的路径算法应该如何工作,因为它看起来不像你在限制灰色块的移动。但是,假设您的目的地存储为一个补丁,那么您可以直接使用 distance destination
计算到该补丁的距离,如下所示:
turtles-own [ destination ]
to testme
clear-all
create-turtles 1
[ set destination one-of patches
ask destination [ set pcolor blue ]
]
ask one-of turtles
[ print distance destination
]
end
我试图让特工以最有效的路线到达目的地(从 10 个补丁中随机选择)。问题是,distance 似乎是一个仅限代理的命令,而且我发现的唯一执行类似操作的代码似乎可以通过 运行 带有补丁的 distance 命令工作,这会产生错误。
这是麻烦的程序:
to-report best-route
let visible-patches patches in-radius turtles-vision-dist
let visible-routes visible-patches with [ pcolor = gray ]
let routes-that-take-me-closer visible-routes with [
;;THIS IS THE PROBLEM LINE RIGHT BELOW HERE
[ distance visible-routes] of destination < [ distance destination - 1 ] of myself
]
在我找到的示例 Paths 中,代码如下:
to-report best-way-to [ destination ]
let visible-patches patches in-radius walker-vision-dist
let visible-routes visible-patches with [ pcolor = gray ]
let routes-that-take-me-closer visible-routes with [
distance destination < [ distance destination - 1 ] of myself
]
ifelse any? routes-that-take-me-closer [
; from those route patches, choose the one that is the closest to me
report min-one-of routes-that-take-me-closer [ distance self ]
] [
; if there are no nearby routes to my destination
report destination
]
end
我本来有一个更相似的东西,但它没有用,所以我一直在玩它,但没有运气,我的同学和我的教授也是如此。
我不知道你的路径算法应该如何工作,因为它看起来不像你在限制灰色块的移动。但是,假设您的目的地存储为一个补丁,那么您可以直接使用 distance destination
计算到该补丁的距离,如下所示:
turtles-own [ destination ]
to testme
clear-all
create-turtles 1
[ set destination one-of patches
ask destination [ set pcolor blue ]
]
ask one-of turtles
[ print distance destination
]
end