我使用 "turtles-on" 的方式有什么问题?
What is wrong with the way I am using "turtles-on"?
我想模拟代理四处移动,如果他们到达一个已经有超过承载能力(由滑块确定)的代理数量的补丁,就会死亡。
我试过这样写:
to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if pcolor = one-of [yellow lime orange grey blue ] [die]
if escarabajos-on patch-here >= capacidad-de-carga-bosques [die]
]
]
但我收到一条消息,突出显示“escarabajos-on patch-here”,并说 > >= 期望此输入是代理或数字或字符串,但得到的是海龟代理集 >
escarabajos-on patch-here
的结果是一个代理集:当前补丁上所有 escarabajos
的集。你想要的是当前补丁中escarabajos
的数,所以你需要count
他们:
if count escarabajos-on patch-here >= capacidad-de-carga-bosques
也就是说,escarabajos-on patch-here
不必要地冗长,因为 NetLogo 也有一个 <breeds>-here
原语:
if count escarabajos-here >= capacidad-de-carga-bosques
最后,我有一种预感,你的意思是:
if member? pcolor [ yellow lime orange grey blue ]
而不是:
if pcolor = one-of [yellow lime orange grey blue ]
相反,one-of
primitive picks an element from a list at random, so your condition would have been true only if the randomly picked color happened to be the color of the current patch. By using member?
如果补丁的颜色是列表中的任何成员,则条件为真。
我想模拟代理四处移动,如果他们到达一个已经有超过承载能力(由滑块确定)的代理数量的补丁,就会死亡。 我试过这样写:
to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if pcolor = one-of [yellow lime orange grey blue ] [die]
if escarabajos-on patch-here >= capacidad-de-carga-bosques [die]
]
]
但我收到一条消息,突出显示“escarabajos-on patch-here”,并说 > >= 期望此输入是代理或数字或字符串,但得到的是海龟代理集 >
escarabajos-on patch-here
的结果是一个代理集:当前补丁上所有 escarabajos
的集。你想要的是当前补丁中escarabajos
的数,所以你需要count
他们:
if count escarabajos-on patch-here >= capacidad-de-carga-bosques
也就是说,escarabajos-on patch-here
不必要地冗长,因为 NetLogo 也有一个 <breeds>-here
原语:
if count escarabajos-here >= capacidad-de-carga-bosques
最后,我有一种预感,你的意思是:
if member? pcolor [ yellow lime orange grey blue ]
而不是:
if pcolor = one-of [yellow lime orange grey blue ]
相反,one-of
primitive picks an element from a list at random, so your condition would have been true only if the randomly picked color happened to be the color of the current patch. By using member?
如果补丁的颜色是列表中的任何成员,则条件为真。