def insert_goal(goal): if hasattr(goal,"trigger"): dictlist.add_value(self.trigger_goals, goal.trigger(), goal) else: for i in range(len(self.goals)-1,-1,-1): if self.cmp_goal_importance(self.goals[i],goal): self.goals.insert(i+1,goal) return self.goals.insert(0,goal)
def insert_goal(self, goal, id=None): if not id: self.goal_id_counter = self.goal_id_counter + 1 id=str(self.goal_id_counter) goal.id = id if hasattr(goal,"trigger"): dictlist.add_value(self.trigger_goals, goal.trigger(), goal) return for i in range(len(self.goals)-1,-1,-1): if self.cmp_goal_importance(self.goals[i],goal): self.goals.insert(i+1,goal) return self.goals.insert(0,goal)
def insert_goal(self, goal, id=None): if not id: self.goal_id_counter = self.goal_id_counter + 1 id = str(self.goal_id_counter) goal.id = id if hasattr(goal, "trigger"): dictlist.add_value(self.trigger_goals, goal.trigger(), goal) return for i in range(len(self.goals) - 1, -1, -1): if self.cmp_goal_importance(self.goals[i], goal): self.goals.insert(i + 1, goal) return self.goals.insert(0, goal)
def add_thing(self,thing): """I own this thing""" #CHEAT!: this feature not yet supported ## if not thing.location: ## thing.location=self.get_knowledge("location",thing.place) log.debug(3,str(self)+" "+str(thing)+" before add_thing: "+str(self.things)) #thought about owing thing name = self.thing_name(thing) if not name: self.pending_things.append(thing.id) return # desc="I own %s." % name # what=thing.as_entity() # ent = Entity(description=desc, what=what) # self.send(Operation("thought",ent)) dictlist.add_value(self.things,name,thing) log.debug(3,"\tafter: "+str(self.things))
def add_thing(self,thing): """I own this thing""" #CHEAT!: this feature not yet supported ## if not thing.location: ## thing.location=self.get_knowledge("location",thing.place) log.debug(3,str(self)+" "+str(thing)+" before add_thing: "+str(self.things)) #thought about owing thing name = self.thing_name(thing) if not name: self.pending_things.append(thing.id) return desc="I own %s." % name what=thing.as_entity() ent = Entity(description=desc, what=what) self.send(Operation("thought",ent)) dictlist.add_value(self.things,name,thing) log.debug(3,"\tafter: "+str(self.things))
def set_goals(self, name, goals): """Set goals. The 'goals' list contains all of the goals for a given subject ('name'). All previous goals for the given subject will be removed. This means that this method can be also be used for deleting goals if the 'goals' list is empty.""" #start by evaluating the goals. This is done before we remove any goals, so as if there's an error #when creating the goals, the process will be aborted without any side effects new_goals=[] for str_goal in goals: #CHEAT!: remove eval (this and later) goal=eval("mind.goals."+str_goal) if const.debug_thinking: goal.debug=1 goal.str=str_goal if type(name)==StringType: goal.key=eval(name) else: goal.key=name new_goals.append(goal) #once we've successfully created the new goals we'll remove the old ones if name in self.known_goals: goallist=self.known_goals[name] for goal in goallist: if hasattr(goal,"trigger"): dictlist.remove_value(self.trigger_goals, goal) else: self.goals.remove(goal) del self.known_goals[name] def insert_goal(goal): if hasattr(goal,"trigger"): dictlist.add_value(self.trigger_goals, goal.trigger(), goal) else: for i in range(len(self.goals)-1,-1,-1): if self.cmp_goal_importance(self.goals[i],goal): self.goals.insert(i+1,goal) return self.goals.insert(0,goal) for goal in new_goals: insert_goal(goal) dictlist.add_value(self.known_goals, name, goal)
def add_goal(self, name, str_goal): """add goal...""" #CHEAT!: remove eval (this and later) goal=eval("mind.goals."+str_goal) if const.debug_thinking: goal.debug=1 goal.str=str_goal if type(name)==StringType: goal.key=eval(name) else: goal.key=name self.add_knowledge("goal",name,goal) if hasattr(goal,"trigger"): dictlist.add_value(self.trigger_goals, goal.trigger(), goal) return for i in range(len(self.goals)-1,-1,-1): if self.cmp_goal_importance(self.goals[i],goal): self.goals.insert(i+1,goal) return self.goals.insert(0,goal)