Commit 51937a71 by serfrape

Allow .send to a list of receivers.

parent 49ce97cb
...@@ -69,15 +69,18 @@ class BDIAgent(Agent): ...@@ -69,15 +69,18 @@ class BDIAgent(Agent):
def add_actions(self): def add_actions(self):
@self.agent.bdi_actions.add(".send", 3) @self.agent.bdi_actions.add(".send", 3)
def _send(agent, term, intention): def _send(agent, term, intention):
receiver = str(asp.grounded(term.args[0], intention.scope)) receivers = asp.grounded(term.args[0], intention.scope)
if isinstance(receivers, str):
receivers = (receivers,)
ilf = asp.grounded(term.args[1], intention.scope) ilf = asp.grounded(term.args[1], intention.scope)
if not asp.is_atom(ilf): if not asp.is_atom(ilf):
return return
ilf_type = ilf.functor ilf_type = ilf.functor
mdata = {"performative": "BDI", "ilf_type": ilf_type, } mdata = {"performative": "BDI", "ilf_type": ilf_type, }
body = asp.asl_str(asp.freeze(term.args[2], intention.scope, {})) for receiver in receivers:
msg = Message(to=receiver, body=body, metadata=mdata) body = asp.asl_str(asp.freeze(term.args[2], intention.scope, {}))
self.agent.submit(self.send(msg)) msg = Message(to=str(receiver), body=body, metadata=mdata)
self.agent.submit(self.send(msg))
yield yield
@self.agent.bdi_actions.add(".custom_action", 1) @self.agent.bdi_actions.add(".custom_action", 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment