示例#1
0
void GameOfLife::control_Conway ( int **prevLattice, int **nextLattice )
{
  for ( int i {0}; i<m_h; ++i )

    for ( int j {0}; j<m_w; ++j )
      {

        int liveNeighbors = numberOfNeighbors ( prevLattice, i, j, true );

        if ( prevLattice[i][j] == true )
          {
            if ( liveNeighbors==2 || liveNeighbors==3 )
              {
                nextLattice[i][j] = true;
              }
            else
              {
                nextLattice[i][j] = false;
              }
          }
        else
          {
            if ( liveNeighbors==3 )
              {
                nextLattice[i][j] = true;
              }
            else
              {
                nextLattice[i][j] = false;
              }
          }
      }
}
//Fonction qui calcule la génération suivante.
void nextStep (int gamePlane[2][DIMENSION][DIMENSION], int size, int currentPlane)
{
	int i = 0, j = 0, neighbors = 0, nextPlane = 0 ;
	
	nextPlane = (currentPlane+1)%2 ;
	for (i=0 ; i<size ; i++)
	{
		for (j=0 ; j<size ; j++)
		{
			neighbors = numberOfNeighbors(gamePlane[currentPlane], size, i, j) ;
			//Destin de la cellule...
			if (gamePlane[currentPlane][i][j] ==1)
			{
				if (neighbors<2)
				{
					gamePlane[nextPlane][i][j] = 0 ;
				}
				else if (neighbors>3)
				{
					gamePlane[nextPlane][i][j] = 0 ;
				}
				else
				{
					gamePlane[nextPlane][i][j] = 1 ;
				}
			}
			else
			{
				if (neighbors == 3)
				{
					gamePlane[nextPlane][i][j] = 1 ;
				}
				else
				{
					gamePlane[nextPlane][i][j] = 0 ;
				}
			}
		}
	}
}