コード例 #1
0
ファイル: SequenceTest.cs プロジェクト: lKrinl/SDBS-v0.2.1.0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldNotRestartFirstChild_WhenSecondChildFails()
        {
            MockNode firstChild   = new MockNode();
            MockNode secondChild  = new MockNode(false);
            Sequence sut          = new Sequence(firstChild, secondChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

            firstChild.Finish(true);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);

            sut.StopLowerPriorityChildrenForChild(firstChild, true);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsFalse(behaviorTree.WasSuccess);
        }
コード例 #2
0
ファイル: RepeaterTest.cs プロジェクト: agarzonp/Tanks
        public void ShouldNotLeaveObserversRegistered_WhenInactive()
        {
            MockNode child        = new MockNode();
            Repeater sut          = new Repeater(-1, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            child.Finish(true);

            Assert.AreEqual(1, behaviorTree.Clock.NumTimers);
            Assert.AreEqual(0, behaviorTree.Clock.NumUpdateObservers);

            Timer.Update(0.01f);
            child.Finish(false);

            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsFalse(behaviorTree.WasSuccess);

            Assert.AreEqual(0, behaviorTree.Clock.NumTimers);
            Assert.AreEqual(0, behaviorTree.Clock.NumUpdateObservers);
        }
コード例 #3
0
        public void ShouldNotThrowErrors_WhenObservingKeysThatDontExist()
        {
            TestRoot        behaviorTree = null;
            MockNode        child        = new MockNode();
            BlackboardQuery sut          = new BlackboardQuery(new string[] { "key1", "key2" }, Stops.IMMEDIATE_RESTART, () => {
                object o1 = behaviorTree.Blackboard.Get <float>("key1");
                object o2 = behaviorTree.Blackboard.Get <float>("key2");
                float f1  = (float)o1;
                float f2  = (float)o2;

                if ((f1 > 0.99) && (f2 < 5.99f))
                {
                    return(true);
                }
                return(false);
            }, child);

            behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();
            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);
        }
コード例 #4
0
        public void ShouldFailAndNotSetCooldown_WhenDecorateeFails_DueToParameter()
        {
            MockNode failingChild = new MockNode();
            Cooldown sut          = new Cooldown(1, false, true, failingChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            // start
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // make child fail
            failingChild.Finish(false);

            // ensure we're stopped
            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);

            // start again
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // ensure the child has been started again ( due to cooldown not active )
            Assert.AreEqual(Node.State.ACTIVE, failingChild.CurrentState);
        }
コード例 #5
0
        public void StopLowerPriorityChildrenForChild_WithoutImmediateRestart_ShouldThrowError()
        {
            Parallel.Policy failurePolicy = Parallel.Policy.ALL;
            Parallel.Policy successPolicy = Parallel.Policy.ALL;

            MockNode firstChild   = new MockNode();
            MockNode secondChild  = new MockNode();
            Parallel sut          = new Parallel(successPolicy, failurePolicy, firstChild, secondChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();
            firstChild.Finish(false);
            bool bExceptionCought = false;

            try
            {
                sut.StopLowerPriorityChildrenForChild(firstChild, false);
            }
            catch
            {
                bExceptionCought = true;
            }
            Assert.AreEqual(bExceptionCought, true);
        }
コード例 #6
0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldRestartFirstChild_WhenSecondChildFails()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode(false);
            RandomSelector sut          = new RandomSelector(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            // TODO: will we keep the priority or will we switch to the priority defined by the randomized children?
            RandomSelector.DebugSetSeed(2);

            behaviorTree.Start();
            firstChild.Finish(false);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);

            sut.StopLowerPriorityChildrenForChild(firstChild, true);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.IsFalse(behaviorTree.DidFinish);
        }
コード例 #7
0
ファイル: GeneralTest.cs プロジェクト: malering/ET
        public void ShouldNotActivateLowerPriorityBranchInCaseMultipleBranchesGetValid()
        {
            this.Timer      = new Clock();
            this.Blackboard = new Blackboard(Timer);

            // our mock nodes we want to query for status
            MockNode firstChild  = new MockNode(false); // false -> fail when aborted
            MockNode secondChild = new MockNode(false);
            MockNode thirdChild  = new MockNode(false);

            // coniditions for each subtree that listen the BB for events
            BlackboardCondition firstCondition  = new BlackboardCondition("branch1", Operator.IS_EQUAL, true, Stops.IMMEDIATE_RESTART, firstChild);
            BlackboardCondition secondCondition = new BlackboardCondition("branch2", Operator.IS_EQUAL, true, Stops.IMMEDIATE_RESTART, secondChild);
            BlackboardCondition thirdCondtion   = new BlackboardCondition("branch3", Operator.IS_EQUAL, true, Stops.IMMEDIATE_RESTART, thirdChild);

            // set up the tree
            Selector selector     = new Selector(firstCondition, secondCondition, thirdCondtion);
            TestRoot behaviorTree = new TestRoot(Blackboard, Timer, selector);

            // intially we want to activate branch3
            Blackboard.Set("branch3", true);

            // start the tree
            behaviorTree.Start();

            // verify the third child is running
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, thirdChild.CurrentState);
            Assert.AreEqual(0, firstChild.DebugNumStartCalls);
            Assert.AreEqual(0, secondChild.DebugNumStartCalls);
            Assert.AreEqual(1, thirdChild.DebugNumStartCalls);

            // change keys so the first & second conditions get true, too
            Blackboard.Set("branch1", true);
            Blackboard.Set("branch2", true);

            // still the third child should be active, as the blackboard didn't yet notifiy the nodes
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, thirdChild.CurrentState);
            Assert.AreEqual(0, firstChild.DebugNumStartCalls);
            Assert.AreEqual(0, secondChild.DebugNumStartCalls);
            Assert.AreEqual(1, thirdChild.DebugNumStartCalls);

            // tick the timer to ensure the blackboard notifies the nodes
            Timer.Update(0.1f);

            // now we should be in branch1
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, thirdChild.CurrentState);
            Assert.AreEqual(1, firstChild.DebugNumStartCalls);
            Assert.AreEqual(0, secondChild.DebugNumStartCalls);
            Assert.AreEqual(1, thirdChild.DebugNumStartCalls);

            // disable first branch
            Blackboard.Set("branch1", false);
            Timer.Update(0.1f);

            // and now the second branch should be active
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, thirdChild.CurrentState);
            Assert.AreEqual(1, firstChild.DebugNumStartCalls);
            Assert.AreEqual(1, secondChild.DebugNumStartCalls);
            Assert.AreEqual(1, thirdChild.DebugNumStartCalls);
        }