Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void nextGen(int array[2][AXE_X][AXE_Y], int var)
- {
- int x, y;
- int i, j;
- int nbAlive;
- for(y=1;y<AXE_Y-1;y++)
- {
- for(x=1;x<AXE_X-1;x++)
- {
- if(array[var][x][y] == MORT)
- {
- nbAlive=0;
- }
- else
- {
- nbAlive=-1;
- }
- for(i=(y-1); i<y+2; i++)
- {
- for(j=(x-1); j<x+2; j++)
- {
- if(array[var][i][j] == VIVANT)
- {
- nbAlive++;
- }
- printf("i=%d, y=%d, j=%d, x=%d, nbAlive=%d\n", i, y, j, x, nbAlive);
- }
- }
- printf("\n");
- //LA SURVIE
- if(array[var][x][y] == VIVANT && (nbAlive == 2 || nbAlive == 3))
- array[!var][x][y] = VIVANT;
- //LA MORT
- else if(array[var][x][y] == VIVANT && (nbAlive > 3 || nbAlive < 2))
- array[!var][x][y] = MORT;
- //LA NAISSANCE
- else if(array[var][x][y] == MORT && nbAlive == 3)
- array[!var][x][y] = VIVANT;
- else
- array[!var][x][y] = array[var][x][y];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement