Esempio n. 1
0
        public void Check(string input, bool learned)
        {
            if (Phrases.ContainsKey(input))
            {
                HandleResponse(input);
            }
            else if (input.ToLower().StartsWith("do you") || input.ToLower().StartsWith("should you") || input.ToLower().StartsWith("can you"))
            {
                switch (RNG.Get(0, 2))
                {
                case 1:
                    Program.Write("Yes!");
                    break;

                case 0:
                    Program.Write("No.");
                    break;
                }
            }
            else
            {
                string[] words = input.ToLower().Split(' ');
                int[]    count = new int[2];
                string   key   = "";

                // Sift through all the phrases.
                for (int x = 0; x < keys.Count; x++)
                {
                    var phrase = keys[x];

                    // Count[1] is the count of the phrase we're currently examining.
                    // Count[0] is the highest count.
                    count[1] = 0;

                    if (phrase.Length >= input.Length)
                    {
                        for (int i = 0; i < words.Length; i++)
                        {
                            if (phrase.ToLower().Contains(words[i]))
                            {
                                count[1]++;
                            }
                        }
                    }

                    // If the current count is bigger than the highest count,
                    // transfer over all the data we need.
                    if (count[1] > count[0])
                    {
                        key      = phrase;
                        count[0] = count[1];
                    }
                }


                float chance = count[0] / words.Length;
                if (chance >= 0.15f)
                {
                    HandleResponse(key);
                    return;
                }

                if (!learned)
                {
                    Phrases.Add(input, new Phrase(new string[] { "" }));
                    keys.Add(input);
                }

                if (RNG.Get(0, 100) <= 75)
                {
                    AskAQuestion();
                }
                else
                {
                    Program.Write("I am still in my learning stages. Keep asking questions!");
                }
            }
        }
Esempio n. 2
0
 public void AskAQuestion()
 {
     Program.Learn = true;
     Program.Write(keys[RNG.Get(0, keys.Count)]);
 }