/* THE GAME OF LIFE Written and produced by Chris C. Keeser on 6/8/04 sitting on my couch listening to music at 12:30 in the morning oh what a good feeling that was. (seriously, it was the most peace I have had all week) */ #include "life.hxx" //////////////////////////////////////////// /* NAME: main DESCRIPTION: The head honcho who is calling all the shots. PAPRAMETERS: INT argc, the number of parameters passed from the command line, and CHAR **argv, the array of character arrays that hold the actual arguments passed from the command line. PRE-CONDITIONS: You must have called the program from the command line you must have also typed a percentage value from 1 to 99 as a second argument. i.e ~game_of_life> life_game 12 POST-CONDITIONS: none. Your done. RETURN: A rather pointless INT SIDE EFFECTS: Alot of your free time has now dissapeared. :) */ ///////////////////////////////////////////// int main(int argc, char **argv) { int old_g[MAXR][MAXC] = {0}, new_g[MAXR][MAXC] = {0}, percentage = 0; // old_g is the 100 X 100 array that holds all life // new_g is the 100 X 100 array that holds all hope for the future // percentage is the number that is going to be passed from the comman line // that will determine how much life starts off in the array int n = 0; // generation counter char dummy = '0'; // place to put the "continue" or "quit" character if(argc != 2) { printf("Error, must pass in a percentage of life as a number between \n1 and 99\nexample:life_game 22"); return -1; } percentage = atoi(argv[1]); // get the percentage from the command line // and convert it into an int if(percentage > 99 || percentage < 1) // crude error checking { printf("Not between 1 and 99"); return 1; } generate_random_start(percentage, old_g); // pass the percentage of life // to be created and the old_g array to be populated (randomly) while(dummy != 'q') // as long as you dont press 'q' to quit you can go forever { show_generation(old_g); // display the entire "planet" to the screen printf("\nGeneration number :%d\n", n); // some fun info to go to the screen printf("Press 'q' to quit\n"); printf("Press enter to continue\n"); where_am_i(old_g, new_g); // this guy is the function behind the "main" (does // all the real work ;) scanf("%c", &dummy); n++; // update the generational counter } system("cls"); //Clears screen printf("\n Goodbye!\n"); return 0; }