#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
const int n=25;
const int p=6;
const int dir[][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};
char s[100][100],o[100][100];
inline void print() {
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
putchar(s[i][j]);
}
putchar('\n');
}
}
int main() {
srand(time(0));
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
int t=rand()%p;
if(!t) s[i][j]=1;
}
}
print();
for(;;) {
char c=getchar();
if(c=='r')break;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
o[i][j]=0;
for(int k=0;k<8;k++) {
o[i][j]+=s[i+dir[k][0]][j+dir[k][1]];
}
if(o[i][j]==3) o[i][j]=1;
else {
if(o[i][j]==2) o[i][j]=s[i][j];
else o[i][j]=0;
}
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
s[i][j]=o[i][j];
}
}
system("cls");
print();
}
}
假的生命游戏
最新推荐文章于 2024-07-08 08:09:13 发布