两个问题: 1.如何对在我指定的标准中具有某些特定变量的海龟数量进行分组。例如,创建Id1为"1“的海龟。期望的输出将是包含相似值的海龟数量的列表。2.如果我得到了包含相似ID-s的海龟的列表,我希望从所有可用的海龟中获得一个组合。在python中(因为它是我唯一熟悉的语言),我会使用:
turtle_list = ["1","2","4","5","6","7"]
def create_pairs(source):
result = []
for p1 in range(len(source)):
for p2 in range(p1+1,len(source)):
result.append([source[p1],source[p2]])
return result
pairings = create_pairs(turtle_list)
print("%d pairings" % len(pairings))
for pair in pairings:
print(pair)发布于 2017-02-22 00:51:18
这里有一个简单的方法。为了获得更高的效率,如果你真的需要它,实现你上面描述的配对算法。
turtles-own [id]
to setup
ca
let _ids range 5
crt 100 [set id one-of _ids]
end
to pairup [_id]
let _ts (turtles with [id = _id])
ask _ts [
create-links-with other _ts
]
end
to test
setup
pairup 0
endhttps://stackoverflow.com/questions/42367769
复制相似问题