Netlogo:使用条件从列表集中更改乌龟颜色

时间:2015-12-14 11:53:14

标签: list colors netlogo any

我有这组代码。 代理商是"消费者",它具有变量"类型的价值"。我正在尝试将白龟改为"类型值"列表中的一种颜色。但我一直在"期待一个不变的"错误信息。

to develop-needs
  if ticks mod 5 = 0 [
    ask consumers [set type-of-value  (list blue red green)] 
    let a count consumers with [color = white]
    if any? consumers with [color = white]
      [ set color one-of type-of-value ]
        ask turtles with [ color = one-of type-of-value ]
      ]]
end

任何帮助都将不胜感激。

谢谢

2 个答案:

答案 0 :(得分:1)

此代码终于有效了。 感谢JenB,我注意到了我的错误。

to develop-needs
  if ticks mod 5 = 0 [
    ask consumers [set type-of-value  (list blue red green)] 
    let a count consumers with [color = white]
    if any? consumers with [color = white]
      [ ask n-of (random a ) consumers with [color = white]
        [set color one-of type-of-value
         set value? true]
         ]]
end

答案 1 :(得分:0)

你还没有告诉它要选择多少。也就是说,如果要从名为a的代理程序集中选择5个使用者,ask n-of 5 a需要说(例如)[ set color one-of type-of-value ] ask turtles with [ color = one-of type-of-value ]

顺便提一下,您的代码中也存在逻辑错误:

set color one-of

如果值的类型是3个项目的列表(例如,代码中的[蓝绿红色]),则第一行中的one-of ...将选择其中一种颜色,但第二行{{ 1}}会做新的随机选择。我不确定你想要实现什么,所以我无法提供代码,但你可能想要选择一种颜色并将其分配给一个变量,然后与该变量进行比较,而不是进行进一步的选择。