Thread: Help.. I can't understand

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    10

    Need help

    Code:
    #define LIFE_MATRIX_SIZE_X        100
    #define LIFE_MATRIX_SIZE_Y        100
    
    
    #define DEAD        0
    #define ALIVE        1
    
    
    char    life_matrix [LIFE_MATRIX_SIZE_Y][LIFE_MATRIX_SIZE_X];
    char    life_matrix2[LIFE_MATRIX_SIZE_Y][LIFE_MATRIX_SIZE_X];
    
    
    
    void    Life_Evolve()
    {
        static const int    movx[] = {  0,  1,  1,  1,  0, -1, -1, -1 };
        static const int    movy[] = { -1, -1,  0,  1,  1,  1,  0, -1 };
    
        int        i, x, y, xn, yn;
        int        alive_count;
    
    
    
        for (y = 0; y < LIFE_MATRIX_SIZE_Y; y++) {
    
            for (x = 0; x < LIFE_MATRIX_SIZE_X; x++) {
    
    
                alive_count = 0;
    
                for (i = 0; i < 8; i++) {
    
                    xn = x + movx[i]; 
                    if (xn < 0) 
                        xn = LIFE_MATRIX_SIZE_X-1; 
                    else if (xn >= LIFE_MATRIX_SIZE_X) 
                        xn = 0;
    
                    yn = x + movy[i]; 
                    if (yn < 0) 
                        yn = LIFE_MATRIX_SIZE_Y-1; 
                    else if (yn >= LIFE_MATRIX_SIZE_Y) 
                        yn = 0;
    
                    if (life_matrix[yn][xn] == ALIVE)
                        alive_count++;                
                
                } // for i
    
    
                
                if (life_matrix[y][x] == ALIVE)
                    life_matrix2[y][x] = (alive_count == 2 || alive_count == 3) ? ALIVE : DEAD;
                else
                    life_matrix2[y][x] = (alive_count == 3) ? ALIVE : DEAD;
    
    
            }  // for x
    
        }  // for y
    
    
    
        memcpy(life_matix, life_matrix2, sizeof(life_matrix));
    
    }  // Life_Evolve
    Last edited by cacca; 06-18-2012 at 02:02 PM.

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    I don't understand the functionality can someone explain??

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    I suggest you Google Conway's Game of Life.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    are you kiding me or what

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    Dude I love you

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    51
    Nope. He is dead serious. Ever played the game?

  7. #7
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    It must be a geek thing that I barely scanned the code and recognised what it was doing, even without the "life_matrix" clue.

    I need to get a life... :-)

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > I need to get a life... :-)
    Just make sure you only have two or three neighbours
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please help me understand this
    By litzkrieg in forum C Programming
    Replies: 8
    Last Post: 02-16-2011, 01:44 PM
  2. help me understand...
    By stormfront in forum C Programming
    Replies: 2
    Last Post: 10-12-2005, 10:47 AM
  3. Help me out understand what I need to do please?
    By seal in forum C Programming
    Replies: 8
    Last Post: 10-11-2005, 10:31 PM
  4. Help me understand why
    By byteme101 in forum C Programming
    Replies: 7
    Last Post: 12-08-2004, 09:39 AM
  5. I don't understand K&R example
    By rllovera in forum C Programming
    Replies: 8
    Last Post: 10-25-2004, 10:45 AM