How can I compute the distance between two patches?

三世轮回 提交于 2019-12-24 12:04:47

问题


I need to find the minimum distance between patches in front of my agent to a certain patch (goal), in order to select the patch that would create the most optimal (shortest) path. The primitive distance only requires one argument so I can't use it as is for this function.


回答1:


The distance primitive only requires one argument, yes, but it is a "patch or turtle primitive": it must be run in the context of a particular agent by "asking" it for its distance to another, so you can think of the context in which it run as another argument.

If you want to know the distance between patch 0 0 and patch 1 1, you can write:

ask patch 0 0 [ show distance patch 1 1 ]

or, likely more useful:

[ distance patch 1 1 ] of patch 0 0


来源:https://stackoverflow.com/questions/15998359/how-can-i-compute-the-distance-between-two-patches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!