我是Netlogo的新手,也是编程新手。我想创建一个netlogo模型,有雌龟和雄龟。这两个种群都是通过随机游走的方式在世界上移动。女性群体应该找到一个伴侣,并拥有‘半径’属性。如果她在找到伴侣之前还没有找到伴侣,那么她自己的半径应该会扩大。如果雌海龟还没有找到伴侣,我怎么能在每一个时间步后扩展它的半径呢?
谢谢你的帮忙!
发布于 2019-05-14 01:47:31
首先,您需要一个海龟属性来存储每个海龟的值。实现这一点的方法是使用turtles-own语句。然后,您只需根据需要更改该值。原语in-radius查看指定距离内的所有对象,然后您可以根据是否存在any?合适的对象来设置条件。你的代码应该看起来像这样(这是一个完整的模型):
turtles-own
[ search-radius
mate
]
to setup
clear-all
create-turtles 20
[ setxy random-xcor random-ycor
set color blue
set search-radius 1
]
reset-ticks
end
to go
check-for-mate
tick
end
to check-for-mate
ask turtles with [color = blue]
[ let candidates other turtles in-radius search-radius
ifelse any? candidates
[ set mate one-of candidates
set color red
]
[ set search-radius search-radius + 0.5 + random-float 1
]
]
endhttps://stackoverflow.com/questions/56109943
复制相似问题