有人让乌龟识别一群其他乌龟,即一群乌龟聚集在一起吗?由于半径为50的海龟可能是完全不同的(整个地方而不是彼此在床旁),因此以下操作无效:
if count turtles in-radius 20 >= 50 [show "There's a crowd"]
目前,我将人群定义为50多只彼此并列的海龟。
答案 0 :(得分:1)
如果您想要连续连接的海龟,则可以从模型库(这里是一个版本)中修改补丁集群示例。使用此设置:
globals [ groups>50 ]
turtles-own [
my-group
]
to setup
ca
crt 500 [
set my-group -99
set shape "square"
move-to one-of patches
]
reset-ticks
end
这些辅助功能:
to identify-groups
let group-counter 0
loop [
let seed one-of turtles with [ my-group = -99 ]
if seed = nobody [
stop
]
ask seed [
set my-group group-counter
set group-counter group-counter + 1
spread-group
]
]
end
to spread-group
set label my-group
set color my-group * 10 + 5
ask ( turtles-on neighbors ) with [ my-group = -99 ] [
set my-group [my-group] of myself
spread-group
]
end
identify-groups
运行一个循环,该循环标识连续斑块上的所有海龟,并在这些组中散布唯一的my-group
值。
然后,您可以获得唯一的组值,并使用filter
仅返回具有一定阈值龟数的组号:
to go
identify-groups
let unique-groups sort remove-duplicates [my-group] of turtles
set groups>50 filter [ i -> count turtles with [ my-group = i ] >= 50 ] unique-groups
print groups>50
end