Conway's Game of Life Help

Discussion in 'Mac Programming' started by Nitrex88, Jan 21, 2008.

  1. Nitrex88 macrumors newbie

    Dec 30, 2007
    Hi, awhile back I asked for basic programming ideas to challenge myself in objective-C, a language that i am not very advanced in. One idea that was suggested was Conways game of Life found here...'s_Game_of_Life

    I was very interested in this challenge and have sat down many times over the last few weeks trying to make such a program in xcode 3, using objective-C. So far I have been unsuccessful and need some help.
    1.) What is best to use as a "cell". I was thinking a square button or picture view.
    2.) What method should i use to detect the neighboring cells

    If anyone has any suggestions it would greatly appreciated. Also i cant seem to find this program for mac except on java, which i am not that good at, so if anyone knows where to find this program already made with non-java source code, u could point me to that. Thanks in advance.
  2. sord macrumors 6502

    Jun 16, 2004
    You may want to instead consider using OpenGL. Using a lot of buttons or a lot of picture viewers is (sorry for the harshness) a HORRIBLE idea.

    Sample code to the rescue! (I got bored last year in one of my classes and just so happened to make exactly what you want, though no guarantee on quality - haven't looked at the code for a year).

    Builds just fine in XCode 3

    Hope this helps! When its not running you can click to add blocks.

    EDIT: You may want to extend it so the blocks can go offscreen instead of just ending.
  3. Catfish_Man macrumors 68030


    Sep 13, 2001
    Portland, OR

    While that might be the "correct" way to do it (I'm not sure I agree!), it's not such a great way to learn Cocoa. Were I him, I would either do it using NSMatrix, or, preferably take the opportunity to learn more about custom drawing and event handling in NSViews. Not terribly difficult, but useful any time you need a custom Cocoa widget.
  4. Doctor Q Administrator

    Doctor Q

    Staff Member

    Sep 19, 2002
    Los Angeles
    I find it's more fun, when coding the Game of Life, to have the squares wraparound horizontally and vertically on the grid, even though you display it on a plane. For example, a cell in the leftmost column is considered a neighbor of the cell in the same row in the rightmost column, and the same kind of wraparound top to bottom.

    That way, moving patterns like a glider don't break up at the boundaries, and can wrap around as if they were on an infinite grid.

Share This Page