英文:
How to make agents search for patches they havent been to Netlogo
问题
我想让一只鹰飞越这张地图。然而,鹰只是在地图的边缘飞翔。边缘指的是任何不是黑色的部分。
我尝试了以下代码:
ask patches [ ifelse pcolor != 0 and pxcor > 350 or pxcor < 100 [set edge 1][set edge 0 ]]
ask Buteo-platypterus [face max-one-of patches with [edge = 1] [distance myself] fd 5]
这使它们移动到边缘,但它们不会移动。我以为通过寻找最大值,它们会一直移动到最远的边缘,但事实并非如此。想法是鸟从一边到另一边,就像乒乓球一样,当它们到达最高点时,它们会下降,反之亦然。
这些鸟从地图的随机点开始,所以它们首先到达地图的任何一边,然后执行乒乓操作。
已编辑以修复格式
英文:
I want to make and eagle fly through this map. However, the eagle just flies by the edges of the map. The edge is anything that's not black.
I tried
ask patches [ ifelse pcolor != 0 and pxcor > 350 or pxcor < 100 [set edge 1][set edge 0 ]]
ask Buteo-platypterus [face max-one-of patches with [edge = 1] [distance myself] fd 5]
This makes them go to the edge, but they don't move. I thought that by asking for the max it would always move to the furthest edge, but it didnt. The idea is that the bird goes from edge to edge, say like a ping pong, where as soon as they reach the topmost point they go down and vice-versa.
The birds start at a random point on the map, so the most first reach the edge of the map, any edge, and then do the ping pong thing.
Edited to fix formating
答案1
得分: 1
在我正在开发的模型中,我使用一个名为"turtles-own"的代理集来记住它们已经访问过的所有斑块。在每次移动之前,它们会将它们当前所在的斑块添加到列表中,然后寻找它们还没有访问过的最近的斑块。
turtles-own [patch-memory]
to setup
ask turtles [set patch-memory [] ] ;仅在初始化列表或有意要忘记其中所有内容时执行此操作
end
to go
ask turtles [
set patch-memory lput patch-here patch-memory
move-to min-one-of patches with [ not member? self [patch-memory] of myself] [distance myself]
]
end
请注意,如果有大量的乌龟和大量的斑块,这可能会相当慢,但这里重要的是概念。
英文:
In a model I am myself working on, I use a turtles-own agentset to remember all the patches they have already visited. Before each move, they add the current patch they are on, and then look for the nearest patch that they haven't visited yet.
turtles-own [patch-memory]
to setup
ask turtles [set patch-memory [] ] ;Only do this to initiate the list, or when you intentionally want to forget everything that was in here
end
to go
ask turtles [
set patch-memory lput patch-here patch-memory
move-to min-one-of patches with [ not member? self [patch-memory] of myself] [distance myself]
]
end
Edit: Do note that this can be quite slow if you have a lot of turtles and a lot of patches, but it is the concept that counts here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论