Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Indevidual"/> class.
 /// </summary>
 /// <param name="number">The number.</param>
 /// <param name="program">The program.</param>
 /// <param name="tree">The tree.</param>
 /// <param name="fitness">The fitness.</param>
 public Indevidual(int number, byte[] program, IMyBehaviourTreeNode tree, float fitness)
 {
     treeNo  = number;
     Program = program;
     Tree    = tree;
     Fitness = fitness;
 }
Esempio n. 2
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");
        }
Esempio n. 3
0
        /// <summary>
        /// Add a child to the parent node.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <exception cref="System.ApplicationException">Can't add more than a single child to InverterNode!</exception>
        public void AddChild(IMyBehaviourTreeNode child)
        {
            if (this.childNode != null)
            {
                throw new ApplicationException("Can't add more than a single child to InverterNode!");
            }

            this.childNode = child;
        }
Esempio n. 4
0
        /// <summary>
        /// Splice a sub tree into the parent tree.
        /// </summary>
        /// <param name="subTree">The sub tree.</param>
        /// <returns>MyTreeBuilder</returns>
        /// <exception cref="System.ArgumentNullException">subTree</exception>
        /// <exception cref="System.ApplicationException">Can't splice an unnested sub-tree, there must be a parent-tree.</exception>
        public MyTreeBuilder Splice(IMyBehaviourTreeNode subTree)
        {
            if (subTree == null)
            {
                throw new ArgumentNullException("subTree");
            }

            if (parentNodeStack.Count <= 0)
            {
                throw new ApplicationException("Can't splice an unnested sub-tree, there must be a parent-tree.");
            }

            parentNodeStack.Peek().AddChild(subTree);
            return(this);
        }
        /// <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;
        }
Esempio n. 6
0
 /// <summary>
 /// Add a child to the parent node.
 /// </summary>
 /// <param name="child">The child.</param>
 public void AddChild(IMyBehaviourTreeNode child)
 {
     children.Add(child);
 }
Esempio n. 7
0
 /// <summary>
 /// Ends a sequence of children.
 /// </summary>
 /// <returns>MyTreeBuilder</returns>
 public MyTreeBuilder End()
 {
     curNode = parentNodeStack.Pop();
     return(this);
 }