我想要比较特定半径内的补丁,关于它们上的特定类别的代理的数量。代理应该移动到大多数代理(在本例中是人类)所在的补丁。如果它们已经在人类最多的补丁上,那么它们就不能移动。我对它和人类组进行了编码,但他们中的大多数人都不会留下来,也不会排成一行(一排接一排)。如果你们中的任何人能快速浏览一下我的代码,那就太好了。谢谢
if Strategy = "Gathering-Simple" [
if ((count(humans-on max-one-of patches in-radius rad [count(humans-here)] )) ) >= count(humans-here) [
if count(humans-on patches in-radius rad) - count(humans-here) > 0 [
face max-one-of patches in-radius rad [count(humans-here)]
fd 1
]]
]发布于 2019-11-01 23:21:51
这是一个使用您的代码的完整的工作示例。这是否显示了您所指的行为?确实有乌龟在互相追逐。
to setup
clear-all
create-turtles 100 [ setxy random-xcor random-ycor ]
reset-ticks
end
to go
let rad 5
ask turtles
[ let target-patch max-one-of patches in-radius rad [count turtles-here]
if count turtles-on target-patch >= count turtles-here ; comment 1
[ if count turtles-on patches in-radius rad > count turtles-here ; comment 2
[ face target-patch
forward 1
]
]
]
tick
end如果是这样的话,看看我评论的这两行。
注释1:>=意味着,即使海龟已经在最高计数的补丁上,这个条件也会得到满足,因为count turtles-here将等于最高计数补丁(该补丁)上的海龟计数。
注释2:这条线意味着只要在半径内的任何一个斑块上都有海龟,而不是在询问海龟的特定斑块上,那么海龟就会向前移动。
如果你只想让乌龟在不是最大数量补丁的情况下移动,可以尝试这样做:
to setup
clear-all
create-turtles 100 [ setxy random-xcor random-ycor ]
reset-ticks
end
to go
let rad 5
ask turtles
[ let target-patch max-one-of patches in-radius rad [count turtles-here]
if count turtles-on target-patch > count turtles-here
[ face target-patch
forward 1
]
]
tick
end我去掉了注释1行中的=,并完全删除了第二个条件,所以现在如果当前补丁中的海龟比它们发现的补丁更少(严格地说,不是<=),这些海龟就会移动。
发布于 2019-11-02 12:42:33
我同意之前的帖子,但有一些额外的信息。
如果您想在每次迭代中完全移动到目标面片,而不是只向目标面片移动一步,在上面的答案中,您可以替换产生一步运动的代码。
[ face target-patch
forward 1
]使用
[
move-to target-patch
]我通过实验证实,这两种移动方法的结果将产生相似但略有不同的结果。
https://stackoverflow.com/questions/58647500
复制相似问题