コード例 #1
0
        public void InvertRunningTest()
        {
            var tickProvider = new TestTickSupplier();
            var root         = new BehaviourTreeBuilder <TestBlackboard>()
                               .Inverter("Invert status")
                               .Wait("Increment counter 1", 3, tickProvider)
                               .End()
                               .Build();
            var metadata   = new BehaviourTreeMetadata <TestBlackboard>(root);
            var data       = metadata.CreateExecutionData();
            var executor   = new BehaviourTreeExecutor <TestBlackboard>(root);
            var blackboard = new TestBlackboard();

            executor.Start(data);

            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);

            tickProvider.Tick();
            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);

            tickProvider.Tick();
            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);

            tickProvider.Tick();
            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Failure, data.Statuses[root.Id]);
            Assert.AreEqual(0, data.Stack.Count);
        }
コード例 #2
0
        public void SelectorRunningTest()
        {
            var tickProvider = new TestTickSupplier();
            var root         = new BehaviourTreeBuilder <TestBlackboard>()
                               .Selector("Sequence")
                               .AlwaysFail("Fail increment")
                               .Do("Increment counter 1", TestActions.IncrementCounter1)
                               .End()
                               .Wait("Wait 1 tick", 1, tickProvider)
                               .Do("Increment counter 2", TestActions.IncrementCounter2)
                               .End()
                               .Build();
            var metadata   = new BehaviourTreeMetadata <TestBlackboard>(root);
            var data       = metadata.CreateExecutionData();
            var executor   = new BehaviourTreeExecutor <TestBlackboard>(root);
            var blackboard = new TestBlackboard();

            executor.Start(data);

            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);
            Assert.AreEqual(1, blackboard.Counter1);
            Assert.AreEqual(0, blackboard.Counter2);

            tickProvider.Tick();
            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Success, data.Statuses[root.Id]);
            Assert.AreEqual(1, blackboard.Counter1);
            Assert.AreEqual(0, blackboard.Counter2);
            Assert.AreEqual(0, data.Stack.Count);
        }
コード例 #3
0
        public void InterruptionTest()
        {
            var tickProvider = new TestTickSupplier();
            var root         = new BehaviourTreeBuilder <TestBlackboard>()
                               .Sequence("Sequence")
                               .Inverter("Inverter")
                               .Do("Reach limit", TestActions.ReachLimitAction)
                               .End()
                               .Wait("Wait 5 ticks", 5, tickProvider)
                               .End()
                               .Build();
            var metadata   = new BehaviourTreeMetadata <TestBlackboard>(root);
            var data       = metadata.CreateExecutionData();
            var executor   = new BehaviourTreeExecutor <TestBlackboard>(root);
            var blackboard = new TestBlackboard();

            executor.Start(data);

            for (var i = 0; i < 5; i++)
            {
                executor.Tick(data, blackboard);
                Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);
                Assert.AreEqual(1, blackboard.Counter1);
                tickProvider.Tick();
            }

            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Success, data.Statuses[root.Id]);
            Assert.AreEqual(1, blackboard.Counter1);
            Assert.AreEqual(0, data.Stack.Count);
        }
コード例 #4
0
        public void WaitNodeTest()
        {
            var tickProvider = new TestTickSupplier();
            var root         = new BehaviourTreeBuilder <TestBlackboard>()
                               .Wait("Increment counter 1", 3, tickProvider)
                               .Build();
            var metadata   = new BehaviourTreeMetadata <TestBlackboard>(root);
            var data       = metadata.CreateExecutionData();
            var executor   = new BehaviourTreeExecutor <TestBlackboard>(root);
            var blackboard = new TestBlackboard();

            executor.Start(data);

            for (var i = 0; i < 3; i++)
            {
                executor.Tick(data, blackboard);
                Assert.AreEqual(BehaviourTreeStatus.Running, data.Statuses[root.Id]);
                tickProvider.Tick();
            }

            executor.Tick(data, blackboard);
            Assert.AreEqual(BehaviourTreeStatus.Success, data.Statuses[root.Id]);
            Assert.AreEqual(0, data.Stack.Count);
        }