forked from conwaylife/BellmanWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritefile.c
More file actions
52 lines (40 loc) · 1.5 KB
/
Copy pathwritefile.c
File metadata and controls
52 lines (40 loc) · 1.5 KB
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
#include <string.h>
#include <stdio.h>
#include "readwrite.h"
void write_life105(FILE *f, generation *g) {
tile *t;
int x, y;
for(t=g->all_first; t; t=t->all_next) {
int ll, rr, tt, bb;
tile_find_bounds(t, &ll, &rr, &tt, &bb);
fprintf(f, "#P %d %d\n", t->xpos + ll, t->ypos + tt);
for(y=tt; y<=bb; y++) {
for(x=ll; x<=rr; x++) {
char c = '.';
switch(tile_get_cell(t, x, y)) {
case OFF: c = '.'; break;
case ON: c = '*'; break;
case UNKNOWN: c = ':'; break;
case UNKNOWN_STABLE: c = '?'; break;
}
fputc(c, f);
}
fputc('\n', f);
}
}
}
void write_life105_text(FILE *f, generation *g) {
tile *t;
int x, y;
for(t=g->all_first; t; t=t->all_next) {
int ll, rr, tt, bb;
tile_find_bounds_text(t, &ll, &rr, &tt, &bb);
fprintf(f, "#P %d %d\n", t->xpos + ll, t->ypos + tt);
for(y=tt; y<=bb; y++) {
for(x=ll; x<=rr; x++) {
fputc(tile_get_text(t, x, y), f);
}
fputc('\n', f);
}
}
}