def think_look_operation(self, op): """Sends back information about goals. This is mainly to be used for debugging minds. If no arguments are specified all goals will be reported, else a match will be done using 'index'. The information will be sent back as a Think operation wrapping an Info operation. This method is automatically invoked by the C++ BaseMind code, due to its *_*_operation name. """ think_op = Operation("think") goal_info_op = Operation("info") goal_infos = [] if not op.get_args(): # get all goals for (index, goal) in enumerate(self.goals): goal_infos.append(Entity(index=index, report=goal.report())) else: for arg in op.get_args(): goal = self.goals[arg.index] if goal and goal is not None: goal_infos.append(Entity(index=arg.index, report=goal.report())) goal_info_op.set_args(goal_infos) think_op.set_refno(op.get_serialno()) think_op.set_args([goal_info_op]) res = Oplist() res = res + think_op return res
def think_look_operation(self, op): """Sends back information about goals. This is mainly to be used for debugging minds. If no arguments are specified all goals will be reported, else a match will be done using 'index'. The information will be sent back as a Think operation wrapping an Info operation. This method is automatically invoked by the C++ BaseMind code, due to its *_*_operation name. """ think_op = Operation("think") goal_info_op = Operation("info") goal_infos = [] if not op.get_args(): # get all goals for (index, goal) in enumerate(self.goals): goal_infos.append(Entity(index=index, report=goal.report())) else: for arg in op.get_args(): goal = self.goals[arg.index] if goal and goal is not None: goal_infos.append( Entity(index=arg.index, report=goal.report())) goal_info_op.set_args(goal_infos) think_op.set_refno(op.get_serialno()) think_op.set_args([goal_info_op]) res = Oplist() res = res + think_op return res
def tick_operation(self, op): """periodically reassess situation This method is automatically invoked by the C++ BaseMind code, due to its *_operation name. """ args = op.get_args() if len(args) != 0: if args[0].name == "think": # It's a "thinking" op, which is the base of the AI behaviour. # At regular intervals the AI needs to assess its goals; this is done through "thinking" ops. op_tick = Operation("tick") # just copy the args from the previous tick op_tick.set_args(args) op_tick.set_future_seconds(const.basic_tick + self.jitter) op_tick.set_to(self.id) for t in self.pending_things: thing = self.map.get(t) if thing and thing.type[0]: self.add_thing(thing) self.pending_things = [] result = self.think() if self.message_queue: result = self.message_queue + result self.message_queue = None return op_tick + result
def _learn(self, target, goal): es = Entity(id=goal[1], goal=goal[1]) set = Operation("set") set.set_args([es]) think = Operation("think", to=target) think.set_args([set]) self.avatar.send(think)
def commune_all_thoughts(self, op, name): """Sends back information on all thoughts. This includes knowledge and goals, as well as known things. The thoughts will be sent back as a "think" operation, wrapping a Set operation, in a manner such that if the same think operation is sent back to the mind all thoughts will be restored. In this way the mind can support server side persistence of its thoughts. A name can optionally be supplied, which will be set on the Set operation. """ think_op = Operation("think") set_op = Operation("set") thoughts = [] for what in sorted(self.knowledge.knowings.keys()): d = self.knowledge.knowings[what] for key in sorted(d): if what != "goal": object_val = d[key] if isinstance(object_val, Location): # Serialize Location as tuple, with parent if available if object_val.parent is None: location = object_val.position else: location = ("$eid:" + object_val.parent.id, object_val.pos) goal_object = str(location) else: goal_object = str(d[key]) thoughts.append( Entity(predicate=what, subject=str(key), object=goal_object)) if len(self.things) > 0: things = {} for (id, thinglist) in sorted(self.things.items()): idlist = [] for thing in thinglist: idlist.append(thing.id) things[id] = idlist thoughts.append(Entity(things=things)) if len(self.pending_things) > 0: thoughts.append(Entity(pending_things=self.pending_things)) set_op.set_args(thoughts) think_op.set_args([set_op]) if not op.is_default_serialno(): think_op.set_refno(op.get_serialno()) if name: set_op.set_name(name) res = Oplist() res = res + think_op return res
def commune_all_thoughts(self, op, name): """Sends back information on all thoughts. This includes knowledge and goals, as well as known things. The thoughts will be sent back as a "think" operation, wrapping a Set operation, in a manner such that if the same think operation is sent back to the mind all thoughts will be restored. In this way the mind can support server side persistence of its thoughts. A name can optionally be supplied, which will be set on the Set operation. """ think_op = Operation("think") set_op = Operation("set") thoughts = [] for what in sorted(self.knowledge.knowings.keys()): d = self.knowledge.knowings[what] for key in sorted(d): if what != "goal": object_val = d[key] if type(object_val) is Location: # Serialize Location as tuple, with parent if available if object_val.parent is None: location = object_val.position else: location = ("$eid:" + object_val.parent.id, object_val.pos) goal_object = str(location) else: goal_object = str(d[key]) thoughts.append(Entity(predicate=what, subject=str(key), object=goal_object)) if len(self.things) > 0: things = {} for (id, thinglist) in sorted(self.things.items()): idlist = [] for thing in thinglist: idlist.append(thing.id) things[id] = idlist thoughts.append(Entity(things=things)) if len(self.pending_things) > 0: thoughts.append(Entity(pending_things=self.pending_things)) set_op.set_args(thoughts) think_op.set_args([set_op]) if not op.is_default_serialno(): think_op.set_refno(op.get_serialno()) if name: set_op.set_name(name) res = Oplist() res = res + think_op return res
def commune_path(self, op): """Sends back information about the path.""" think_op = Operation("think") path = [] my_path = self.path # print("path size: " + str(len(my_path))) for point in my_path: path.append([point.x, point.y, point.z]) think_op.set_args([Entity(path=path, current_path_index=self.current_path_index)]) res = Oplist() res = res + think_op return res
def commune_path(self, op): """Sends back information about the path.""" think_op = Operation("think") path = [] my_path = self.steering.path # print("path size: " + str(len(my_path))) for point in my_path: path.append([point.x, point.y, point.z]) think_op.set_args([Entity(path=path, current_path_index=self.steering.current_path_index)]) res = Oplist() res = res + think_op return res
def _know(self, target, know): subject = know[0] if len(know) == 2: predicate = 'location' object = know[1] else: predicate = know[1] object = know[2] es = Entity(subject=self.sanitizeKnowledge(subject), object=self.sanitizeKnowledge(object), predicate=predicate) set = Operation("set") set.set_args([es]) think = Operation("think", to=target) think.set_args([set]) self.avatar.send(think)
def setup_operation(self, op): """called once by world after object has been made send first tick operation to object This method is automatically invoked by the C++ BaseMind code, due to its *_operation name.""" # Setup a tick operation for thinking think_tick_op = Operation("tick") think_tick_op.set_to(self.id) think_tick_op.set_args([Entity(name="think")]) # Setup a tick operation for moving move_tick_op = Operation("tick") move_tick_op.set_to(self.id) move_tick_op.set_args([Entity(name="move")]) move_tick_op.set_future_seconds(0.2) return Operation("look") + think_tick_op + move_tick_op
def setup_operation(self, op): """called once by world after object has been made send first tick operation to object This method is automatically invoked by the C++ BaseMind code, due to its *_operation name.""" # CHEAT!: add memory, etc... initialization (or some of it to __init__) # Setup a tick operation for thinking think_tick_op = Operation("tick") think_tick_op.set_to(self.id) think_tick_op.set_args([Entity(name="think")]) # Setup a tick operation for moving move_tick_op = Operation("tick") think_tick_op.set_to(self.id) move_tick_op.set_args([Entity(name="move")]) move_tick_op.set_future_seconds(0.2) return Operation("look") + think_tick_op + move_tick_op
def commune_goals(self, op, goal_entity): """Sends back information about goals only.""" think_op = Operation("think") set_op = Operation("set") thoughts = [] # It's important that the order of the goals is retained for goal in self.goals: if hasattr(goal, "str"): goal_string = goal.str else: goal_string = goal.__class__.__name__ thoughts.append(Entity(goal=goal_string, id=goal_string)) set_op.set_args(thoughts) think_op.set_args([set_op]) think_op.set_refno(op.get_serialno()) res = Oplist() res = res + think_op return res