Esempio n. 1
0
        public SequentailCallCompilerVsSequentailCallCompilerNew()
        {
            var actionNode1 = new ActionNode <int, int>("action 1", (a, b) =>
            {
                b = a + b;
                return(BehaviourTreeState.Success);
            });

            var actionNode2 = new ActionNode <int, int>("action 2", (a, b) =>
            {
                b = a * b;
                return(BehaviourTreeState.Success);
            });

            var actionNode3 = new ActionNode <int, int>("action 3", (a, b) =>
            {
                b = a * b * b;
                return(BehaviourTreeState.Success);
            });

            _wrapCallCompiler = new WrapCallCompiler <int, int>(new[] { actionNode1, actionNode2, actionNode3 }, (state) => state == BehaviourTreeState.Error).Compile(true);
            _seqCallCompiler  = new SequentialCallCompiler <int, int>(new[] { actionNode1, actionNode2, actionNode3 }, (state) => state == BehaviourTreeState.Error).Compile(true);
            _randomCompiler   = new RandomCallCompiler <int, int>(new[] {
                new RandomEntry <IBehaviourTreeNode <int, int> >(33, actionNode1),
                new RandomEntry <IBehaviourTreeNode <int, int> >(33, actionNode2),
                new RandomEntry <IBehaviourTreeNode <int, int> >(33, actionNode3),
            }, (state) => state == BehaviourTreeState.Error).Compile(true);
        }
        public Func <TTickData, TState, BehaviourTreeState> Compile()
        {
            if (!_nodes.Any())
            {
                throw new BehaviourTreeCompilationException(ExceptionMessages.ChildShouldNotBeEmpty);
            }

            foreach (var node in _nodes)
            {
                node.Entry.Profiler = Profiler;
            }

            var compiler = new RandomCallCompiler <TTickData, TState>(_nodes.AsEnumerable(),
                                                                      (nodeState) => nodeState != BehaviourTreeState.Success);

            var func = compiler.Compile(_stateful);

            return(Profiler.Decorate(Name, func, true));
        }