GOL元胞自动机c语言实现,“约翰·康威生命游戏”的C语言实现(22*22)

#include

int delay(unsigned int i);

int main(void)

{

char a[24][24]={' '};

char b[24][24]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ','8',' ',' ',' ','8',' ',' ',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ','8',' ','8',' ','8',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ','8',' ','8',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ','8',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',

' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',};

int n=0,i=0,j=0,k=0,x=0,y=0;

while(1)

{

for(i=1;i<=22;i++)

{   for(j=1;j<=22;j++)

{

n=0;

for(x=(i-1);x<=(i+1);x++)

{  for(y=(j-1);y<=(j+1);y++)

{   if(b[x][y]=='8')

n=n+1;

}

}

if(b[i][j]=='8')

{

if(n>4)

a[i][j]=' ';

else if(n<3)

a[i][j]=' ';

else if(n==3)

a[i][j]='8';

else if(n==4)

a[i][j]='8';

printf("%c ",a[i][j]);

}

else if(b[i][j]==' ')

{

if(n==3)

a[i][j]='8';

else

a[i][j]=' ';

printf("%c ",a[i][j]);

}

}

printf("\n");

}

printf("\n");

delay(3000);

for(i=1;i<=22;i++)

{   for(j=1;j<=22;j++)

{

n=0;

for(x=(i-1);x<=(i+1);x++)

{  for(y=(j-1);y<=(j+1);y++)

{   if(a[x][y]=='8')

n=n+1;

}

}

if(a[i][j]=='8')

{

if(n>4)

b[i][j]=' ';

else if(n<3)

b[i][j]=' ';

else if(n==3)

b[i][j]='8';

else if(n==4)

b[i][j]='8';

printf("%c ",b[i][j]);

}

else if(a[i][j]==' ')

{

if(n==3)

b[i][j]='8';

else

b[i][j]=' ';

printf("%c ",b[i][j]);

}

}

printf("\n");

}

printf("\n");

delay(3000);

}

}

int delay(unsigned int i)

{

unsigned int j,k;

for(j=i; j>0; j--)

for(k=100000; k>0; k--);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值