[net.ai] UNIX - ai

emneufeld@water.UUCP (Animal D.H.) (11/21/84)

/*
	For all you ai-ers, here's a great state-of-the-art
	ai program that runs on UNIX.  compile this program
	with the command

	cc riddle.c -o ridde -lcurses -ltermlib

*/


#include <math.h>
# include <sys/types.h>
# include <sys/timeb.h>
#include <curses.h>
main()
{
    int     i,
            j;
    char    a,
            b,
            c;
    savetty();
    initscr ();
    printw ("ask me a riddle...\n");
    refresh ();
    i = randy (10);
    j = 0;
    while ((c = getchar ()) != '\n') {
	if (i = j)
	    srand ((int) c);
	j++;
    }
    printw ("Gee! ");
    refresh ();
    sleep (2);
    printw (" That's a tough one...");
    refresh ();
    refresh ();
    for (i = 0; i < 10; i++) {
	printw (".");
	refresh ();
	sleep (1);
    };
    printw ("\nI give up !!  What's the answer?\n");
    refresh ();
    while (getchar () != '\n');
    for (j = 0; j < 100; j++) {
	i = randy (3);
	move (randy (31), randy (70));
	switch (i) {
	    case 0: 
		printw ("Hee hee!");
		break;
	    case 1: 
		printw ("Har har!");
		break;
	    case 2: 
		printw ("That's a good one!");
		break;
	    case 3: 
		printw ("Yuk, yuk!!");
		break;
	    default: 
		printw ("That's hilarious!");
		break;
	}
	refresh ();
    }
    endwin();
    resetty();
}

randy(i)
int i;
{
    i = (int) ((double) i * (double) rand () / (double) 017777777777);
    return (i);
}