public void VerifyExecution(IEnumerable <IBehaviourTreeNode <int, int> > nodes, BehaviourTreeState expectedState)
        {
            var selectNode = new RandomSequenceNode <int, int>("test");

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

            var func = selectNode.Compile();

            var state = func(0, 0);

            Assert.Equal(expectedState, state);
        }
        public void VerifyStatefulExecution()
        {
            var node1CallCount = 0;
            var node2CallCount = 0;
            var node3CallCount = 0;

            var node1 = new Mock <IBehaviourTreeNode <int, int> >();

            node1.Setup(f => f.Compile()).Returns((tick, state) => {
                node1CallCount++;
                return(BehaviourTreeState.Success);
            });

            var node2 = new Mock <IBehaviourTreeNode <int, int> >();

            node2.Setup(f => f.Compile()).Returns((tick, state) => {
                node2CallCount++;
                return(BehaviourTreeState.Success);
            });

            var node3 = new Mock <IBehaviourTreeNode <int, int> >();

            node3.Setup(f => f.Compile()).Returns((tick, state) => {
                node3CallCount++;
                return(node3CallCount > 2 ? BehaviourTreeState.Success : BehaviourTreeState.Running);
            });

            var selectNode = new RandomSequenceNode <int, int>("test", stateful: true);

            selectNode.AddNode(node1.Object, 33);
            selectNode.AddNode(node2.Object, 33);
            selectNode.AddNode(node3.Object, 33);

            var func = selectNode.Compile();

            while (true)
            {
                if (func(1, 1) != BehaviourTreeState.Running)
                {
                    break;
                }
            }

            Assert.Equal(1, node1CallCount);
            Assert.Equal(1, node2CallCount);
            Assert.Equal(3, node3CallCount);
        }
        public void CountRandomCall()
        {
            var action1 = new Mock <IBehaviourTreeNode <int, int> >();
            var action2 = new Mock <IBehaviourTreeNode <int, int> >();
            var action3 = new Mock <IBehaviourTreeNode <int, int> >();

            int callCount1 = 0, callCount2 = 0, callCount3 = 0;

            action1.Setup(f => f.Compile()).Returns((t, s) =>
            {
                callCount1++;
                return(BehaviourTreeState.Failure);
            });

            action2.Setup(f => f.Compile()).Returns((t, s) =>
            {
                callCount2++;
                return(BehaviourTreeState.Failure);
            });

            action3.Setup(f => f.Compile()).Returns((t, s) =>
            {
                callCount3++;
                return(BehaviourTreeState.Failure);
            });

            var randomSequence = new RandomSequenceNode <int, int>("test");

            randomSequence.AddNode(action1.Object, 100);
            randomSequence.AddNode(action2.Object, 50);
            randomSequence.AddNode(action3.Object, 40);

            var func = randomSequence.Compile();

            for (int i = 0; i < 100; i++)
            {
                func(0, 0);
            }

            var condition = (callCount1 > callCount2) && (callCount2 > callCount3);

            Assert.True(condition);
        }