首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用时间变量制作一个列表,并从这些元素中随机选择一个

用时间变量制作一个列表,并从这些元素中随机选择一个
EN

Stack Overflow用户
提问于 2015-10-14 01:36:10
回答 2查看 42关注 0票数 0

嗨,我正在做一个模型,我需要使用时间变量的值创建一个元素列表。这是我用来定义时间变量的代码

代码语言:javascript
运行
复制
to react
  ask  cells
   [
   let Ai1 count turtles with [color = blue and xcor < -13 and ycor > -26] 
   let Ai2 count turtles with [color = blue and xcor < -13 and ycor < -27] 
   let Ai3 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor > -26]
   let Ai4 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor < -26]
    let Ai5 count turtles with [color = blue and xcor > 11 and ycor > -26]
    let Ai6 count turtles with [color = blue and xcor > 11 and ycor < -26]
  let Aimax list  (Ai1 Ai2 Ai3 Ai4 Ai5 Ai6)
   set calories (44.5 * random Aimax)
     ]
  end

所以我需要创建一个Ai1...Ai6值的列表,然后随机选择这6个值中的一个,在时间变量Aimax值的下一个乘法中使用它,那么这样做是可能的吗?如果我使用随机命令,它可以在列表中使用吗?Tks用于阅读。

EN

回答 2

Stack Overflow用户

发布于 2015-10-14 02:21:24

one-of将从列表中随机挑选一项:

代码语言:javascript
运行
复制
set calories (44.5 * one-of Aimax)
票数 1
EN

Stack Overflow用户

发布于 2015-10-14 20:18:33

不要那样做。您让每个单元格计算所有的计数,这些计数只需要确定一次。你还用蓝色重复过滤你的乌龟。如果我们坚持你的界限,我们就可以写

代码语言:javascript
运行
复制
to-report countblues
  let blues (turtles with [color = blue])
  let counts (list
    count blues with [xcor < -13 and ycor > -26] 
    count blues with [xcor < -13 and ycor < -27] 
    count blues with [xcor > -12 and xcor < 11 and ycor > -26]
    count blues with [xcor > -12 and xcor < 11 and ycor < -26]
    count blues with [xcor > 11 and ycor > -26]
    count blues with [xcor > 11 and ycor < -26]
    )
  report counts
end

to react
  let counts countblues
  ask  cells[
    set calories (44.5 * one-of counts)
  ]
end

请注意,如果你的乌龟从来不改变颜色,你可以把blues变成一个全局的,尽管这会有很小的收益,并且每个全局都有引用透明度的代价。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33109084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档