Ejemplo n.º 1
0
 private bool fullyTraversed(LogicTree.TreeNode current)
 {
     if (current is null)
     {
         return(true);
     }
     if (current.timesWalked == 0)
     {
         return(false);
     }
     return(fullyTraversed(current.left) && fullyTraversed(current.right));
 }
Ejemplo n.º 2
0
        private string traverseTreeUnity(LogicTree.TreeNode current, int indent, int maxWalk)
        {
            if (current is null)
            {
                return("");
            }
            string color = "FF0000";

            if (current.timesWalked > 0)
            {
                int _c = 100 + ((155 * current.timesWalked) / maxWalk);
                color = "00" + _c.ToString("X") + "00";
                if (color.Length < 6)
                {
                    color = "0" + color;
                }
            }

            string ret = "<color=#" + color + ">";

            foreach (char n in current.vals)
            {
                ret += new String('\t', indent) + decode[n] + "\n";
                if (n == 'O' || n == 'F')
                {
                    ret  += "</color><color=#FF0000>";
                    color = "FF0000";
                }
            }

            if (decode.ContainsKey(current.question))
            {
                ret += new String('\t', indent) + decode[current.question];
                ret += "</color> \n";
                ret += traverseTreeUnity(current.right, indent + 1, maxWalk);
                ret += new String('\t', indent) + "<color=#" + color + "> } else { </color> \n";
                ret += traverseTreeUnity(current.left, indent + 1, maxWalk);
                ret += new String('\t', indent) + "<color=#" + color + "> } \n";
            }
            ret += "</color>";
            return(ret);
        }
Ejemplo n.º 3
0
        public AIEnumeratorValues next()
        {
            bool print         = false;
            int  value         = 0;
            bool state_changed = false;
            bool end           = false;
            bool error         = false;
            bool faulty        = false;

            LogicTree.TreeNode current = brain.root;
            int valLength = 0;

            while (current != null && !error && !print)
            {
                string vals = current.vals;
                valLength = vals.Length;
                current.timesWalked++;
                foreach (char c in current.vals)
                {
                    valLength--;
                    // Commands are here

                    /**
                     * Q Add Active Element to Queue
                     * P Add Active Element to Priority Queue
                     * D Dequeue into Active Element
                     * N Get next Priority Queue
                     * W Active Element = length of input
                     * A Dequeue and add to current element
                     * + +1 to Active Element
                     * - -1 to Active Element
                     * O print Active Element
                     * I get the Active Element'th item from the input, give to Active Element
                     * F End/Submit
                     * */
                    switch (c)
                    {
                    case 'Q':
                        state_changed = true;
                        state.queue().Enqueue(state.active);
                        break;

                    case 'P':
                        state_changed = true;
                        state.priority().Enqueue(state.active);
                        break;

                    case 'N':
                        state_changed = true;
                        state.nextQueue();
                        break;

                    case 'D':
                        state_changed = true;
                        if (!state.canDequeue())
                        {
                            error = true; break;
                        }
                        state.active = state.Dequeue();
                        break;

                    case 'A':
                        state_changed = true;
                        if (!state.canDequeue())
                        {
                            error = true; break;
                        }
                        state.active += state.Dequeue();
                        break;

                    case '+':
                        state_changed = true;
                        state.active++;
                        break;

                    case '-':
                        state_changed = true;
                        state.active--;
                        break;

                    case 'O':
                        value = state.active;
                        print = true;
                        break;

                    case 'I':
                        if (input.Length > 0)
                        {
                            if (!(state.active < input.Length && state.active >= 0))
                            {
                                error = true; break;
                            }
                            state_changed = true;
                            state.active  = input[state.active];
                        }
                        break;

                    case 'F':
                        end = true;
                        break;
                    }
                    if (error || print || end)
                    {
                        break;
                    }
                }
                if (error || print || end)
                {
                    break;
                }
                // do question logic
                // rewriting code because it's 1:17am and I just don't want to bother simplifying a copy/paste right now.
                if (current.question == 'G')
                {
                    if (!state.canDequeue())
                    {
                        error = true; break;
                    }
                    if (state.active > state.getFront())
                    {
                        current = current.right;
                    }
                    else
                    {
                        current = current.left;
                    }
                }
                else if (current.question == 'L')
                {
                    if (!state.canDequeue())
                    {
                        error = true; break;
                    }
                    if (state.active < state.getFront())
                    {
                        current = current.right;
                    }
                    else
                    {
                        current = current.left;
                    }
                }
                else if (current.question == 'V')
                {
                    if (state.active >= 0 && state.active < input.Length)
                    {
                        current = current.right;
                    }
                    else
                    {
                        current = current.left;
                    }
                }
                else
                {
                    break;
                }
            }
            if (valLength > 0)
            {
                faulty = true;
            }
            return(new AIEnumeratorValues(print, value, state_changed, end, error, faulty));
        }