hello could anyone please give me the source code for a text based version of game of life implementing simple 2d array in c???
hello could anyone please give me the source code for a text based version of game of life implementing simple 2d array in c???
Just do some work on it, better than spoon feeding aint it...The happiness you will feel at cracking it, hitting run and seeing the thing doing what it is supposed to is more than worth a little effort to work it out for yourself.
The algorithm is fairly easy to write code for, there are only a few rules to implement and you can store the whole 'world' ina 2d array as you request.
To display using text just use a 0 for a dead cell and a 1 for a live one. Use a gotoXY function to control where the characters are written.
To simplify things at first just 'hardcode' the starting cells, that is, work out where a centralportion of the 'world' is in x and y coords and then set a few of them to LIVE status to get things going.
When you are determining what will happen to each cell on the next ‘tick’ you need to look at each of the surrounding cells that touch the current one and check if they are live or dead, this is where you need to watch out and not try to access out of bounds areas of arrays, so you will need to have a method to cope with that.
You could try putting an extra strip of edge cells with a flag value like 1000 in them so you can safely check their location but ignore them if they contain the flag value. (you could output a suitable char for these cells to represent a border as a graphics touch).
Another way is to check if the next x and or y values are beyond your world bounds.
If you actually try to code it yourself you will soon see what I mean.
Thought for the day:FLTK: "The most fun you can have with your clothes on.""Are you sure your sanity chip is fully screwed in sir?" (Kryten)
Stroustrup:
"If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"