예제 #1
0
        public void StatefulSelectNode()
        {
            var moqAction1 = new Mock <IBehaviourTreeNode <int, int> >();
            var moqAction2 = new Mock <IBehaviourTreeNode <int, int> >();

            var selectNode = new SelectNode <int, int>("test", true);

            int func1CallCount = 0, func2CallCount = 0;

            moqAction1.Setup(f => f.Compile()).Returns((tick, state) => {
                func1CallCount++;
                return(BehaviourTreeState.Failure);
            });
            moqAction2.Setup(f => f.Compile()).Returns((tick, state) => {
                func2CallCount++;
                return(BehaviourTreeState.Running);
            });

            selectNode.AddNode(moqAction1.Object);
            selectNode.AddNode(moqAction2.Object);

            var func = selectNode.Compile();

            var callResult1 = func(0, 0);
            var callResult2 = func(0, 0);

            Assert.Equal(BehaviourTreeState.Running, callResult1);
            Assert.Equal(BehaviourTreeState.Running, callResult2);

            Assert.Equal(1, func1CallCount);
            Assert.Equal(2, func2CallCount);
        }
예제 #2
0
        public void VerifyStatelessExecution(IEnumerable <IBehaviourTreeNode <int, int> > nodes, BehaviourTreeState expectedState)
        {
            var selectNode = new SelectNode <int, int>("test", false);

            foreach (var node in nodes)
            {
                selectNode.AddNode(node);
            }

            var func = selectNode.Compile();

            var state = func(0, 0);

            Assert.Equal(expectedState, state);
        }