コード例 #1
0
        public void can_create_a_sequence()
        {
            Init();

            var invokeCount = 0;

            var sequence = testObject
                           .Sequence("some-sequence")
                           .Do("some-action-1", t =>
            {
                ++invokeCount;
                return(MyBehaviourTreeStatus.Success);
            })
                           .Do("some-action-2", t =>
            {
                ++invokeCount;
                return(MyBehaviourTreeStatus.Success);
            })
                           .End()
                           .Build();

            Assert.IsType <SequenceNode>(sequence);
            Assert.Equal(MyBehaviourTreeStatus.Success, sequence.Tick(new MyTimeData()));
            Assert.Equal(2, invokeCount);
        }
コード例 #2
0
        /// <summary>
        /// Parsers the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        public void parser(byte[] input)
        {
            //this is a parser that creates the tree by reading the
            //byte array that is passed in as aperamiter
            var builder = new MyTreeBuilder(crouched, close, medium, far);
            IMyBehaviourTreeNode botTree;

            for (int i = 0; i < input.Length; i++)
            {
                switch (input[i])
                {
                case Root_Node:
                    builder.Sequence("Root-Sequence-Node");
                    break;

                case Punch:
                    builder.Punch(gw, AI, NAI);
                    break;

                case Kick:
                    builder.Kick(gw, AI, NAI);
                    break;

                case Special:
                    builder.Special(gw, AI, NAI);
                    break;

                case isCrouched:
                    builder.Condition
                        ("is_Opponent_Crouched",
                        t =>
                    {
                        if (builder.Crouched == true)
                        {
                            return(true);
                        }
                        return(false);
                    });
                    builder.Selector("If_Crouched");
                    break;

                case isClose:
                    builder.Condition
                        ("is_Opponent_Close",
                        t =>
                    {
                        if (builder.Close == true)
                        {
                            return(true);
                        }
                        return(false);
                    });
                    builder.Selector("If_Close");
                    break;

                case isMedium:
                    builder.Condition
                        ("is_Opponent_Medium",
                        t =>
                    {
                        if (builder.Medium == true)
                        {
                            return(true);
                        }
                        return(false);
                    });
                    builder.Selector("If_Medium");
                    break;

                case isFar:
                    builder.Condition
                        ("is_Opponent_Far",
                        t =>
                    {
                        if (builder.Far == true)
                        {
                            return(true);
                        }
                        return(false);
                    });
                    builder.Selector("If_Far");
                    break;

                case End:
                    builder.End().Build();
                    break;
                }
            }

            //will have gotten nodes from parser so should build
            botTree = builder.Build();

            interp_tree_builder = builder;

            interp_tree = botTree;
        }