void playss(int **, int, int);
void print(int**,int);
int adjacent_to (int **, int, int );
int sizeX,sizeY;
int num_of_iterations;
int** temp;
int** current;
int** next;
int main(){
/* reading the size of the grid */
printf("enter size for mxm matrix");
scanf("%d",&sizeX);
sizeY=sizeX;
printf("\n%d,%d\n",sizeX,sizeY);
//initializing an double pointer array to hold the grid cell
current = new int*[sizeX];
for(int i=0; i < sizeX; ++i)
{ //int value;
current[i] = new int[sizeY];
}
// Reading the state of the grid from user input
printf("\n enter the state of the matrix\n");
for(int i=0; i<sizeX ; i++)
{ for(int j=0; j<sizeY; j++)
{
printf("enter state for a[%d][%d]",i,j);
scanf("%d",¤t[i][j]);
}
}
// get the value for number of generations user want to generate
printf("number of iterations");
scanf("%d",&num_of_iterations);
#pragma
{
// starting game
for(int play=0;play<=num_of_iterations;play++)
{
// calculating the neighbors values
for (int i=0; i<sizeX; i++)
{
for (int j=0; j<sizeX; j++)
{
int n=0;
if ((i+1)<sizeX && current[i+1][j]==1)
n=n+1;
if ((i-1)>=0 && current[i-1][j]==1)
n=n+1;
if ((j+1)<sizeX && current[i][j+1]==1)
n=n+1;
if ((j-1)>=0 && current[i][j-1]==1)
n=n+1;
if ((i+1)<sizeX && (j+1)<sizeX && current[i+1][j+1]==1)
n=n+1;
if ((i+1)<sizeX && (j-1)>=0 && current[i+1][j-1]==1)
n=n+1;
if ((i-1)>=0 && (j+1)<sizeX && current[i-1][j+1]==1)
n=n+1;
if ((i-1)>=0 && (j-1)>=0 && current[i-1][j-1]==1)
n=n+1;
// decide the cell postion in next generation
if (n==3)
next[i][j]=1; // if neighbors == 3 make it alive
if (current[i][j]==1 && n!=2 && n!=3)// make it dead
next[i][j]=0;
}
}