我想比较一定半径范围内的补丁,关于它们上某类代理的数量。特工应移至大多数特工(在此情况下为人类)所在的区域。如果已经有人最多,他们就不得动弹。我对它和人类小组进行了编码,但是其中大多数人并没有排成一行(一个接一个)。如果你们中的任何人都可以快速浏览一下我的代码,那就太好了。谢谢
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
]]
]
答案 0 :(得分:1)
这是一个使用您的代码的完整的工作示例。这是否显示了您的意思?确实有海龟互相追逐。
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行中删除了=,并完全删除了第二个条件,所以现在如果乌龟的当前斑块比其发现的斑块少(严格来说,不是<=),它们就会移动。
答案 1 :(得分:1)
我同意上一篇文章,但是有一些其他信息。
如果您想在每次迭代中完全移至目标补丁,而不是向目标补丁迈进,只需在上述答案中替换产生一步动作的代码
[ face target-patch
forward 1
]
使用
[
move-to target-patch
]
我通过实验证实,两种移动方法的结果将产生相似但略有不同的结果。