Exemplo n.º 1
0
        public void InterpreterTest()
        {
            //
            // TODO: Add test logic here
            //
            byte[] program = { 1, 2, 9 };
            // byte[] program = { 1,8,8,5,2,9,5,6,6,4,4,4,9,9,6,5,8,3,3,3,9,8,3,9,9,5,6,6,4,9,9,9,5,3,9,9,9,5,4,9,9,9,8,8,2,2,9,9,3,9 };

            GeneticProgramming gp = new GeneticProgramming();

            String Expected = "RootNode( <Punch> ) )";

            IMyBehaviourTreeNode test_tree = gp.GetInterpTree(program);

            MyTreeBuilder test = gp.interp_tree_builder;

            String[] list;
            Stack <IMyParentBehaviourTreeNode> nodes = new Stack <IMyParentBehaviourTreeNode>();

            //String Actual = test_tree.ToString();
            foreach (IMyParentBehaviourTreeNode i in test.parentNodeStack)
            {
                nodes.Push(i);
            }
            Stack <IMyParentBehaviourTreeNode> Actual = nodes;

            Assert.AreEqual(Expected, Actual, " Error incorrect result");
        }
 void Init()
 {
     //tree builder reference had to be modified to fit my usage
     testObject = new MyTreeBuilder(false, true, false, false);
 }
        /// <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;
        }
Exemplo n.º 4
0
 void Init()
 {
     testObject = new MyTreeBuilder();
 }