# Thread: Game Of Life 3D

1. ## 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. 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. Originally Posted by C_ntua
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. You posted this everywhere you could find, eh? Very poor etiquette.

5. 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. 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. 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. 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.

9. Originally Posted by C_ntua
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