def think(self): if const.debug_thinking: log.thinking("think: "+str(self.id)) output=self.fulfill_goals(self.time) # if output and const.debug_thinking: # log.thinking(str(self)+" result at "+str(self.time)+": "+output[-1][0].description) return output
def check_goal_rec(self, me, time, depth): """check (sub)goal recursively""" res, deb = None, "" if self.irrelevant: return res, deb #is it right time range? if self.time and not time.is_now(self.time): return res, deb if self.debug: log.thinking("\t" * depth + "GOAL: bef fulfilled: " + self.desc + " " + ` self.fulfilled `) if self.fulfilled(me): return res, deb for sg in self.subgoals: if type(sg) == FunctionType or type(sg) == MethodType: res = sg(me) if res == None: if self.debug: log.thinking("\t" * depth + "GOAL: function: " + ` sg ` + " " + ` res `) deb = sg.__name__ + "()" return res, deb else: if self.debug: log.thinking("\t" * depth + "GOAL: bef sg: " + sg.desc) res, deb = sg.check_goal_rec(me, time, depth + 1) if self.debug: log.thinking("\t" * depth + "GOAL: aft sg: " + sg.desc + " " + str(res)) if len(deb) > 0: deb = sg.info() + "." + deb return res, deb return res, deb
def think(self): if const.debug_thinking: log.thinking("think: " + str(self.id)) output = self.fulfill_goals(self.time) # if output and const.debug_thinking: # log.thinking(str(self)+" result at "+str(self.time)+": "+output[-1][0].description) return output
def check_goal(self, me, time): "executes goal. Any response that's not None causes the goal checking code to stop after this goal" if self.debug: log.thinking("GOAL desc: " + str(self)) res, debug_info = self.check_goal_rec(me, time, 0, "") if len(debug_info) != 0: # Keep a copy of the debug info for the "report" method. self.lastProcessedGoals = debug_info return res
def check_goal(self, me, time): "executes goal, see top of file" if self.debug: log.thinking("GOAL desc: " + self.str) res, debugInfo = self.check_goal_rec(me, time, 0, "") if len(debugInfo) != 0: #Keep a copy of the debug info for the "report" method. self.lastProcessedGoals = debugInfo if res != None: info_ent = Entity(op=res, description=debugInfo) return res + Operation("goal_info", info_ent)
def check_goal(self, me, time): "executes goal, see top of file" if self.debug: log.thinking("GOAL desc: "+self.str) res,debugInfo=self.check_goal_rec(me,time,0,"") if len(debugInfo)!=0: #Keep a copy of the debug info for the "report" method. self.lastProcessedGoals=debugInfo if res!=None: info_ent=Entity(op=res,description=debugInfo) return res+Operation("goal_info",info_ent)
def check_goal(self, me, time): "executes goal, see top of file" if self.debug: log.thinking("GOAL desc: " + self.str) res, deb = self.check_goal_rec(me, time, 0) if len(deb) != 0: deb = self.info() + "." + deb # print deb if res != None: info_ent = Entity(op=res, description=deb) return res + Operation("goal_info", info_ent)
def check_goal(self, me, time): "executes goal, see top of file" if self.debug: log.thinking("GOAL desc: "+self.str) res,deb=self.check_goal_rec(me,time,0) if len(deb)!=0: deb=self.info()+"."+deb # print deb if res!=None: info_ent=Entity(op=res,description=deb) return res+Operation("goal_info",info_ent)
def check_goal_rec(self, me, time, depth, debugInfo): """check (sub)goal recursively. This is done by iterating over all subgoals, breaking if any subgoal returns an operation.""" res = None if self.irrelevant: return res, debugInfo #is it right time range? if self.time and not time.is_now(self.time): return res, debugInfo if self.debug: log.thinking("\t" * depth + "GOAL: bef fulfilled: " + self.desc + " " + ` self.fulfilled `) if self.fulfilled(me): self.is_fulfilled = 1 if self.debug: log.thinking("\t" * depth + "GOAL: is fulfilled: " + self.desc + " " + ` self.fulfilled `) return res, debugInfo else: if self.debug: log.thinking("\t" * depth + "GOAL: is not fulfilled: " + self.desc + " " + ` self.fulfilled `) self.is_fulfilled = 0 debugInfo = debugInfo + "." + self.info() #Iterate over all subgoals, but break if any goal returns an operation for sg in self.subgoals: if sg == None: continue if type(sg) == FunctionType or type(sg) == MethodType: if self.debug: log.thinking("\t" * depth + "GOAL: bef function: " + ` sg ` + " " + ` res `) res = sg(me) if self.debug: log.thinking("\t" * depth + "GOAL: aft function: " + ` sg ` + " " + ` res `) debugInfo = debugInfo + "." + sg.__name__ + "()" if res != None: #If the function generated an op, stop iterating here and return return res, debugInfo else: if self.debug: log.thinking("\t" * depth + "GOAL: bef sg: " + sg.desc) res, debugInfo = sg.check_goal_rec(me, time, depth + 1, debugInfo) if self.debug: log.thinking("\t" * depth + "GOAL: aft sg: " + sg.desc + ", Result: " + str(res)) #If the subgoal generated an op, stop iterating here and return if res != None: return res, debugInfo return res, debugInfo
def check_goal_rec(self, me, time, depth): """check (sub)goal recursively""" res,deb=None,"" if self.irrelevant: return res,deb #is it right time range? if self.time and not time.is_now(self.time): return res,deb if self.debug: log.thinking("\t"*depth+"GOAL: bef fulfilled: "+self.desc+" "+`self.fulfilled`) if self.fulfilled(me): self.is_fulfilled = 1 return res,deb else: self.is_fulfilled = 0 for sg in self.subgoals: if type(sg)==FunctionType or type(sg)==MethodType: res=sg(me) if res==None: if self.debug: log.thinking("\t"*depth+"GOAL: function: "+`sg`+" "+`res`) deb=sg.__name__+"()" return res,deb else: if self.debug: log.thinking("\t"*depth+"GOAL: bef sg: "+sg.desc) res,deb=sg.check_goal_rec(me,time,depth+1) if self.debug: log.thinking("\t"*depth+"GOAL: aft sg: "+sg.desc+" "+str(res)) if len(deb)>0: deb=sg.info()+"."+deb return res,deb return res,deb
def check_goal_rec(self, me, time, depth, debugInfo): """check (sub)goal recursively. This is done by iterating over all subgoals, breaking if any subgoal returns an operation.""" res=None if self.irrelevant: return res,debugInfo #is it right time range? if self.time and not time.is_now(self.time): return res,debugInfo if self.debug: log.thinking("\t"*depth+"GOAL: bef fulfilled: "+self.desc+" "+`self.fulfilled`) if self.fulfilled(me): self.is_fulfilled = 1 if self.debug: log.thinking("\t"*depth+"GOAL: is fulfilled: "+self.desc+" "+`self.fulfilled`) return res,debugInfo else: if self.debug: log.thinking("\t"*depth+"GOAL: is not fulfilled: "+self.desc+" "+`self.fulfilled`) self.is_fulfilled = 0 debugInfo=debugInfo+"."+self.info() #Iterate over all subgoals, but break if any goal returns an operation for sg in self.subgoals: if type(sg)==FunctionType or type(sg)==MethodType: if self.debug: log.thinking("\t"*depth+"GOAL: bef function: "+`sg`+" "+`res`) res=sg(me) if self.debug: log.thinking("\t"*depth+"GOAL: aft function: "+`sg`+" "+`res`) debugInfo=debugInfo+"."+sg.__name__+"()" if res!=None: #If the function generated an op, stop iterating here and return return res,debugInfo else: if self.debug: log.thinking("\t"*depth+"GOAL: bef sg: "+sg.desc) res,debugInfo=sg.check_goal_rec(me,time,depth+1,debugInfo) if self.debug: log.thinking("\t"*depth+"GOAL: aft sg: "+sg.desc+", Result: "+str(res)) #If the subgoal generated an op, stop iterating here and return if res!=None: return res,debugInfo return res,debugInfo
def check_goal_recursively(self, me, depth, debug_info): """check (sub)goal recursively. This is done by iterating over all sub goals, breaking if any sub goal returns an operation.""" res = None if self.irrelevant: return res, debug_info if self.debug: log.thinking("\t" * depth + "GOAL: bef fulfilled: " + self.desc + " " + repr(self.fulfilled)) if self.fulfilled(me): self.is_fulfilled = 1 if self.debug: log.thinking("\t" * depth + "GOAL: is fulfilled: " + self.desc + " " + repr(self.fulfilled)) return res, debug_info else: if self.debug: log.thinking("\t" * depth + "GOAL: is not fulfilled: " + self.desc + " " + repr(self.fulfilled)) self.is_fulfilled = 0 debug_info = debug_info + "." + self.info() # Iterate over all sub goals, but break if any goal returns an operation for sg in self.sub_goals: if sg is None: continue if isinstance(sg, types.FunctionType) or isinstance(sg, types.MethodType): if self.debug: log.thinking("\t" * depth + "GOAL: bef function: " + repr(sg) + " " + repr(res)) res = sg(me) if self.debug: log.thinking("\t" * depth + "GOAL: aft function: " + repr(sg) + " " + repr(res)) debug_info = debug_info + "." + sg.__name__ + "()" if res is not None: # If the function generated something, stop iterating here and return return res, debug_info else: if self.debug: log.thinking("\t" * depth + "GOAL: bef sg: " + sg.desc) # If the subgoal is irrelevant, remove it if sg.irrelevant: self.sub_goals.remove(sg) continue res, debug_info = sg.check_goal_recursively(me, depth + 1, debug_info) if self.debug: log.thinking("\t" * depth + "GOAL: aft sg: " + sg.desc + ", Result: " + str(res)) # If the subgoal generated an op, stop iterating here and return if res is not None: return res, debug_info return res, debug_info