Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!decwrl!glacier!oliveb!hplabs!tektronix!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataioDataio.UUCP (Walter Bright) Newsgroups: net.sources.games Subject: AI riddle program Message-ID: <941@dataioDataio.UUCP> Date: Tue, 1-Apr-86 14:38:16 EST Article-I.D.: dataioDa.941 Posted: Tue Apr 1 14:38:16 1986 Date-Received: Sat, 5-Apr-86 05:00:58 EST Organization: Data I/O Corp., Redmond WA Lines: 83 The following program is a demonstration of AI techniques disguised as a game. Cut, compile and run. Note that this program may be made even more intelligent if it is written in an AI language such as PROLOG or LISP. --------------- Cut (ouch) here --------------------- /*_ riddle.c Tue Apr 1 1986 Written by: Walter Bright */ #include #include main() { extern long time(); static char *msg[] = { "ha ","hah ","ho ","hee " }; int i,cntrlC(); printf("Welcome to riddle, an AI demonstration program.\n"); printf("riddle will attempt to solve one line riddles.\n"); printf("\nInitializing...\n"); delay(2); srand(time((long *) NULL)); printf("Tell me a riddle (one line): "); while (1) { fflush(stdout); getline(); signal(SIGINT,cntrlC); delay(rand() % 3 + 1); printf("Hmmmmm.....\n"); delay(rand() % 10 + 3); printf("Gee, that's a tough one.\n"); delay(rand() % 10 + 4); signal(SIGINT,SIG_DFL); printf("I give up. What's the answer? "); fflush(stdout); getline(); printf("hah "); i = rand() % 15 + 5; while (i--) { printf(msg[rand() % (sizeof(msg)/sizeof(msg[0]))]); fflush(stdout); delay(1); } printf("\nThat was a good one (sniff).\n"); printf("Tell me another one: "); } } getline() { char buffer[100]; fgets(buffer,sizeof(buffer),stdin); } delay(secs) { #ifdef DLC long starttime; time(&starttime); while (time((long *) NULL) <= starttime + secs) ; #else sleep(secs); #endif } cntrlC() { static char *msg[] = { "Hang on a sec, I've almost got it.", "I said just a sec.", "Give me a chance, will ya? The machine's a little slow today.", "Buzz off, I'm artificially thinking.", "Yer mother wears army boots", "Row well, and live", "" }; static int i = 0; printf("%s\n",msg[i]); if (i < 5) i++; }