Thread: Text Based Conway's game of Life in C

  1. #1
    Registered User
    Join Date
    Jul 2011

    Text Based Conway's game of Life 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???

  2. #2
    Registered User
    Join Date
    May 2011
    Around 8.3 light-minutes from the Sun
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Liverpool UK
    Quote Originally Posted by spideysagnik View Post
    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:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    "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'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. John Conway's Game Of Life
    By O Mighty Nips in forum C Programming
    Replies: 3
    Last Post: 05-14-2011, 11:30 PM
  2. Text based game
    By wipeout4wh in forum C Programming
    Replies: 12
    Last Post: 03-26-2009, 04:39 PM
  3. Text Based Game Help!
    By TylerMoyer in forum Game Programming
    Replies: 10
    Last Post: 07-01-2007, 12:02 AM
  4. Replies: 20
    Last Post: 05-24-2007, 01:06 AM
  5. Conway's Life
    By prxom1 in forum C Programming
    Replies: 1
    Last Post: 03-27-2002, 02:13 PM