Game Of Life 3D

This is a discussion on Game Of Life 3D within the C Programming forums, part of the General Programming Boards category; I had to implement Game of Life in a 3D matrix (int a[ ][ ][ ]) , but the complexity ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    4

    Arrow Game Of Life 3D

    I had to implement Game of Life in a 3D matrix (int a[ ][ ][ ]) , but the complexity of my implementation is O(n^6) (6 imbricated for) and it runs very slow . Can anyone help me with an optimized version of Game of life , even with a 2D matrix . Or how the Game of Life in general could be optimized ?

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    How big is the array? I don't know why you use a 3d array in the first place.
    Generally you could make the 3d array in a 2d array, even if 1d array, but how would that help? The point is to reduce the total information needed.

    My first thought is that the board game Game of Life cannot run slow in any possible implementation. It is a simple turn based game.
    So:
    1) How big is the 3d array? And why is it 3d?
    2) Give some code (if you want) of the function you think delays the game

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    4
    Quote Originally Posted by C_ntua View Post
    How big is the array? I don't know why you use a 3d array in the first place.
    Generally you could make the 3d array in a 2d array, even if 1d array, but how would that help? The point is to reduce the total information needed.

    My first thought is that the board game Game of Life cannot run slow in any possible implementation. It is a simple turn based game.
    So:
    1) How big is the 3d array? And why is it 3d?
    2) Give some code (if you want) of the function you think delays the game
    it has to be a cube with tha n*n*n dimensions with n*n*n cells . i tested it with n = 64 and 5 generations , and even with one generation it doesn't stop from running . with n = 10 it's ok


    for(i=0;i<max;i++)
    for(j=0;j<max;j++)
    for(k=0;k<max;k++){

    another 3 for cycles for the area in witch the neighbours are

    test if the neighbour matrix[i'][j'][k'] of the element matrix[i][j][k] is alive



    do u know a way to transform a 3d matrix in a 2d one

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    You posted this everywhere you could find, eh? Very poor etiquette.

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    So it has 262,144 elements. If they are int (4bytes) it is about 1MB. It isn't big. I guess what you check inside the loops is what creates a delay, but you don't provide that information.
    You ask the wrong question, that is what I am trying to say.

    You can have 1D matrix of 3*max dimension. Then to find the right element you can use the a[i+max*j+max*k] if you know what I mean. But you will gain nothing.

    What you want is to reduce the data. Or reduce the calculations you do. In another way you have to post your algorithm

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Conway's Game of Life is usually coded up in a 2D array. If your version is slow, it's because you have extra code that isn't needed, running madly about inside the loops.

    Post up your program, and let's get this going into a 2D and/or quick 3D program. Game of Life is a lightning bolt compared to chess. Speed will be no problem.

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I wikipedied game of life. Lol, I though you met the (simple-fun-stupid) board game "Game of Life".

    Well, yeah you need a 2D array, don't know why you made it 3D. Are you creating a 3d version of the original "game"?

    Anyway, it is too simple not to be solved, so just post your code

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    If you want optimisation help you pretty much need to provide more information, and usually need to post code. O(n^6) seems beyond ridiculous for this, to me.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by C_ntua View Post
    I wikipedied game of life. Lol, I though you met the (simple-fun-stupid) board game "Game of Life".

    Well, yeah you need a 2D array, don't know why you made it 3D. Are you creating a 3d version of the original "game"?

    Anyway, it is too simple not to be solved, so just post your code
    ROFL!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL - 2d text in 3d game
    By mikeb1986 in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 12:24 PM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. 3d game modellers
    By Boomba in forum Game Programming
    Replies: 10
    Last Post: 08-29-2005, 06:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21