-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenvelope.c
69 lines (55 loc) · 2.23 KB
/
envelope.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 <stdlib.h>
#include <assert.h>
#include <getopt.h>
#include "universe.h"
#include "readwrite.h"
int main(int argc, char *argv[]) {
int c;
int gens = 10;
while((c = getopt(argc, argv, "g:")) != -1) switch(c) {
case 'g':
gens = strtoul(optarg, NULL, 10);
break;
}
universe *u = read_text(argv[optind]);
tile *t;
int x, y;
for(t=u->first->all_first; t; t=t->all_next) {
for(y=0; y<TILE_HEIGHT; y++) for(x=0; x<TILE_WIDTH; x++) {
cellvalue v = tile_get_cell(t, x, y);
if(v != OFF)
tile_set_cell(t, x, y, ON);
}
}
int i;
for(i=0; i<gens; i++)
universe_evolve_next(u);
generation_to_text(u->first);
for(t=u->first->all_first; t; t=t->all_next) {
for(y=0; y<TILE_HEIGHT; y++) for(x=0; x<TILE_WIDTH; x++) {
char v = tile_get_text(t, x, y);
if(v == '.')
tile_set_text(t, x, y, ' ');
}
}
generation *g;
for(g = u->first; g; g = g->next) {
for(t = g->all_first; t; t = t->next) {
for(y=0; y<TILE_HEIGHT; y++) for(x=0; x<TILE_WIDTH; x++) {
cellvalue v = tile_get_cell(t, x, y);
if(v == ON) {
int dx, dy;
for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) {
int xx = t->xpos + x + dx;
int yy = t->ypos + y + dy;
c = generation_get_text(u->first, xx, yy);
if(c == ' ')
generation_set_text(u->first, xx, yy, '.');
}
}
}
}
}
write_life105_text(stdout, u->first);
return 0;
}