Example #1
0
        public void ShouldFailInsteadOfWait_WhenCooldownActive_DueToParameter()
        {
            MockNode child        = new MockNode();
            Cooldown sut          = new Cooldown(1, false, false, true, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

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

            // make child suceed
            child.Finish(true);

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

            // start again
            behaviorTree.Start();

            // ensure that neither this node nor the child has not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock past cooldown, start the tree again and check that we could be activated again
            behaviorTree.Clock.Update(2.0f);
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, child.CurrentState);
        }
Example #2
0
        public void ShouldSucceedAndSetCooldown_WhenDecorateeSucceeds()
        {
            MockNode child        = new MockNode();
            Cooldown sut          = new Cooldown(1, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

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

            // make child suceed
            child.Finish(true);

            // 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 not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock past cooldown and check that the child has been activated
            behaviorTree.Clock.Update(2.0f);
            Assert.AreEqual(Node.State.ACTIVE, child.CurrentState);
        }
Example #3
0
        public void ShouldSucceedAndSetCooldownRightAway_WhenDecorateeSucceeds()
        {
            MockNode child        = new MockNode();
            Cooldown sut          = new Cooldown(1, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

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

            // wait 1.5 seconds
            behaviorTree.Clock.Update(1.5f);

            // make child suceed
            child.Finish(true);

            // 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 as well ( due to cooldown )
            Assert.AreEqual(Node.State.ACTIVE, child.CurrentState);
        }
Example #4
0
        public void ShouldFail_WhenFirstChildFails()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode();
            RandomSequence sut          = new RandomSequence(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

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

            MockNode activeChild = sut.DebugGetActiveChild() as MockNode;

            Assert.NotNull(activeChild);
            MockNode inactiveChild = activeChild == firstChild ? secondChild : firstChild;

            Assert.AreEqual(Node.State.ACTIVE, activeChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, inactiveChild.CurrentState);

            activeChild.Finish(false);

            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);
        }
Example #5
0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldNotRestartFirstChild_WhenSecondChildFails()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode(false);
            RandomSequence sut          = new RandomSequence(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

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

            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);
        }
Example #6
0
        public void ShouldProcceedToSecondChild_WhenFirstChildSucceeded()
        {
            MockNode firstChild   = new MockNode();
            MockNode secondChild  = new MockNode();
            Sequence sut          = new Sequence(firstChild, secondChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

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

            firstChild.Finish(true);

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

            secondChild.Finish(false);

            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);
        }
Example #7
0
        public void ShouldSucceed_WhenFirstChildSuccessful()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode();
            RandomSelector sut          = new RandomSelector(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

            MockNode firstActiveChild = sut.DebugGetActiveChild() as MockNode;
            MockNode inactiveChild    = firstActiveChild == firstChild ? secondChild : firstChild;

            Assert.IsNotNull(firstActiveChild);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstActiveChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, inactiveChild.CurrentState);

            firstActiveChild.Finish(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.IsTrue(behaviorTree.WasSuccess);
        }
Example #8
0
        public void ShouldSucceedButSetCooldownAfterDecorator_WhenDecorateeSucceeds_DueToParameter()
        {
            MockNode child        = new MockNode();
            Cooldown sut          = new Cooldown(1, true, false, false, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

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

            // wait 1.5 seconds
            behaviorTree.Clock.Update(1.5f);

            // make child suceed
            child.Finish(true);

            // 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 not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock to be at 2.0 seconds
            behaviorTree.Clock.Update(0.5f);

            // ensure the child has not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock to be at 3 seconds
            behaviorTree.Clock.Update(1.0f);

            // ensure the child has been started
            Assert.AreEqual(Node.State.ACTIVE, child.CurrentState);
        }
Example #9
0
        public void ShouldEndWithFailure_WhenYieldsFailure()
        {
            var timer      = new Clock();
            var blackboard = new Blackboard(timer);
            var action     = new CoroutineAction(TestFailCoroutine);
            var tree       = new TestRoot(blackboard, timer, action);

            tree.Start();                                              // First step should run
            timer.Update(0.1f);                                        // Tick - Second step should run
            timer.Update(0.1f);                                        // Tick - Third step should run

            Assert.AreEqual(Node.State.INACTIVE, action.CurrentState); // Action should have ended...
            Assert.IsFalse(action.DebugLastResult);                    // ... with failure
        }
Example #10
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);
            sut.StopLowerPriorityChildrenForChild(firstChild, false);
        }
