How to link actions of agents?

两盒软妹~` 提交于 2019-12-11 01:44:40

问题


I am trying to program the simulation with 3 sets of agents - A,B,C. The point is that the agents from the set A can choose to DO the action or NOT. If they decide to NOT do the action, the simulation stops. When they decide to DO the action, simulation continues to the next step, where the agents from the set B can also decide to DO the action or not. The same is here. And the agents from the set C, can also decide to DO the action or NOT, but here, the simulation in both cases stops. Here is my code:

ask turttles [
if breed = set A [ ifeslse do?= false [ set lazy]
                                        stop]
[ if breed = set B [ ifelse do1?= false [ set lazy]
                                         stop]
[ask other turtles [ if breed = set C [ ifelse do 2? = false [ set lazy
                                                               stop] ] 
                                       [set done
                                        stop] ]
                                        ]
                                      ]
                                    ]

The code does not work very good,I need somehing to link these three step, because when I export-world, I got data only from the first step


回答1:


If you do stop inside of an ask, it won't cause the whole simulation to stop. It will only stop the current turtle from executing the rest of the ask.

I think you want something more like:

globals [done?]

to setup
  ...
  set done? false
  ...
end

to go
  if done? [ stop ]
  ifelse ...
    [ ask A [ do-action ] ]
    [ set done? true ]
  ifelse ...
    [ ask B [ do-action ] ]
    [ set done? true ]
  ifelse ...
    [ ask C [ do-action ] ]
    [ set done? true ]
  ...
end

But I'm guessing somewhat, since it's difficult to tell from your description what your actual intentions are. (Especially since you haven't included your real code — the coede in your question wouldn't get past the compiler.)



来源:https://stackoverflow.com/questions/23460679/how-to-link-actions-of-agents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!