0

Hey
I had made a chatbox, where if it don't know to the question, it just spit random sentence that don't make sense, but i don't how to make it read the question and se if it has a answer for it, and if it don't have a answer it should spit the one of the random sentence out...
How do i make it do that.??

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by lolafuertes
0

Can you be so kind to post here the chat part you have written so far where you want to include the search function?

0

Yes of course

string[] svin = { "Noob Error", "Jeg skal lige have en joint", "Der er rygepause", "Jeg skal lige lave pølle", "Har ikke tid til dit lort", "Kællingen skal lige kneppes", "Hvad snakker du om?", " Skal du ha' slag?", "Min luder er lige kommet", "Du er dum i dit ansigt", "Du er dum og høre på", "Få dig et liv" };
            Random Rand = new Random();
 while (tændt)
            {
                Console.WriteLine("Spørg Jesus hvad du vil vide?");
                Console.Write(">");
                sætning = Console.ReadLine();

It is in danish.
When the bot don't know what "sætning" is, then it have to spit one of the random sentence out..

0

Lets separate the problem in parts:
1) Find the returned phrase in a list of known ones
2) Return a random string from svin if the searched phrase does not exists

Lets assume that we already have a list of known prhases like

static string[] knownPhrases = {"You are the best","Can you help me?"}
static string[] knownAnswers = {"You are rightr","Of course"}
static string[] svin = { "Noob Error", "Jeg skal lige have en joint", "Der er rygepause", "Jeg skal lige lave pølle", "Har ikke tid til dit lort", "Kællingen skal lige kneppes", "Hvad snakker du om?", " Skal du ha' slag?", "Min luder er lige kommet", "Du er dum i dit ansigt", "Du er dum og høre på", "Få dig et liv" };

In order to find if the phrase is know or not you can create a function that will return the righ answer or a random one like:

static string GetAnAnswer(string inputPhrase)
{
for (int i=0;i<knownPhrases.Length;i++) if (inputPhrase == knownPhrases[i]) return knownAnswers[i];

Random rand = new Random();
// this will return a non negative value less tha the max supplied
int randvalue = (int) rand.Next(svin.Length); 

return svin[randvalue];
}

Then after reading the input phrase you can :

if (sætning.Length==0) return; // end of 
Console.WriteLine(GetAnAnswer(sætning));

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.