Exemple #1
0
/* Say something!
*/
void Niall_Reply(char *Buffer,int BufSize)
{
	WORD *Word;

	/* Clear the buffer.
	*/
	Buffer[0]=0;

	/* Check we have some words to say
	*/
	if(WordList==NULL)
	{
		Niall_Warning("Corrupted brain (Not initialised).");
		Niall_NewDictionary();
		return;
	}
	if(CountProbs(WordList)==0)
	{
		strcpy(Buffer,"I cannot speak yet!");
		return;
	}

	/* Speak some words of wisdom.
	*/
	StringWord(Buffer,BufSize,WordList);
	Buffer[0]=toupper(Buffer[0]);
        //fprintf(stderr, "speaking 1\n");
	safeStrcat(Buffer,BufSize,".");
        //fprintf(stderr, "speaking 2\n");
}
Exemple #2
0
/* Add the next word on to the end of the buffer
*/
static void StringWord(char *Buffer,int BufSize,WORD *ThisWord)
{
	int nProbs,iProb,total;
	WORD *NextWord;
	ASCN *Assoc;

	/* Randomly select an index for the next word.
	*/
	nProbs = CountProbs(ThisWord);
	if(nProbs<1)
	{
		Niall_Warning("Corrupted brain (Unlinked word).");
		return;
	}

	/* Taken from the rand(3) manual page...
	*/
	iProb = (int)( (float)nProbs*(float)rand() / ((float)RAND_MAX+1.0) );

	/* Find the next word.
	*/
	for(total=0,Assoc=ThisWord->Associations;Assoc;Assoc=Assoc->Next)
	{
		total+=Assoc->Probability;
		if(total>iProb)
		{
			NextWord = GetWord(Assoc->Word);
			if(NextWord != END_SENTENCE)
			{
				if(strlen(Buffer)) safeStrcat(Buffer,BufSize," ");
				safeStrcat(Buffer,BufSize,NextWord->Data);
				StringWord(Buffer,BufSize,NextWord);
				return;
			}
			else return;
		}
	}
	Niall_Warning("Corrupted brain (Loop Overflow).");
}
void str_words_in_rev(char *input, int len)
{
	StringRev(input, 0, len-1);
	StringWord(input, len);
}