Program described in class on 9/10/21
Rules can be found in class video, short version here::
For G[x][y] ... add all neighbors & self to find sum
In the next generation, value at [x][y] is
XXXXXXXXXXsum % 10 == 0 XXXXXXXXXX0
XXXXXXXXXXsum is under 50 XXXXXXXXXXadd 3 to cu
ent
XXXXXXXXXXsum between 50 & XXXXXXXXXXsubtract 3, but can't go below 0
XXXXXXXXXXsum over 150 XXXXXXXXXX1
XXXXXXXXXXAny neighbors outside space are 0's
*
Sample to illustrate rules:
A--
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
B--
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
*
this code does not work, but shows you how it should be structured
#include
establish your sizes using variables or #define
so that it is easy to change;
remainder of code should look at these values
int NR = 6;
int NC = 6;
fill grid G with random values
use srand(seed); to set the sequence
use % high to restrict the range
int fillGrid( int G[][], int seed, int high )
{
}
print out the grid
void printGrid( int G[][] )
{
}
given grid, and an particular (x,y) location
compute the value of that spot in next generation
int checker( int a
[][NC],int x, int y )
{
}
int main()
{
int A[NR][NC];
fillGrid( A, 38, 20 );
printf("A--\n");
printGrid(A);
for (i = __ ; i < __; ++i )
{
for (j = __; j < __; ++j )
{
B[i][j] = checker( A, i, j );
}
}
printGrid(B);
return 0;
}