Esempio n. 1
0
        private static T GetDictData0 <T>(IList <T> unifiables, string name, int startChars, out bool found) where T : IConvertible
        {
            string s = name.Substring(startChars);

            if (s == "*" || s == "ALL" || s == "0")
            {
                StringAppendableUnifiableImpl result = Unifiable.CreateAppendable();
                foreach (T u in unifiables)
                {
                    result.Append(u.ToString());
                }
                found = true;
                return(PASSTHRU <T>(result));
            }

            int uc = unifiables.Count;

            bool fromend = false;

            if (s.StartsWith("-"))
            {
                fromend = true;
                s       = s.Substring(1);
            }

            int i = Int32.Parse(s);

            if (i == 0)
            {
                if (uc == 0)
                {
                    found = true;
                    return(PASSTHRU <T>(""));
                }
            }
            int ii = i - 1;

            if (fromend)
            {
                ii = uc - i;
            }
            if (uc == 0)
            {
                AltBot.writeDebugLine(" !ERROR -star underflow! " + i + " in " + name);
                found = false;
                return(PASSTHRU <T>(String.Empty));
            }
            if (ii >= uc || ii < 0)
            {
                AltBot.writeDebugLine(" !ERROR -star badindexed 0 < " + i + " < " + uc + " in " + name);
                found = false;
                return(unifiables[ii]);
            }
            found = true;
            return(unifiables[ii]);
        }
Esempio n. 2
0
        protected override Unifiable ProcessChangeU()
        {
            if (FinalResultValid)
            {
                return(FinalResult);
            }
            ResetValues(true);
            int maxConditions = GetAttribValue <int>(templateNode, "count", 1);
            int minConditions = GetAttribValue <int>(templateNode, "mincount", 1);
            var nodes         = SelectNodes(templateNode.ChildNodes);

            if (CheckNode("random"))
            {
                Unifiable appendable = Unifiable.CreateAppendable();
                if (templateNode.HasChildNodes)
                {
                    // only grab <li> nodes
                    List <XmlNode> listNodes = new List <XmlNode>();
                    foreach (XmlNode childNode in nodes)
                    {
                        if (childNode.Name == "li")
                        {
                            listNodes.Add(childNode);
                        }
                    }
                    // randomly grab <li> nodes and use them
                    List <XmlNode> useNodes = new List <XmlNode>();
                    while (maxConditions-- > 0 && listNodes.Count > 0)
                    {
                        XmlNode chosenNode = listNodes[r.Next(0, listNodes.Count - 1)];
                        listNodes.Remove(chosenNode);
                        var childResult = ProcessChildNode(chosenNode);
                        if (childResult != null)
                        {
                            useNodes.Add(chosenNode);
                            QueryHasSuceededN++;
                            appendable.Append(childResult);
                        }
                    }
                    if (QueryHasSuceededN < minConditions)
                    {
                        QueryHasFailedN++;
                        return(null);
                    }
                    return(appendable);
                }
            }
            return(Unifiable.Empty);
        }
Esempio n. 3
0
 protected override Unifiable Format(Unifiable templateNodeInnerText)
 {
     if (CheckNode("formal"))
     {
         Unifiable result = Unifiable.CreateAppendable();
         Unifiable rest   = templateNodeInnerText;
         while (!IsNullOrEmpty(rest))
         {
             // Unifiable[] words = templateNodeInnerText.AsString().Split(new char[]{''});
             Unifiable word = rest.First;
             rest = rest.Rest;
             {
                 Unifiable newWord = word.ToPropper();
                 result.Append(newWord);
             }
         }
         return(Trim(Unifiable.ToVMString(result)));
     }
     return(Unifiable.Empty);
 }
Esempio n. 4
0
        protected override Unifiable ProcessChangeU()
        {
            return(templateNodeInnerText);

            if (false && templateNode.Name.ToLower() == "aimlexec")
            {
                Unifiable result = Unifiable.CreateAppendable();
                Unifiable rest   = templateNodeInnerText;
                while (!IsNullOrEmpty(rest))
                {
                    // Unifiable[] words = templateNodeInnerText.AsString().Split(new char[]{''});
                    Unifiable word = templateNodeInnerText.First;
                    rest = rest.Rest;
                    {
                        Unifiable newWord = word;
                        result.Append(newWord + " ");
                    }
                }
                return(Trim(Unifiable.ToVMString(result)));
            }
            return(templateNodeInnerText);
        }