Exemple #1
0
 def update_goal(self, goal, str_goal):
     new_goal = self.create_goal(goal.key, str_goal)
     new_goal.id = goal.id
     #We need to handle the case where a goal which had a trigger is replaced by one
     #that hasn't, and the opposite
     if hasattr(goal,"trigger"):
         dictlist.remove_value(self.trigger_goals, goal)
         self.insert_goal(new_goal, goal.id)
     else:
         if hasattr(new_goal,"trigger"):
             self.goals.remove(goal)
             self.insert_goal(new_goal, goal.id)
         else:
             index=self.goals.index(goal)
             self.goals[index] = new_goal
Exemple #2
0
 def update_goal(self, goal, str_goal):
     new_goal = self.create_goal(goal.key, str_goal)
     new_goal.id = goal.id
     #We need to handle the case where a goal which had a trigger is replaced by one
     #that hasn't, and the opposite
     if hasattr(goal, "trigger"):
         dictlist.remove_value(self.trigger_goals, goal)
         self.insert_goal(new_goal, goal.id)
     else:
         if hasattr(new_goal, "trigger"):
             self.goals.remove(goal)
             self.insert_goal(new_goal, goal.id)
         else:
             index = self.goals.index(goal)
             self.goals[index] = new_goal
Exemple #3
0
 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)
Exemple #4
0
    def update_goal(self, goal, str_goal):
        try:
            new_goal = self.create_goal(goal.key, str_goal)
        except BaseException as e:
            print("Error when updating goal: " + str(e))
            return

        new_goal.id = goal.id
        #We need to handle the case where a goal which had a trigger is replaced by one
        #that hasn't, and the opposite
        if hasattr(goal, "trigger"):
            dictlist.remove_value(self.trigger_goals, goal)
            self.insert_goal(new_goal, goal.id)
        else:
            if hasattr(new_goal, "trigger"):
                self.goals.remove(goal)
                self.insert_goal(new_goal, goal.id)
            else:
                index = self.goals.index(goal)
                self.goals[index] = new_goal
Exemple #5
0
 def update_goal(self, goal, str_goal):
     try:
         new_goal = self.create_goal(goal.key, str_goal)
     except BaseException as e:
         print("Error when updating goal: " + str(e))
         return
     
     new_goal.id = goal.id
     #We need to handle the case where a goal which had a trigger is replaced by one
     #that hasn't, and the opposite
     if hasattr(goal,"trigger"):
         dictlist.remove_value(self.trigger_goals, goal)
         self.insert_goal(new_goal, goal.id)
     else:
         if hasattr(new_goal,"trigger"):
             self.goals.remove(goal)
             self.insert_goal(new_goal, goal.id)
         else:
             index=self.goals.index(goal)
             self.goals[index] = new_goal
Exemple #6
0
 def remove_goal(self, goal):
     """Removes a goal."""
     if hasattr(goal,"trigger"):
         dictlist.remove_value(self.trigger_goals, goal)
     else:
         self.goals.remove(goal)
Exemple #7
0
 def remove_thing(self, thing):
     """I don't own this anymore (it may not exist)"""
     dictlist.remove_value(self.things, thing)
Exemple #8
0
 def remove_goal(self, goal):
     """Removes a goal."""
     if hasattr(goal, "trigger"):
         dictlist.remove_value(self.trigger_goals, goal)
     else:
         self.goals.remove(goal)
Exemple #9
0
 def remove_thing(self, thing):
     """I don't own this anymore (it may not exist)"""
     dictlist.remove_value(self.things, thing)