/* * SCIFI.C -- Print out a little Science Fiction story. * Original idea from the flow chart in * some obscure issue of Omni. * * Copyright (C) 1980 JAB, Jeff A. Bowles * (In case some jerk tries to put his name on this * garbage, I can get angry...) * * This version modified by David L. Cathey * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <assert.h> #define THE_END ((struct node *) NULL) #define random() (rand() & 0xff) struct node { char *s_mesg ; /* What we actually want to say... */ int s_num ; struct node *s_where[10] ; } ; struct node a[] = { { "", 1, &a[1]}, /* 1*/ { "Earth", 4, &a[4], &a[8], &a[9], &a[5] }, /* 2*/ { "**NotUsed**", 4, &a[4], &a[8], &a[9], &a[5] }, /* 3*/ { "**NotUsed**", 4, &a[4], &a[8], &a[9], &a[5] }, /* 4*/ { "", 3, &a[70], &a[71], &a[76] }, /* 5*/ { "is struck by a giant comet and", 3, &a[10], &a[11], &a[12] }, /* 6*/ { "and everyone dies", 1, THE_END }, /* 7*/ { "and ALMOST everyone dies", 1, THE_END }, /* 8*/ { "scientists", 2, &a[13], &a[14] }, /* 9*/ { "is attacked by", 2, &a[15], &a[16]}, /* 10*/ { "destroyed", 1, THE_END }, /* 11*/ { "saved", 1, THE_END }, /* 12*/ { "not destroyed but", 2, &a[17], &a[18] }, /* 13*/ { "invent", 2, &a[20], &a[21] }, /* 14*/ { "discover", 2, &a[22], &a[23] }, /* 15*/ { "tiny", 2, &a[24], &a[77] }, /* 16*/ { "giant", 2, &a[24], &a[77] }, /* 17*/ { "everyone dies", 1, THE_END }, /* 18*/ { "ALMOST everyone dies", 1, THE_END }, /* 19*/ { "not used", 1, THE_END }, /* 20*/ { "tiny", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 21*/ { "giant", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 22*/ { "tiny", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 23*/ { "giant", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 24*/ { "Martian", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 25*/ { "bugs", 1, &a[31] }, /* 26*/ { "reptiles", 1, &a[31] }, /* 27*/ { "mechanical devices", 1, &a[31] }, /* 28*/ { "superpersons", 1, &a[31] }, /* 29*/ { "icky things", 1, &a[31] }, /* 30*/ { "and take a few and leave", 1, THE_END }, /* 31*/ { "who", 6, &a[33], &a[34], &a[35], &a[36], &a[37], &a[38] }, /* 32*/ { "and eat us", 1, THE_END }, /* 33*/ { "want our women", 2, &a[30], &a[39] }, /* 34*/ { "are friendly", 1, &a[39] }, /* 35*/ { "are friendly but misunderstood", 1, &a[39] }, /* 36*/ { "misunderstand us", 1, &a[39] }, /* 37*/ { "understand us too well", 1, &a[39] }, /* 38*/ { "look upon us as only a source of nourishment", 2, &a[32], &a[39] }, /* 39*/ { "and are", 2, &a[40], &a[41] }, /* 40*/ { "radioactive", 1, &a[42] }, /* 41*/ { "not radioactive", 1, &a[42] }, /* 42*/ { "and", 2, &a[43], &a[44] }, /* 43*/ { "can be killed by", 5, &a[45], &a[46], &a[47], &a[72], &a[73] }, /* 44*/ { "cannot be killed by", 5, &a[48], &a[49], &a[50], &a[74], &a[75] }, /* 45*/ { "a crowd of peasants with torches", 1, THE_END }, /* 46*/ { "the Army", 1, THE_END }, /* 47*/ { "the atomic bomb", 1, THE_END }, /* 48*/ { "the atomic bomb", 7, &a[56], &a[60], &a[51], &a[53], &a[54], &a[55], &a[78] }, /* 49*/ { "the Army", 7, &a[56], &a[60], &a[51], &a[53], &a[54], &a[55], &a[78] }, /* 50*/ { "a crowd of peasants with torches", 7, &a[56], &a[60], &a[51], &a[53], &a[54], &a[55], &a[78] }, /* 51*/ { "but", 1, &a[52] }, /* 52*/ { "they die from catching chicken pox", 1, THE_END }, /* 53*/ { "so they kill us", 1, THE_END }, /* 54*/ { "so they put us under a benign dictatorship", 1, THE_END }, /* 55*/ { "so they eat us", 1, THE_END }, /* 56*/ { "so scientists invent a weapon", 2, &a[57], &a[58] }, /* 57*/ { "which fails", 6, &a[51], &a[53], &a[54], &a[55], &a[60], &a[78] }, /* 58*/ { "which kills them", 1, THE_END }, /* 59*/ { "which turns them into disgusting lumps", 1, THE_END }, /* 60*/ { "but", 3, &a[61], &a[62], &a[63] }, /* 61*/ { "a cute kid convinces them that people are okay", 3, &a[64], &a[65], &a[66] }, /* 62*/ { "a priest talks to them of God", 3, &a[64], &a[65], &a[66] }, /* 63*/ { "they fall in love with this beautiful girl", 4, &a[64], &a[65], &a[66], &a[67] }, /* 64*/ { "and they die", 1, THE_END }, /* 65*/ { "and they leave", 1, THE_END }, /* 66*/ { "and they turn into disgusting lumps", 1, THE_END }, /* 67*/ { "and they get married and live happily ever after", 1, THE_END }, /* 68*/ { "is hit by a *BIG* truck and", 3, &a[10], &a[11], &a[12] }, /* 69*/ { "Montagar Software", 5, &a[4], &a[8], &a[9], &a[5], &a[68] }, /* 70*/ { "freezes", 2, &a[6], &a[7] }, /* 71*/ { "falls into the sun", 2, &a[6], &a[7] }, /* 72*/ { "the Navy", 1, THE_END }, /* 73*/ { "the Air Force", 1, THE_END }, /* 74*/ { "the Navy", 7, &a[56], &a[60], &a[51], &a[53], &a[54], &a[55], &a[78] }, /* 75*/ { "the Air Force", 7, &a[56], &a[60], &a[51], &a[53], &a[54], &a[55], &a[78] }, /* 76*/ { "burns up", 2, &a[6], &a[7] }, /* 77*/ { "Moon", 5, &a[25], &a[26], &a[27], &a[28], &a[29] }, /* 78*/ { "so they turn us into disgusting lumps", 1, THE_END }, } ; #define NUMNODES (sizeof(a)/sizeof(a[0])) main (argc, argv) char *argv[] ; { struct node *where , *last_where; int col, ntimes ; time_t t; t = time((time_t) 0); srand(getpid()^t) ; ntimes = (argc == 1) ? 1 : atoi(argv[1]); while (ntimes--) { where = &a[0] ; col = 0 ; do { if (col && strlen(where->s_mesg)) { putchar(' ') ; col++ ; } col += strlen(where->s_mesg) ; printf("%s", where->s_mesg) ; where = (where->s_where[random() % (where->s_num)]) ; } while (where != THE_END) ; printf(".\n\n") ; } exit(1) ; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 117 | Jeff Bowles |
Adding small, cute science-fiction-generating program. I'll probably use it in examples later. |