Example #11
0
        public void ShouldStartAllChildrenInParallel()
        {
            Parallel.Policy successPolicy = Parallel.Policy.ONE;
            Parallel.Policy failurePolicy = Parallel.Policy.ONE;
            MockNode        firstChild    = new MockNode();
            MockNode        secondChild   = new MockNode();
            Parallel        sut           = new Parallel(successPolicy, failurePolicy, firstChild, secondChild);
            TestRoot        behaviorTree  = CreateBehaviorTree(sut);

            behaviorTree.Start();

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
        }
Example #12
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);
        }
Example #13
0
        public void AllStepsShouldRun_WhenDoesntYieldFailure()
        {
            var timer      = new Clock();
            var blackboard = new Blackboard(timer);
            var action     = new CoroutineAction(TestCoroutine);
            var tree       = new TestRoot(blackboard, timer, action);

            tree.Start();       // First step should run
            timer.Update(0.1f); // Tick - Second step should run
            timer.Update(0.1f); // Tick - Third step should run

            Assert.AreEqual(1, firstStepRunCount);
            Assert.AreEqual(1, secondStepRunCount);
            Assert.AreEqual(1, thirdStepRunCount);
        }
Example #14
0
        public void ShouldFail_WhenDecorateeFails()
        {
            MockNode failingChild = new MockNode();
            Repeater sut          = new Repeater(-1, failingChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

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

            failingChild.Finish(false);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsFalse(behaviorTree.WasSuccess);
        }
Example #15
0
        public void StepAfterFailureShouldNotRun_WhenYieldsFailure()
        {
            var timer      = new Clock();
            var blackboard = new Blackboard(timer);
            var action     = new CoroutineAction(TestFailCoroutine);
            var tree       = new TestRoot(blackboard, timer, action);

            tree.Start();       // First step should run
            timer.Update(0.1f); // Tick - Second step should run
            timer.Update(0.1f); // Tick - Third step should run

            Assert.AreEqual(1, firstStepRunCount);
            Assert.AreEqual(1, secondStepRunCount);
            Assert.AreEqual(0, thirdStepRunCount); // Third step should not run as coroutine is failing earlier
        }
Example #16
0
        public void ShouldSucceed_WhenStoppedExplicitlyButChildStillFinishesSuccessfully()
        {
            MockNode succeedingChild = new MockNode(true);
            Sequence sut             = new Sequence(succeedingChild);
            TestRoot behaviorTree    = CreateBehaviorTree(sut);

            behaviorTree.Start();

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

            sut.Stop();

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.True(behaviorTree.WasSuccess);
        }
Example #17
0
        public void ShouldSucceed_WhenSingleChildSucceeds()
        {
            MockNode succeedingChild = new MockNode();
            Sequence sut             = new Sequence(succeedingChild);
            TestRoot behaviorTree    = CreateBehaviorTree(sut);

            behaviorTree.Start();

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

            succeedingChild.Finish(true);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsTrue(behaviorTree.WasSuccess);
        }
Example #18
0
        public void ShouldFail_WhenStoppedExplicitly()
        {
            MockNode failingChild = new MockNode(false);
            Sequence sut          = new Sequence(failingChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

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

            sut.Stop();

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsFalse(behaviorTree.WasSuccess);
        }
Example #19
0
        public void ShouldSucceed_WhenNotAllChildrenFailed_AndFailPolicyAll_AndSucessPolicyOne()
        {
            Parallel.Policy failurePolicy = Parallel.Policy.ALL;
            Parallel.Policy successPolicy = Parallel.Policy.ONE;
            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);
            secondChild.Finish(true);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsTrue(behaviorTree.WasSuccess);
        }
Example #20
0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldRestartChild()
        {
            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);
            sut.StopLowerPriorityChildrenForChild(firstChild, true);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);
        }
Example #21
0
        public void ShouldEndWithSuccess_WhenDoesntYieldFailure()
        {
            var timer      = new Clock();
            var blackboard = new Blackboard(timer);
            var action     = new CoroutineAction(TestCoroutine);
            var tree       = new TestRoot(blackboard, timer, action);

            tree.Start();       // First step should run
            timer.Update(0.1f); // Tick - Second step should run
            timer.Update(0.1f); // Tick - Third step should run

            Assert.AreEqual(1, firstStepRunCount);
            Assert.AreEqual(1, secondStepRunCount);
            Assert.AreEqual(1, thirdStepRunCount);

            Assert.AreEqual(Node.State.INACTIVE, action.CurrentState); // Action should have ended...
            Assert.IsTrue(action.DebugLastResult);                     // ... with success
        }
