Exemplo n.º 1
0
        TreeNode getRandomFunction()
        {
            int rand = random.Next(4);

            TreeNode ret;

            switch (rand)
            {
            case 0: ret = new IfFoodAhead(); break;

            case 1: ret = new Progn2(); break;

            case 2: ret = new Progn3(); break;

            case 3: ret = new IfWallAhead(); break;

            default: ret = new IfFoodAhead(); break;
            }

            return(ret);
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            var ifFoodAhead = new IfFoodAhead();
            var prog2       = new Prog2();
            var prog3       = new Prog3();
            var move        = new Move();
            var left        = new Left();
            var right       = new Right();
            var allSymbols  = new List <Symbol>()
            {
                ifFoodAhead, prog2, prog3, move, left, right
            };
            var nonTerminalSymbols = new List <Symbol>()
            {
                ifFoodAhead, prog2, prog3
            };

            allSymbols.ForEach(s => AddSymbol(s));
            SetSubtreeCount(ifFoodAhead, 2, 2);
            SetSubtreeCount(prog2, 2, 2);
            SetSubtreeCount(prog3, 3, 3);
            SetSubtreeCount(move, 0, 0);
            SetSubtreeCount(left, 0, 0);
            SetSubtreeCount(right, 0, 0);

            // each symbols is allowed as child of the start symbol
            allSymbols.ForEach(s => AddAllowedChildSymbol(StartSymbol, s));
            allSymbols.ForEach(s => AddAllowedChildSymbol(DefunSymbol, s));

            // each symbol is allowed as child of all other symbols (except for terminals that have MaxSubtreeCount == 0
            foreach (var parent in nonTerminalSymbols)
            {
                foreach (var child in allSymbols)
                {
                    AddAllowedChildSymbol(parent, child);
                }
            }
        }