Commit db843562 by serfrape

Allow to send tell messages with no args

parent 9df8a2dc
...@@ -103,13 +103,9 @@ class BDIAgent(Agent): ...@@ -103,13 +103,9 @@ class BDIAgent(Agent):
else: else:
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, belief, self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, belief,
pyson.runtime.Intention())) pyson.runtime.Intention()))
# self.agent.bdi_agent.call(pyson.Trigger.removal, pyson.GoalType.belief, belief,
# pyson.runtime.Intention())
if not found: if not found:
self.agent.bdi_intention_buffer.append((pyson.Trigger.addition, pyson.GoalType.belief, term, self.agent.bdi_intention_buffer.append((pyson.Trigger.addition, pyson.GoalType.belief, term,
pyson.runtime.Intention())) pyson.runtime.Intention()))
# self.agent.bdi_agent.call(pyson.Trigger.addition, pyson.GoalType.belief, term,
# pyson.runtime.Intention())
def remove_belief(self, name, *args): def remove_belief(self, name, *args):
"""Remove an existing agent's belief.""" """Remove an existing agent's belief."""
...@@ -122,19 +118,16 @@ class BDIAgent(Agent): ...@@ -122,19 +118,16 @@ class BDIAgent(Agent):
term = pyson.Literal(name, tuple(new_args), PERCEPT_TAG) term = pyson.Literal(name, tuple(new_args), PERCEPT_TAG)
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, term, self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, term,
pyson.runtime.Intention())) pyson.runtime.Intention()))
# self.agent.bdi_agent.call(pyson.Trigger.removal, pyson.GoalType.belief, term,
# pyson.runtime.Intention())
def get_belief(self, key, pyson_format=False): def get_belief(self, key, source=False):
"""Get an agent's existing belief. The first belief matching """Get an agent's existing belief. The first belief matching
<key> is returned. Keep <pyson_format> False to strip pyson <key> is returned. Keep <source> False to strip source."""
formatting."""
key = str(key) key = str(key)
for beliefs in self.agent.bdi_agent.beliefs: for beliefs in self.agent.bdi_agent.beliefs:
if beliefs[0] == key: if beliefs[0] == key:
raw_belief = ( raw_belief = (
str(list(self.agent.bdi_agent.beliefs[beliefs])[0])) str(list(self.agent.bdi_agent.beliefs[beliefs])[0]))
if ')[source' in raw_belief and not pyson_format: if ')[source' in raw_belief and not source:
raw_belief = raw_belief.split( raw_belief = raw_belief.split(
'[')[0].replace('"', '') '[')[0].replace('"', '')
belief = raw_belief belief = raw_belief
...@@ -150,28 +143,25 @@ class BDIAgent(Agent): ...@@ -150,28 +143,25 @@ class BDIAgent(Agent):
else: else:
return None return None
def get_beliefs(self, pyson_format=False): def get_beliefs(self, source=False):
"""Get agent's beliefs.Keep <pyson_format> False to strip pyson """Get agent's beliefs.Keep <source> False to strip source."""
formatting."""
belief_list = [] belief_list = []
for beliefs in self.agent.bdi_agent.beliefs: for beliefs in self.agent.bdi_agent.beliefs:
try: try:
raw_belief = ( raw_belief = (
str(list(self.agent.bdi_agent.beliefs[beliefs])[0])) str(list(self.agent.bdi_agent.beliefs[beliefs])[0]))
if ')[source(' in raw_belief and not pyson_format: if ')[source(' in raw_belief and not source:
raw_belief = raw_belief.split('[')[0].replace('"', '') raw_belief = raw_belief.split('[')[0].replace('"', '')
belief_list.append(raw_belief) belief_list.append(raw_belief)
except IndexError: except IndexError:
pass pass
return belief_list return belief_list
def print_beliefs(self, pyson_format=False): def print_beliefs(self, source=False):
"""Print agent's beliefs.Keep <pyson_format> False to strip pyson """Print agent's beliefs.Keep <source> False to strip source."""
formatting."""
print("PRINTING BELIEFS")
for beliefs in self.agent.bdi_agent.beliefs.values(): for beliefs in self.agent.bdi_agent.beliefs.values():
for belief in beliefs: for belief in beliefs:
if ')[source(' in str(belief) and not pyson_format: if ')[source(' in str(belief) and not source:
belief = str(belief).split('[')[0].replace('"', '') belief = str(belief).split('[')[0].replace('"', '')
print(belief) print(belief)
...@@ -218,13 +208,11 @@ class BDIAgent(Agent): ...@@ -218,13 +208,11 @@ class BDIAgent(Agent):
pyson.Literal("source", (pyson.Literal(str(msg.sender)), ))) pyson.Literal("source", (pyson.Literal(str(msg.sender)), )))
self.agent.bdi_intention_buffer.append((trigger, goal_type, self.agent.bdi_intention_buffer.append((trigger, goal_type,
tagged_message, intention)) tagged_message, intention))
# self.agent.bdi_agent.call(trigger, goal_type,
# tagged_message, intention)
if self.agent.bdi_intention_buffer: if self.agent.bdi_intention_buffer:
temp_intentions = deque(self.agent.bdi_intention_buffer) temp_intentions = deque(self.agent.bdi_intention_buffer)
for trigger, goal_type, tagged_message, intention in temp_intentions: for trigger, goal_type, term, intention in temp_intentions:
self.agent.bdi_agent.call( self.agent.bdi_agent.call(
trigger, goal_type, tagged_message, intention) trigger, goal_type, term, intention)
self.agent.bdi_agent.step() self.agent.bdi_agent.step()
self.agent.bdi_intention_buffer.popleft() self.agent.bdi_intention_buffer.popleft()
else: else:
...@@ -247,5 +235,5 @@ async def parse_literal(msg): ...@@ -247,5 +235,5 @@ async def parse_literal(msg):
args = tuple(new_args) args = tuple(new_args)
else: else:
args = None args = ''
return functor, args return functor, args
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