嗨我正在做一个模型,我需要使用时间变量的值来制作元素列表。这是我用来定义时态变量的代码
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的值,然后选择ramdomly这6个值中的一个,在下一个时间变量Aimax的乘法中使用它,那么这样做是否可行?如果我使用随机命令,它可以在列表中使用? Tks for reading。
答案 0 :(得分:1)
one-of
会从列表中选择一个随机项:
set calories (44.5 * one-of Aimax)
答案 1 :(得分:0)
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
转变为全局颜色,尽管这样会有很小的收益,并且每个全球都有参考透明度的成本。