我想让特工们和其他人分享他们的文化。它们有一个长度为11的字符串,表示它们的区域性,由二进制标记(例如,10100111101)组成。因此,为了与每个朋友分享他们的文化,他们选择了一个随机标签。如果朋友同意代理人在那个标签位置,没有改变;如果他们不同意,朋友的标签被翻转同意代理人的标签(爱泼斯坦和阿克塞尔,气体)。
有关更多细节,区域性设置如下:
set t-culture-tags n-values 11 [random 2]然后,为了细分的目的,我像这样过滤,计数0,然后给他们一个组:
set shared-culture (filter [i -> i = 0] t-culture-tags)发布于 2017-07-26 16:39:18
使用replace-item
turtles-own [ t-culture-tags ]
to setup
clear-all
create-turtles 10 [ set t-culture-tags n-values 11 [random 2] ]
end
to go
ask turtles [
let friend one-of other turtles
let i random length t-culture-tags
let my-tag item i t-culture-tags
let friend-tag [ item i t-culture-tags ] of friend
if my-tag != friend-tag [
set t-culture-tags replace-item i t-culture-tags friend-tag
]
]
end发布于 2017-07-26 16:37:26
turtles-own [ t-culture-tags ]
to setup
ca
reset-ticks
crt 10 [
set t-culture-tags n-values 11 [ random 2 ]
setxy random-xcor random-ycor
set color sum t-culture-tags + 50
]
end该设置使用t-culture-tags创建了10只海龟,如上面的示例所示。现在,既然你说只有在代理海龟和它的朋友之间标签不同的时候才会发生改变,那么最简单的方法就是总是传播问海龟的文化(因为,实际上,这不会改变朋友的t-culture-tags )。
所以,你可以选择一个从0到10的随机数,然后用它作为一个索引,然后让问海龟在索引位置把它的标签分发给所有你想要的“朋友”。在下面的例子中,每一只随机的海龟在半径为5的范围内向所有其他海龟传播它的养殖:
to spread-culture
ask one-of turtles [
let tag-index random 11
let my-tag-at-index item tag-index t-culture-tags
if any? other turtles in-radius 10 [
ask other turtles in-radius 10 [
set t-culture-tags replace-item tag-index t-culture-tags my-tag-at-index
set color sum t-culture-tags + 50
]
]
]
tick
end如果你运行一段时间,你会看到所有的海龟,在半径范围内-另一个,最终将有相同的t文化标签,在这个例子中用他们的颜色表示。
https://stackoverflow.com/questions/45332030
复制相似问题