-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game_of_Life_Dynamic.c
executable file
·143 lines (84 loc) · 1.85 KB
/
Game_of_Life_Dynamic.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int x_size = 102;
const int y_size = 102;
const int x_board = 100;
const int y_board = 100;
const int cycles = 100;
//Matrix-Print Function
void mprint(double matrix[x_size][y_size]){
for (int i = 0; i < x_size; i++){
for (int j = 0; j < y_size; j++){
printf("%f ", matrix[i][j]);
}
printf("\n");
}
}
int main(){
FILE *f = fopen("Game_Saver.txt", "w");
double universe[x_size][y_size];
for (int i = 0; i<x_size; i++){
for (int j = 0; j<y_size; j++){
universe[i][j] = 0.0;
}
}
int iterator, init;
int x, y;
iterator = 0;
init =6000;
srand(time(NULL));
//Initialize the universe
while (iterator < init){
x = 1 + random() % x_board;
y = 1 + random() % y_board;
if (universe[x][y] == 0.0){
universe[x][y] += 1.0;
iterator += 1;
}
}
double alpha = 10;
iterator = 0;
double summation[x_board][y_board];
while (iterator < cycles){
for (int i = 0; i<x_board; i++){
for (int j = 0; j<y_board; j++){
summation[i][j] = 0.0;
}
}
for (int m =0; m<3; m++){
for (int n =0; n<3; n++){
for (int i = 0; i < x_board; i++){
for (int j=0; j < y_board; j++){
if (m == 1 && n == 1){
summation[i][j] += universe[i+m][j+n]*10.0;
}
else {
summation[i][j] += universe[i+m][j+n];
}
}
}
}
}
iterator += 1;
for (int i = 0; i < x_board; i++){
for (int j = 0; j < y_board; j++){
universe[i+1][j+1] = 0.0;
if (summation[i][j] == 3.0){
universe[i+1][j+1] += 1.0;
}
if (summation[i][j] == 12.0 || summation[i][j] == 13.0){
universe[i+1][j+1] += 1.0;
}
}
}
for (int i = 1; i < x_size-1; i++){
for (int j = 1; j < y_size-1; j++){
fprintf(f, "%f ", universe[i][j]);
}
}
fprintf(f, "\n");
}
fclose(f);
return 0;
}