我定义了一个名为color-affinity的乌龟拥有的列表。此列表中的14个条目中的每个条目都由一个命名的netlogo颜色和一个相应的随机数组成,但不包括5。
我试图通过调用以下函数来初始化此列表:setup-turtle-color-affinity。
我正在使用Netlogo 6.1(最新版本)。代码如下。
turtles-own [
color-affinity
]
...
..
.
to setup
clear-all
create-turtles population
setup-turtle-color-affinity
setup-patches
reset-ticks
end
...
..
.
to setup-turtle-color-affinity
ask turtles
[ setup-color-affinity ]
end
to setup-color-affinity
[
; Here, I want to set up the list so that each turtle gets a random named netlogo color and a corresponding random "affinity" score of up to 5. However, whenever I try this (and I've tried various combinations of syntax) it gives me an error saying "closing bracket expected".
]
end
答案 0 :(得分:2)
这可能需要更多细节才能获得有用的答案-例如,如何设置颜色列表?在Netlogo中,颜色名称简单地读为数字-grey
是5,red
是15,依此类推。color-affinity
的格式是什么?
如果您在每只乌龟的列表对列表之后,其中每对都是颜色值和亲和力值,那么也许这样的事情可能对您有用:
turtles-own [
color-affinity
]
to setup
ca
let color-values ( range 5 145 10 )
crt 5 [
set color-affinity map [ c -> list c ( random 4 + 1 ) ] color-values
show color-affinity
]
reset-ticks
end
输出:
(turtle 1): [[5 4] [15 3] [25 2] [35 4] [45 2] [55 1] [65 2] [75 1] [85 2] [95 3] [105 3] [115 1] [125 3]]
(turtle 3): [[5 2] [15 2] [25 2] [35 1] [45 2] [55 4] [65 4] [75 4] [85 3] [95 2] [105 1] [115 2] [125 2]]
(turtle 2): [[5 2] [15 4] [25 1] [35 1] [45 1] [55 4] [65 3] [75 2] [85 4] [95 1] [105 4] [115 4] [125 2]]
(turtle 0): [[5 1] [15 1] [25 3] [35 4] [45 4] [55 1] [65 4] [75 2] [85 1] [95 4] [105 1] [115 1] [125 1]]
(turtle 4): [[5 3] [15 3] [25 4] [35 4] [45 2] [55 2] [65 4] [75 1] [85 2] [95 3] [105 1] [115 4] [125 3]]
编辑:
我不知道一种自动提取颜色名称的方法(更不用说了!)-您可能需要执行以下table
扩展方法:
extensions [ table ]
globals [ color-table ]
to setup-color-table
set color-table table:make
let color-names [
"gray" "red" "orange" "brown" "yellow"
"green" "lime" "turquoise" "cyan" "sky"
"blue" "violet" "magenta" "pink"
]
let color-values ( range 5 145 10 )
( foreach color-values color-names [
[ cv cn ] ->
table:put color-table cv cn
]
)
show table:get color-table 15
show table:get color-table 65
show table:get color-table 115
end
输出:
observer: "red"
observer: "lime"
observer: "violet"