From cf1f2224b3625b01a6aa7db221403849b308b3bc Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 29 Nov 2010 00:00:26 -0500 Subject: Making recursive behaviors work. Some bugs existed before. Adding running behavior which makes a signal bounce back and forth. --- behaviors/BehaviorChain.py | 10 +++++++++- behaviors/RunningBehavior.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 behaviors/RunningBehavior.py (limited to 'behaviors') diff --git a/behaviors/BehaviorChain.py b/behaviors/BehaviorChain.py index 15f7d74..8bf97bb 100644 --- a/behaviors/BehaviorChain.py +++ b/behaviors/BehaviorChain.py @@ -2,9 +2,17 @@ from operationscore.Behavior import * import Util import pdb class BehaviorChain(Behavior): + def behaviorInit(self): + self.feedback = {} #dictionary to allow feedback of recursives def processResponse(self, sensorInputs, recursiveInputs): response = sensorInputs for behaviorId in self['ChainedBehaviors']: behavior = Util.getComponentById(behaviorId) - response = behavior.immediateProcessInput(response) + if behaviorId in self.feedback: + recurrence = self.feedback[behaviorId] + else: + recurrence = [] + (response,recurrence) = behavior.immediateProcessInput(response,\ + recurrence) + self.feedback[behaviorId] = recurrence return response diff --git a/behaviors/RunningBehavior.py b/behaviors/RunningBehavior.py new file mode 100644 index 0000000..255ce69 --- /dev/null +++ b/behaviors/RunningBehavior.py @@ -0,0 +1,21 @@ +from operationscore.Behavior import * +import pdb +import Util +class RunningBehavior(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + newResponses = sensorInputs + ret = [] + ret += newResponses + for recurInput in recursiveInputs: + outDict = dict(recurInput) + if not 'Dir' in outDict: + outDict['Dir'] = 1 #to the right + outDict['Location']= Util.addLocations(outDict['Location'], + (self['StepSize']*outDict['Dir'],0)) + if not Util.pointWithinBoundingBox(outDict['Location'], \ + Util.getScreen().getSize()): + outDict['Dir'] *= -1 + ret.append(outDict) + ret += newResponses + return (ret, ret) + -- cgit v1.2.3