-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
68 lines (61 loc) · 1.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
int gen[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int ruleset[]={0,0,0,1,1,1,1,0};
int size = sizeof gen / sizeof gen[0];
int alive=1;
int dead=0;
int rules(int a, int b, int c){
if(a==alive && b==alive && c==alive){return ruleset[0];}
if(a==alive && b==alive && c==dead){return ruleset[1];}
if(a==alive && b==dead && c==alive){return ruleset[2];}
if(a==alive && b==dead && c==dead){return ruleset[3];}
if(a==dead && b==alive && c==alive){return ruleset[4];}
if(a==dead && b==alive && c==dead){return ruleset[5];}
if(a==dead && b==dead && c==alive){return ruleset[6];}
if(a==dead && b==dead && c==dead){return ruleset[7];}
}
int get_gen(int pos,int *gen,int sz){
if(pos<0 || pos>=sz){
return 0;
}
return gen[pos];
}
int main(void){
int iterations;
int procces;
for(iterations=0;iterations<30;iterations++){
int left=get_gen(-1,gen,size);
for(procces=0;procces<size;procces++){
int right=get_gen(procces+1,gen,size);
int cell=get_gen(procces,gen,size);
gen[procces]=rules(left,cell,right);
if(gen[procces]==0){
printf(" ");
} else {
printf("@");
}
left=cell;
}
printf("\n");
}
}
int ruleset(int grid[sizeX][sizeY], int x, int y){
if(grid[x-1][y+1]==0 && grid[x][y+1]==0 && grid[x+1][y+1]==0){
grid[x][y] = 0;
grid[x][y+1] = 1;
}
else if(grid[x][y+1]==1){
if(grid[x-1][y+1]==0){
grid[x][y] = 0;
grid[x-1][y+1] = 1;
}
else if(grid[x+1][y+1]== 0){
grid[x][y] = 0;
grid[x+1][y+1] = 1;
}
}
}