我在流行病算法中工作,我使用八卦算法和SIR模型的组合。 我要做的一部分是改变邻居海龟之一的颜色并等待3.0然后将另一只颜色着色,直到所有海龟都变成绿色。
但我的程序只执行一次该功能。现在如何让我的海龟每次等待3.0滴,然后给邻居上色。
这个代码:
to setup clear-all reset-ticks crt 100 set color blue end to go wait 3.0 ask one-of out-link-neighbors with [color = blue] [ set color green ask (link-with myself) [ set color green - 3 ] ] tick end谢谢大家。
I work in epidemic algorithm , i use a combination between gossip algorithm and SIR model. Part of what I am trying to do is to change the color of one of neighbors turtles and wait 3.0 then color the other one until all the turtles get the color green.
But my program do the function wait just one time.Now how to make my turtles wait every time 3.0 ticks then color its neighbor.
this the code :
to setup clear-all reset-ticks crt 100 set color blue end to go wait 3.0 ask one-of out-link-neighbors with [color = blue] [ set color green ask (link-with myself) [ set color green - 3 ] ] tick endAnd thank you all.
最满意答案
go go命令中的wait停止执行(以秒为单位)。 你想要做的是在刻度线上涂上颜色。 因此,相反,您希望将刻度修改为3,并且每当余数为0时,将其设置为绿色。
to go if ticks mod 3 = 0 [ ask one-of out-link-neighbors with [color = blue] [ set color green ask (link-with myself) [set color green - 3] ] ]The wait in your go command stalls the execution (in seconds). What you want to do is color it on the ticks. So, instead, you want to mod the ticks by 3 and whenever the remainder is 0, color it green.
to go if ticks mod 3 = 0 [ ask one-of out-link-neighbors with [color = blue] [ set color green ask (link-with myself) [set color green - 3] ] ]更多推荐
发布评论