Yes, here it is: /* * * CS2123 - C Programming - 10:30 MWF * David John Davis * Chapter 5 - Exercise 18 * * Start Date: October 15, 1996 * Last Changed: October 16, 1996 * * John H. Conway (Scientific American, October 1970, p. 120) invented a game called * Life to model the process of birth, survival, and death. The idea is that * organisms require others in order to survive and procreate but that overcrowding * results in death. This program simulates the game Life. It ask the user for an * integer which it uses to seed a random number generator. This random number * generator is used to generate a random first generation in the game. After this * the game continues for the number of generations defined by N. The games follows * these rules: * * A) Birth Rule: An organism is born into any empty cell that has exactly three * living neighbors. * B) Survival Rule: An organism with either two or three neighbors survives from * one generation to the next. * C) Death Rule: An organism with four or more neighbors dies from overcrowding. * An organism with fewer than two neightbors dies from loneliness. * * This program uses a 10x10 array to represent the environment, and each cell can * have a * to represent a life, or be blank. * */ #include #include #define LIFE_GRID 10 /* Defines the width x height of the arrays used. */ #define N 20 /* Defines the number of generations the program should simulate. */ void load_init(char [LIFE_GRID][LIFE_GRID]); /* Function to setup initial generation. */ void step_generation(char [LIFE_GRID][LIFE_GRID]); /* Function to move forward one generation. */ void print_grid(char [LIFE_GRID][LIFE_GRID]); /* Function to print the array. */ int neighbors(char [LIFE_GRID][LIFE_GRID],int,int); /* Function to figure the number of neighbors for a given cell. */ void copy_array(char [LIFE_GRID][LIFE_GRID],char [LIFE_GRID][LIFE_GRID]); /* Function to copy the contents of one array to another. */ void main(void) { char life[LIFE_GRID][LIFE_GRID]; /* Array used for the simulation. */ int i; unsigned int seed; /* Holds the user entered seed for the random number generater. */ /* Get a unsigned int from the user and use it to seed the random number generator. */ printf("\nPlease enter a postive integer: "); scanf("%u",&seed); srand(seed); /* Print a message to the screen and run load_init to setup the initial generation. */ printf("\n\nGenerating inital grid...\n
Alex
Posts
-
Game of Life -
2 dimensional dynamic arraysI am having problems building a 2 dimensional dynamic array. I built a one dimensional dynamic array, but I don't know were to start with a 2 dimensional. I cannot find any helpful documentation on it so far on it. Any comments?
-
Interface Design Hall of ShameAt last - somewhere where I can get my code the appreciation it deserves. Kind regards Al. ATL, whomever that is, all the way
-
OFX (or OFC) and FpMLHi, Has anyone successfully written a OFX/OFC interface from scratch for personal/SME use (avoiding the obvious answers please)? Or (of less interest at the moment) anyone playing with FpML? Kind regards Al. ATL, whomever that is, all the way!
-
Number of downloadsAlong that sort of line could you put the current score (and voters) figure against each article when listing them. Kind regards Al. ATL, whomever that is, all the way!
-
UK out of petrol.. I think the current PM is too young to remember (Mrs T or) the Poll Tax. Is it me or has everyone else in the UK notice that the Two Jags' department is [being kept] quiet, I thought that this should be his ostrich-in-sand ..er.. baby. News tonight C4 said that BT .. sorry.. TB is trying to get the suppliers to lower prices. Fuel cost 15%, Tax 85% Duh! It's like a failing B2C looking for credibility by cutting back on pencil rubber expenditure. Does anyone know what the proporionality is on the Fuel tax roughly? Is it 600% (85/15 as %) or x pence per litre? I keep being told that it is proportional, but note that Bobby Brown says that tax is going up by x-pence in the Budget. Kind regards Al. ATL, whoever they are, all the way
-
Why is there no....Hi, I'm a VBer, I can't wite much C++ beyond "Hello Inclusive Multicultural Global Society" [ex-Pascal too], but I'm getting kinda tired of: (1) not really knowing what is going on in there (proxy and stub who?), and/or (2) having the feeling of missing something fundamental: for me it feels like hiring a self drive 7-tonner on a automatic driving licence, when I'm trying to figure out why my latest and greatest dog-food app. hangs my colleagues machine (what! you serously think I'd test my own work, hey I wrote it I know what it is like inside!) I'm a *big* *big* fan of this site mainly because I want to extend my knowledge; I'm out of my depth amoung these people. I think that skill-set enhancement is a pretty common desire amongst our (I'm including you, if I may) breed. The peer group have written some wonderful tutorials (go see, there's even VB), and are more then helpful when reasonable questions are asked. IMHO devotees of other languages go to other well known sites because that's where they would expect their peers to be. I'm off to www.csharpindex.com now (oooh infamy), perhaps I'll 'see' you there?! Kind regards Al. ATL, whatever that is, all the way!
-
MSDN Engine-Collection-ClassIn the last few days I've found something on MSDN which gets me quite excited (we've just had another child and .. let's not go there) The URL is http://msdn.microsoft.com/library/default.asp?URL=/library/techart/desipat.htm (how do I make it clickable, guys?) I had a Google (is this a verb yet?) and couldn't find anything else on it (surely some mistake). But liked it so much I wondered if anyone else had (1) had the same thoughts or (2) (more interestingly) been using it for years. Its got me going so much I'm even considering firing up visual modeler help to find out how to use it properly (.. and how do I get smilies too)! Kind regards Al. ATL, whatever that is, all the way!
-
Is this A true Story ?Like most 'legends', that depends on how many times you can post it, over what period of time. Kind regards Al. ATL, whatever that is, all the way
-
COM+ and MTSWhere is the best place to go read how to use COM+ without the acronym MTS being mentioned? Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC?
-
Restricting access to DBHi, The good news: There is a comprehensive security setup document suite inside the help files of Access. It is relatively easy to read. The bad news (for me): I could not get it to work reliably and usually couldn't get the options that I wanted. I gave up eventually. My advice: download the miniSQL server version from vstudio in MSDN. It's called MSDE. Here's a link to a Jet vs MSDE debate: http://msdn.microsoft.com/library/default.asp?URL=/library/backgrnd/html/msdeforvs.htm&RLD=462. Here's a link to the MSDE itself: http://msdn.microsoft.com/library/default.asp?URL=/library/backgrnd/html/msdeforvs.htm Hope this helps. Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC?
-
Internet Bandwidth MeterCareful there guys, I understand BT would like to make you an offer you *must* refuse. Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC
-
For <i>really</i> lazy programmersExcuse me Chris (mock annoyed tone), I'm still p*ssed-off that I can *still* get a message from the compiler: "Missing ; in line xx". If you know where it is suppoosed to be.. Talk about lack of progress, I used to get the same thing on my Acorn Atom. Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC
-
Interesting web destinations..... I know how you feel. Funny thing is that I know I used to spend hours surfing away - I think this Internet thing is just another fad - just like CB radio!? It'll die once they make it legal. Try www.darwinawards.com (strange but true), or www.imode.com (don't go there if you're feeling down). Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC
-
CodeProject makes 100hot.com!No - thank you. Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC
-
No more IP addresses for hosting co'sWon't this just hasten the move to IPv6? Kind regards, Al. VBer who wants to go back to, but will have to learn again, C++. I'll carry on using VB for the front-end; so when I get proficient at C++/STL can I jump straight to ATL and avoid the MFC
-
MS AgentMS Agent is cool ;-) But does anyone know a way to get it to behave like the Office Assistant in office 2000. ie. not only text in the balloons, but buttons, edit ctrls etc. etc.
-
API to play MP3 filesIs there any API to play MP3 files ? Alex
-
Reduce color depthHi! I need to combine a stored bitmap (>= 256 color) with some graphic elements (e.g. lines, text, ...) and save it as a 256 color bitmap. Do you have any code to reduce the color depth of a bitmap (because this is the real hard thing for me)? Thank you in advance! Ciao, Alex