Advertisement
Guest User

fbiezfbeuzf

a guest
Oct 25th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. void nextGen(int array[2][AXE_X][AXE_Y], int var)
  2. {
  3.     int x, y;
  4.     int i, j;
  5.     int nbAlive;
  6.     for(y=1;y<AXE_Y-1;y++)
  7.         {
  8.                 for(x=1;x<AXE_X-1;x++)
  9.                 {
  10.             if(array[var][x][y] == MORT)
  11.             {
  12.                 nbAlive=0;
  13.             }
  14.             else
  15.             {
  16.                 nbAlive=-1;
  17.             }
  18.             for(i=(y-1); i<y+2; i++)
  19.             {
  20.                 for(j=(x-1); j<x+2; j++)
  21.                 {
  22.                     if(array[var][i][j] == VIVANT)
  23.                     {
  24.                         nbAlive++;
  25.                     }
  26.                     printf("i=%d, y=%d, j=%d, x=%d, nbAlive=%d\n", i, y, j, x, nbAlive);
  27.                 }
  28.             }
  29.             printf("\n");
  30.             //LA SURVIE
  31.             if(array[var][x][y] == VIVANT && (nbAlive == 2 || nbAlive == 3))
  32.                 array[!var][x][y] = VIVANT;
  33.             //LA MORT
  34.             else if(array[var][x][y] == VIVANT && (nbAlive > 3 || nbAlive < 2))
  35.                 array[!var][x][y] = MORT;
  36.             //LA NAISSANCE
  37.             else if(array[var][x][y] == MORT && nbAlive == 3)
  38.                 array[!var][x][y] = VIVANT;
  39.             else
  40.                 array[!var][x][y] = array[var][x][y];
  41.         }
  42.         }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement