Beispiel #1
0
        public static string LLToString(LinkedListA <string> linkedList)
        {
            string result = "";

            for (LinkedListNodeA <string> c = linkedList.first; c != null; c = c.next)
            {
                result += c.item;
            }
            return(result);
        }
Beispiel #2
0
        public LinkedListA <string> DoIterations(int n)
        {
            LinkedListA <string> ll = StringToLL(axiom);

            for (int i = 0; i < n; i++)
            {
                for (LinkedListNodeA <string> c = ll.first; c != null; c = c.next)
                {
                    replaceNode(ll, c);
                }
            }

            iterations = n;

            return(ll);
        }
Beispiel #3
0
    public void Enqueue(T item)
    {
        LinkedListNodeA <T> oldLast = last;

        last      = new LinkedListNodeA <T>();
        last.item = item;
        last.next = null;
        if (IsEmpty())
        {
            first = last;
        }
        if (oldLast != null)
        {
            oldLast.next = last;
        }
        last.previous = oldLast;
        n++;
    }
Beispiel #4
0
 // repalce node with linkedlistA
 public void Replace(LinkedListNodeA <T> node, LinkedListA <T> linkedList)
 {
     if (linkedList.IsEmpty())
     {
         return;
     }
     if (node.previous == null)
     {
         first = linkedList.first;
     }
     else
     {
         Link(node.previous, linkedList.first);
     }
     if (node.next != null)
     {
         Link(linkedList.last, node.next);
     }
 }
Beispiel #5
0
    public T Dequeue()
    {
        if (IsEmpty())
        {
            return(default(T));
        }
        T item = first.item;

        first = first.next;
        n--;
        if (IsEmpty())
        {
            last = null;
        }
        else
        {
            first.previous = null;
        }
        return(item);
    }
Beispiel #6
0
        private void replaceNode(LinkedListA <string> ll, LinkedListNodeA <string> node)
        {
            if (Regex.IsMatch(node.item, @"^[a-zA-Z]+$"))
            {
                if (grammar.ContainsKey(node.item))
                {
                    List <Rule> rules            = grammar[node.item];
                    float       totalProbability = 0;

                    // roll dice against each rule
                    for (var i = 0; i < rules.Count; i++)
                    {
                        totalProbability += rules[i].probability;

                        if (totalProbability >= UnityEngine.Random.value)
                        {
                            // apply rule
                            ll.Replace(node, StringToLL(rules[i].str));
                            break;
                        }
                    }
                }
            }
        }
Beispiel #7
0
 private void Link(LinkedListNodeA <T> a, LinkedListNodeA <T> b)
 {
     a.next     = b;
     b.previous = a;
 }