-
Notifications
You must be signed in to change notification settings - Fork 0
/
Larger_than_life.c
executable file
·157 lines (104 loc) · 2.63 KB
/
Larger_than_life.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//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");
int window, cycles, iterator, init, x, y;
int x_board;
int y_board;
double birth, survive_1, survive_2;
printf("Select x board size:\n");
scanf("%d", &x_board);
printf("Select y board size:\n");
scanf("%d", &y_board);
printf("Select initialization population:\n");
scanf("%d", &init);
printf("Select cycle number:\n");
scanf("%d", &cycles);
printf("Select your preferred window size:\n");
scanf("%d", &window);
printf("Select your preferred birth rule:\n");
scanf("%lf", &birth);
printf("Select your preferred first survive rule:\n");
scanf("%lf", &survive_1);
printf("Select your preferred second survive rule:\n");
scanf("%lf", &survive_2);
int x_size = x_board + (2 * (window - 2));
int y_size = x_board + (2 * (window - 2));
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;
}
}
iterator = 0;
srand(time(NULL));
//Initialize the universe
while (iterator < init){
x = (window - 2) + random() % x_board;
y = (window - 2) + 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<window; m++){
for (int n =0; n<window; n++){
for (int i = 0; i < x_board; i++){
for (int j=0; j < y_board; j++){
if (m == (window-2) && n == (window-2)){
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+(window-2)][j+(window-2)] = 0.0;
if (summation[i][j] == birth){
universe[i+(window-2)][j+(window-2)] += 1.0;
}
if (summation[i][j] == 10.0 + survive_1 || summation[i][j] == 10.0 + survive_2){
universe[i+(window-2)][j+(window-2)] += 1.0;
}
}
}
for (int i = (window - 2); i < x_size - (window - 2); i++){
for (int j = (window - 2); j < y_size - (window - 2); j++){
fprintf(f, "%f ", universe[i][j]);
}
}
fprintf(f, "\n");
}
fclose(f);
return 0;
}