Example #22
0
        public void ShouldFail_WhenAllChildrenFailed_AndFailPolicyAll()
        {
            Parallel.Policy failurePolicy = Parallel.Policy.ALL;
            foreach (Parallel.Policy successPolicy in ALL_SUCCESS_POLICIES)
            {
                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);
                secondChild.Finish(false);

                Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
                Assert.IsTrue(behaviorTree.DidFinish);
                Assert.IsFalse(behaviorTree.WasSuccess);
            }
        }
Example #23
0
        public void ShouldSucceed_WhenOneChildSuccessful_AndSuccessPolicyOne()
        {
            Parallel.Policy successPolicy = Parallel.Policy.ONE;
            foreach (Parallel.Policy failurePolicy in ALL_FAILURE_POLICIES)
            {
                MockNode firstChild   = new MockNode();
                MockNode secondChild  = new MockNode(false);
                Parallel sut          = new Parallel(successPolicy, failurePolicy, firstChild, secondChild);
                TestRoot behaviorTree = CreateBehaviorTree(sut);

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

                Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
                Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
                Assert.IsTrue(behaviorTree.DidFinish);
                Assert.IsTrue(behaviorTree.WasSuccess);
            }
        }
Example #24
0
        public void ShouldWaitForNextUpdate_WhenDecorateeSucceedsImmediately()
        {
            MockNode succeedingChild = new MockNode();
            Repeater sut             = new Repeater(-1, succeedingChild);
            TestRoot behaviorTree    = CreateBehaviorTree(sut);

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

            // the child should not have been immediately restarted
            Assert.AreEqual(Node.State.INACTIVE, succeedingChild.CurrentState);

            // after update it's ok to have
            Timer.Update(0.01f);
            Assert.AreEqual(Node.State.ACTIVE, succeedingChild.CurrentState);

            Assert.IsFalse(behaviorTree.DidFinish);
        }
Example #25
0
        public void ShouldSucceed_WhenStoppedExplicitlyButChildStillFinishesSuccessfully()
        {
            foreach (Parallel.Policy successPolicy in ALL_SUCCESS_POLICIES)
            {
                foreach (Parallel.Policy failurePolicy in ALL_FAILURE_POLICIES)
                {
                    MockNode succeedingChild = new MockNode(true);
                    Parallel sut             = new Parallel(successPolicy, failurePolicy, succeedingChild);
                    TestRoot behaviorTree    = CreateBehaviorTree(sut);

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

                    sut.Stop();

                    Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
                    Assert.IsTrue(behaviorTree.DidFinish);
                    Assert.True(behaviorTree.WasSuccess);
                }
            }
        }
Example #26
0
        public void ShouldFail_WhenSingleChildFails()
        {
            foreach (Parallel.Policy sucessPolicy in ALL_SUCCESS_POLICIES)
            {
                foreach (Parallel.Policy failurePolicy in ALL_FAILURE_POLICIES)
                {
                    MockNode failingChild = new MockNode();
                    Parallel sut          = new Parallel(sucessPolicy, failurePolicy, failingChild);
                    TestRoot behaviorTree = CreateBehaviorTree(sut);

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

                    failingChild.Finish(false);

                    Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
                    Assert.IsTrue(behaviorTree.DidFinish);
                    Assert.IsFalse(behaviorTree.WasSuccess);
                }
            }
        }
Example #27
0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldRestartFirstChild_WhenSecondChildSucceeds()
        {
            MockNode firstChild   = new MockNode();
            MockNode secondChild  = new MockNode(true);
            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.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.IsFalse(behaviorTree.DidFinish);
        }
        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 (Exception) {
                bExceptionCought = true;
            }
            Assert.AreEqual(bExceptionCought, true);
        }
        public void ShouldListenToEvents_WhenUsingChildBlackboard()
        {
            Blackboard rootBlackboard = new Blackboard(clock);
            Blackboard blackboard     = new Blackboard(rootBlackboard, clock);

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

            // conditions 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);

            // set up the tree
            Selector selector     = new Selector(firstCondition, secondCondition);
            TestRoot behaviorTree = new TestRoot(blackboard, clock, selector);

            // intially we want to activate branch2
            rootBlackboard.Set("branch2", true);

            // start the tree
            behaviorTree.Start();

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

            // verify the second child is running
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);

            // change keys so the first conditions get true, too
            rootBlackboard.Set("branch1", true);

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

            // now we should be in branch1
            Assert.AreEqual(Node.State.ACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
        }
Example #30
0
        public void StopLowerPriorityChildrenForChild_WithoutImmediateRestart_ShouldCancelSecondChild()
        {
            MockNode firstChild   = new MockNode();
            MockNode secondChild  = new MockNode();
            Selector sut          = new Selector(firstChild, secondChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            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, false);

            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);
        }