Conway's Game of Life Help

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

  1. Nitrex88 macrumors newbie

    Joined:
    Dec 30, 2007
    #1
    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...

    http://en.wikipedia.org/wiki/Conway'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

    Joined:
    Jun 16, 2004
    #2
    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
    http://home.earthlink.net/~valiantsoul/life.zip

    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

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3

    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

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    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