I'm sorry for tripleposting, but I just wanted to increase this request's visibility.
I have finished writing the database updater. Unfortunately, the code's not working right now. The updater was never meant to be public, but I felt that it was important for me to post it here.
Could anyone try fixing the bugs in this program so I can use it for the database?
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "dict.h"
#define RLE 160401
typedef struct Speed {
long long dx;
long long dy;
long long period;
} Speed;
typedef struct Rulespace {
char minrule[274];
char rule[274];
char maxrule[274];
} Rulespace;
typedef struct Conds {
int bconds[117];
int sconds[117];
} Conds;
typedef struct Glider {
long long dx;
long long dy;
long long period;
int minpop;
char minrule[274];
char maxrule[274];
} Glider;
void open(char filepath[], Speed * speed, Rulespace * rulespace, char (* rle)[RLE]) {
int n = 0;
char c;
(*speed).dx = 0;
(*speed).dy = 0;
(*speed).period = 0;
FILE * file;
file = fopen(filepath, "r");
c = getc(file);
while (isdigit(c)) {
(*speed).dx *= 10;
(*speed).dx += (c - '0');
c = getc(file);
}
/* SPACE */
c = getc(file);
/* COLON */
c = getc(file);
/* SPACE */
c = getc(file);
while (isdigit(c)) {
(*speed).dy *= 10;
(*speed).dy += (c - '0');
c = getc(file);
}
/* SPACE */
c = getc(file);
/* COLON */
c = getc(file);
/* SPACE */
c = getc(file);
while (isdigit(c)) {
(*speed).period *= 10;
(*speed).period += (c - '0');
c = getc(file);
}
/* SPACE */
c = getc(file);
/* COLON */
c = getc(file);
/* SPACE */
c = getc(file);
while (c != ' ') {
(*rulespace).rule[n] = c;
n++;
c = getc(file);
}
(*rulespace).rule[n] = 0;
n = 0;
/* SPACE */
c = getc(file);
/* COLON */
c = getc(file);
/* SPACE */
c = getc(file);
while (c != ',') {
(*rle)[n] = c;
n++;
c = getc(file);
}
(*rle)[n] = 0;
fclose(file);
}
void rparse(char rule[274], Conds * conds) {
int n = 1; /* Skip the leading B */
int negating = 0;
int lastdigit = -1;
char letters[14] = "cekainyqjrtwz";
for (int nn = 0; nn < 117; nn++) {
(*conds).bconds[nn] = 0;
(*conds).sconds[nn] = 0;
}
while (rule[n] != '/') {
if (isdigit(rule[n])) {
for (int nn = 0; nn < 13; nn++) {
(*conds).bconds[((rule[n] - '0') * 13) + nn] = 2;
negating = 0;
lastdigit = rule[n] - '0';
}
}
if (isalpha(rule[n])) {
if (negating) {
for (int nn = 0; nn < 13; nn++) {
if (rule[n] == letters[nn]) {
(*conds).bconds[((rule[n] - '0') * 13) + nn] = 0;
}
}
} else {
for (int nn = 0; nn < 13; nn++) {
if ((*conds).bconds[((rule[n] - '0') * 13) + nn] == 2) (*conds).bconds[((rule[n] - '0') * 13) + nn] = 0;
if (rule[n] == letters[nn]) (*conds).bconds[((rule[n] - '0') * 13) + nn] = 1;
}
}
}
if (rule[n] == '-') negating = 1;
n++;
}
n += 2; /* Skip "/S" */
negating = 0;
lastdigit = -1;
while (rule[n]) {
if (isdigit(rule[n])) {
for (int nn = 0; nn < 13; nn++) {
(*conds).sconds[((rule[n] - '0') * 13) + nn] = 2;
negating = 0;
lastdigit = rule[n] - '0';
}
}
if (isalpha(rule[n])) {
if (negating) {
for (int nn = 0; nn < 13; nn++) {
if (rule[n] == letters[nn]) {
(*conds).sconds[((rule[n] - '0') * 13) + nn] = 0;
}
}
} else {
for (int nn = 0; nn < 13; nn++) {
if ((*conds).sconds[((rule[n] - '0') * 13) + nn] == 2) (*conds).sconds[((rule[n] - '0') * 13) + nn] = 0;
if (rule[n] == letters[nn]) (*conds).sconds[((rule[n] - '0') * 13) + nn] = 1;
}
}
}
if (rule[n] == '-') negating = 1;
n++;
}
}
void makebb(char rle[RLE], int * bx, int * by) {
int bbx = 0, bbxr = 0, bby = 0;
int n = 0;
int run;
while (rle[n] != '!') {
if (isdigit(rle[n])) {
run *= 10;
run += (rle[n] - '0');
}
if ((rle[n] == 'b') || (rle[n] == 'o')) {
int r = (run == 0) ? 1 : run;
for (int nn = 0; nn < r; nn++) {
if (bbx > bbxr) {
bbx++;
bbxr++;
} else {
bbx++;
}
}
}
if (rle[n] == '$') {
bbx = 0;
bby++;
}
n++;
}
*bx = bbxr;
*by = bby;
}
void makeworld(char rle[RLE], int bbx, int bby, int (* world)[bby][bbx], Speed speed) {
int x = speed.period, y = speed.period;
int n = 0;
int run;
while (rle[n] != '!') {
if (isdigit(rle[n])) {
run *= 10;
run += (rle[n] - '0');
}
if (rle[n] == 'b') {
int r = (run == 0) ? 1 : run;
for (int nn = 0; nn < r; nn++) {
(*world)[y][x] = 0;
x++;
}
}
if (rle[n] == 'o') {
int r = (run == 0) ? 1 : run;
for (int nn = 0; nn < r; nn++) {
(*world)[y][x] = 1;
x++;
}
}
if (rle[n] == '$') {
y++;
x = speed.period;
}
n++;
}
}
void advance(int bbx, int bby, int (* world)[bby][bbx], Conds conds) {
int binary;
int neigh[8][2] = {{1, 1}, {1, 0}, {1, -1}, {0, 1}, {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};
int next[bby][bbx];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) next[y][x] = 0;
for (int y = 0; y < bby; y++) {
for (int x = 0; x < bbx; x++) {
binary = 0;
for (int n = 0; n < 8; n++) {
binary *= 2;
if ((y + neigh[n][0] < 0) || (y + neigh[n][0] >= bby) || (x + neigh[n][1] < 0) || (x + neigh[n][1] >= bbx)) continue;
binary += (*world)[y][x];
}
if (!(*world)[y][x] && (conds.bconds[dict[binary]])) next[y][x] = 1;
if ((*world)[y][x] && (conds.sconds[dict[binary]])) next[y][x] = 1;
}
}
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) (*world)[y][x] = next[y][x];
}
int getpop(int bbx, int bby, int world[bby][bbx]) {
int pop = 0;
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) if (world[y][x]) pop++;
return pop;
}
int verify(int bbx, int bby, int world[bby][bbx], Speed speed, Conds conds) {
int equal = 1;
int orig[bby][bbx];
int iter[bby][bbx];
int comp[bby][bbx];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) {
orig[y][x] = world[y][x];
iter[y][x] = world[y][x];
comp[y][x] = 0;
}
for (int n = 0; n < speed.period; n++) advance(bbx, bby, &iter, conds);
for (int y = speed.dy; y < bby; y++) for (int x = speed.dx; x < bbx; x++) comp[y - speed.dy][x - speed.dx] = iter[y][x];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) if (comp[y][x] != orig[y][x]) equal = 0;
return equal;
}
void sort(char (* letters)[14]) { /* Basic selection sort */
int n = 0;
int current;
char sorted[14] = "";
for (int current = 'a'; current <= 'z'; current++) {
for (int nn = 0; nn < 13; nn++) {
if ((*letters)[nn] == current) {
sorted[n] = current;
n++;
}
}
}
for (int n = 0; n < 13; n++) (*letters)[n] = sorted[n];
}
void writerule(char (* rulestring)[274], Conds conds) { /* Does the opposite of rparse */
int negating;
int positive;
int n = 0;
int vals[9] = {1, 2, 6, 10, 13, 10, 6, 2, 1};
char letters[14] = "cekainyqjrtwz";
char used[14] = "";
(*rulestring)[n] = 'B';
n++;
for (int c = 0; c < 9; c++) {
positive = 0;
for (int m = 0; m < vals[c]; m++) if (conds.bconds[(c * 13) + m]) positive++;
if (!positive) continue;
(*rulestring)[n] = c + '0';
n++;
if ((vals[c] - positive) < (vals[c] / 2)) negating = 1;
int nn = 0;
if (negating) {
(*rulestring)[n] = '-';
n++;
for (int m = 0; m < vals[c]; m++) {
if (!(conds.bconds[(c * 13) + m])) {
used[nn] = letters[m];
nn++;
}
}
sort(&used);
nn = 0;
while (used[nn]) {
(*rulestring)[n] = used[nn];
nn++;
n++;
}
} else {
for (int m = 0; m < vals[c]; m++) {
if ((conds.bconds[(c * 13) + m])) {
used[nn] = letters[m];
nn++;
}
}
sort(&used);
nn = 0;
while (used[nn]) {
(*rulestring)[n] = used[nn];
nn++;
n++;
}
}
}
(*rulestring)[n] = '/';
n++;
(*rulestring)[n] = 'S';
n++;
for (int c = 0; c < 9; c++) {
positive = 0;
for (int m = 0; m < vals[c]; m++) if (conds.sconds[(c * 13) + m]) positive++;
if (!positive) continue;
(*rulestring)[n] = c + '0';
n++;
if ((vals[c] - positive) < (vals[c] / 2)) negating = 1;
int nn = 0;
if (negating) {
(*rulestring)[n] = '-';
n++;
for (int m = 0; m < vals[c]; m++) {
if (!(conds.sconds[(c * 13) + m])) {
used[nn] = letters[m];
nn++;
}
}
sort(&used);
nn = 0;
while (used[nn]) {
(*rulestring)[n] = used[nn];
nn++;
n++;
}
} else {
for (int m = 0; m < vals[c]; m++) {
if ((conds.sconds[(c * 13) + m])) {
used[nn] = letters[m];
nn++;
}
}
sort(&used);
nn = 0;
while (used[nn]) {
(*rulestring)[n] = used[nn];
nn++;
n++;
}
}
}
}
void getmaxrule(int bbx, int bby, int world[bby][bbx], Speed speed, Conds (* conds)) {
for (int nn = 0; nn < 117; nn++) {
(*conds).bconds[nn] = 0;
(*conds).sconds[nn] = 0;
}
for (int n = 0; n < 117; n++) {
(*conds).bconds[n] = 1;
if (!(verify(bbx, bby, world, speed, *conds))) (*conds).bconds[n] = 0;
}
for (int n = 0; n < 117; n++) {
(*conds).sconds[n] = 1;
if (!(verify(bbx, bby, world, speed, *conds))) (*conds).sconds[n] = 0;
}
}
void getminrule(int bbx, int bby, int world[bby][bbx], Speed speed, Conds (* conds)) {
for (int nn = 0; nn < 117; nn++) {
(*conds).bconds[nn] = 0;
(*conds).sconds[nn] = 0;
}
for (int n = 0; n < 117; n++) {
(*conds).bconds[n] = 0;
if (!(verify(bbx, bby, world, speed, *conds))) (*conds).bconds[n] = 1;
}
for (int n = 0; n < 117; n++) {
(*conds).sconds[n] = 0;
if (!(verify(bbx, bby, world, speed, *conds))) (*conds).sconds[n] = 1;
}
}
int getminpop(int bbx, int bby, int world[bby][bbx], int (* target)[bby][bbx], Speed speed, Conds conds) {
int pop = getpop(bbx, bby, world);
int min[bby][bbx];
int iter[bby][bbx];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) {
min[y][x] = world[y][x];
iter[y][x] = world[y][x];
}
for (int n = 0; n < speed.period; n++) {
if (getpop(bbx, bby, iter) < pop) {
pop = getpop(bbx, bby, iter);
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) (*target)[y][x] = iter[y][x];
}
advance(bbx, bby, &iter, conds);
}
return pop;
}
int sgmp(int bbx, int bby, int world[bby][bbx], Speed speed, Conds conds) { /* Silently get minpop */
int pop = getpop(bbx, bby, world);
int iter[bby][bbx];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) {
iter[y][x] = world[y][x];
}
for (int n = 0; n < speed.period; n++) {
if (getpop(bbx, bby, iter) < pop) {
pop = getpop(bbx, bby, iter);
}
advance(bbx, bby, &iter, conds);
}
return pop;
}
int power(int a, int b) {
int x = 1;
for (int n = 0; n < b; n++) x *= a;
return x;
}
int calcpow(int n) {
int nn;
for (nn = 0; n < power(10, nn); nn++);
return nn;
}
void makerle(int bbx, int bby, int world[bby][bbx], char (* rle)[RLE]) {
int n = 0;
int run = 1;
int lastdigit = -1;
for (int nn = 0; nn < RLE; nn++) (*rle)[nn] = 0;
for (int y = 0; y < bby; y++) {
for (int x = 0; x < bbx; x++) {
if (world[y][x] == lastdigit) {
run++;
} else {
if (run == 1) {
if (world[y][x]) {
(*rle)[n] = 'o';
} else {
(*rle)[n] = 'b';
}
n++;
} else {
for (int nn = calcpow(run); nn > 0; nn--) {
(*rle)[n] = '0' + ((run % power(10, nn)) / power(10, (nn - 1)));
n++;
}
if (world[y][x]) {
(*rle)[n] = 'o';
} else {
(*rle)[n] = 'b';
}
n++;
}
}
}
(*rle)[n] = '$';
n++;
}
(*rle)[n - 1] = '!';
}
int abovelower(Conds test, Conds lower) {
int above = 1;
for (int n = 0; n < 117; n++) {
if (((test.bconds)[n] == 0) && ((lower.bconds)[n] == 1)) {
above = 0;
return above;
}
}
for (int n = 0; n < 117; n++) {
if (((test.sconds)[n] == 0) && ((lower.sconds)[n] == 1)) {
above = 0;
return above;
}
}
return above;
}
int belowupper(Conds test, Conds upper) {
int below = 1;
for (int n = 0; n < 117; n++) {
if (((test.bconds)[n] == 1) && ((upper.bconds)[n] == 0)) {
below = 0;
return below;
}
}
for (int n = 0; n < 117; n++) {
if (((test.sconds)[n] == 1) && ((upper.sconds)[n] == 0)) {
below = 0;
return below;
}
}
return below;
}
int getglidid(int processed) { /* Returns an ID from a line number */
int commacount = 0;
int id = 1; /* Raw ID */
FILE * gliders;
gliders = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "r");
while (commacount != (processed - 1)) {
if (getc(gliders) == ',') commacount++;
}
char c;
while ((c = getc(gliders)) != '!'); /* Scans until the end of the RLE */
getc(gliders); /* Gets ' ' */
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ',') {
id *= 10;
id += (c - '0');
}
return id;
}
int processid(int id, int maxid) { /* Looks for a specific ID */
int n = 1;
FILE * gliders;
gliders = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "r");
for (int n = 1; ; n++) {
if (getglidid(n) == id) return n;
if (n > maxid) break;
}
return -1;
}
void getdata(int processed, Glider * glider) {
int commacount = 0;
FILE * gliders;
gliders = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "r");
while (commacount != (processed - 1)) {
if (getc(gliders) == ',') commacount++;
}
getc(gliders); /* Gets '\n' */
char c;
(*glider).dx = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).dx *= 10;
(*glider).dx += (c - '0');
}
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
(*glider).dy = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).dy *= 10;
(*glider).dy += (c - '0');
}
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
(*glider).period = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).period *= 10;
(*glider).period += (c - '0');
}
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
(*glider).minpop = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).minpop *= 10;
(*glider).minpop += (c - '0');
}
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
for (int n = 0; n < 274; n++) (*glider).minrule[n] = 0;
int nn = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).minrule[nn] = c;
nn++;
}
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
for (int n = 0; n < 274; n++) (*glider).maxrule[n] = 0;
nn = 0;
while ((c = getc(gliders)) != ' ') {
(*glider).maxrule[nn] = c;
nn++;
}
fclose(gliders);
}
int getid(void) {
int id = 0;
FILE * num;
num = fopen("/Users/mamaral/Sites/gliders/ngliders.txt", "r");
char c;
while ((c = getc(num)) != EOF) {
id *= 10;
id += (c - '0');
}
fclose(num);
return id;
}
void putid(void) {
int id = getid();
id++;
FILE * num;
num = fopen("/Users/mamaral/Sites/gliders/ngliders.txt", "w");
for (int n = calcpow(id); n > 0; n--) {
putc(('0' + ((id % power(10, n)) / power(10, n - 1))), num);
}
fclose(num);
}
void transpose(int processed, Speed speed, int (* world)[400 + (speed.period * 2)][400 + (speed.period * 2)]) { /* Get a glider RLE and put it in a world */
int commacount = 0;
int bbx = 400 + (speed.period * 2);
int bby = bbx;
char rle[RLE] = "";
FILE * gliders;
gliders = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "r");
while (commacount != (processed - 1)) {
if (getc(gliders) == ',') commacount++;
}
getc(gliders); /* Gets '\n' */
char c;
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
while ((c = getc(gliders)) != ' ');
getc(gliders); /* Gets ':' */
getc(gliders); /* Gets ' ' */
int nn;
while ((c = getc(gliders)) != ' ') {
rle[nn] = c;
}
makeworld(rle, bbx, bby, world, speed);
}
void getredundantgliders(int (* list)[65536] /* Assume a maximum of 65,536 gliders made redundant */, int maxid, int bbex, int bbey, int exworld[bbey][bbex], Speed speed, Rulespace rulespace) { /* Gets the IDs of all redundant gliders */
int n = 0;
int processed;
int bbx = 400 + (2 * speed.period);
int bby = bbx;
int world[bby][bbx];
int oldmp = 0;
int newmp = 0;
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) world[y][x] = 0;
char minrule[274] = "";
char maxrule[274] = "";
Glider current;
Conds conds;
Conds oldlower;
Conds oldupper;
Conds newlower;
Conds newupper;
rparse(rulespace.rule, &conds);
for (int nn = 0; nn < 65536; nn++) (*list)[nn] = 0;
for (int nn = 1; nn <= maxid; nn++) {
processed = processid(nn, maxid);
if (processed == -1) continue; /* Skips deleted ships */
getdata(processed, ¤t);
if ((current.dx != speed.dx) || (current.dy != speed.dy) || (current.period != speed.period)) continue;
transpose(processed, speed, &world);
oldmp = sgmp(bbx, bby, world, speed, conds);
newmp = sgmp(bbex, bbey, exworld, speed, conds);
getminrule(bbex, bbey, world, speed, &newlower);
getmaxrule(bbex, bbey, world, speed, &newlower);
getminrule(bbx, bby, world, speed, &oldlower);
getmaxrule(bbx, bby, world, speed, &oldupper);
if (newmp > oldmp) continue; /* Some gliders may be made redundant but this one won't since it's smaller */
if (abovelower(oldlower, newlower) && belowupper(oldupper, newupper)) { /* The new glider supports every rule the old glider does */
(*list)[n] = nn; /* Found a redundant glider; add to list */
}
}
}
int isnotable(int maxid, int bbex, int bbey, int exworld[bbey][bbex], Speed speed, Rulespace rulespace) { /* Preliminary check */
/* Logical values */
// int docrule = 0;
int docspeed = 0;
int versatile = 0;
int optimal = 0;
/* ---------------- */
int processed;
int bbx = 400 + (2 * speed.period);
int bby = bbx;
int oldmp = 0;
int newmp = 0;
int world[bby][bbx];
Glider current;
Conds conds;
Conds oldlower;
Conds oldupper;
Conds medrule;
Conds newlower;
Conds newupper;
rparse(rulespace.rule, &medrule);
for (int nn = 1; nn <= maxid; nn++) {
processed = processid(nn, maxid);
if (processed == -1) continue; /* Skips deleted ships */
transpose(processed, speed, &world);
getminrule(bbex, bbey, exworld, speed, &newlower);
getmaxrule(bbex, bbey, exworld, speed, &newlower);
getminrule(bbx, bby, world, speed, &oldlower);
getmaxrule(bbx, bby, world, speed, &oldupper);
if (!(abovelower(medrule, oldlower) && belowupper(medrule, oldupper))) continue; /* Skips spaceships alien to the selected rule */
if (abovelower(newlower, oldlower) && belowupper(newupper, oldupper)) { /* The new spaceship works in a strict subset of the old one's rulespace */
getdata(processed, ¤t);
if ((current.dx == speed.dx) && (current.dy == speed.dy) && (current.period == speed.period)) {
docspeed = 1;
oldmp = sgmp(bbx, bby, world, speed, conds);
newmp = sgmp(bbex, bbey, exworld, speed, conds);
if (newmp < oldmp) {
return 1;
} else {
return 0;
}
}
} else { /* The new spaceship works in a different ruleset */
versatile = 1;
return 1;
}
}
return 1;
}
int in(int id, int list[65536]) {
for (int n = 0; n < 65536; n++) {
if (!(list[n])) break;
if (list[n] == id) return 1;
}
return 0;
}
void move(int (* list)[65536], int maxid) {
int n = 0;
while ((*list)[n]) {
(*list)[n] = processid((*list)[n], maxid);
}
FILE * original;
FILE * buffer;
original = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "r");
buffer = fopen("/Users/mamaral/Sites/gliders/buffer.json", "w");
int commacount = 0;
char c;
while ((c = getc(original))) {
if (!(in((commacount + 1), *list))) {
putc(c, buffer);
}
}
fclose(original);
fclose(buffer);
}
void compose(char (* entry)[200000], int minpop, int id, Speed speed, Rulespace rulespace, char rle[RLE]) {
for (int n = 0; n < 200000; n++) (*entry)[n] = 0;
int n = 0;
for (int nn = calcpow(speed.dx); nn > 0; nn--) {
(*entry)[n] = '0' + ((speed.dx % power(10, nn)) / power(10, (nn - 1)));
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
for (int nn = calcpow(speed.dy); nn > 0; nn--) {
(*entry)[n] = '0' + ((speed.dy % power(10, nn)) / power(10, (nn - 1)));
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
for (int nn = calcpow(speed.period); nn > 0; nn--) {
(*entry)[n] = '0' + ((speed.period % power(10, nn)) / power(10, (nn - 1)));
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
for (int nn = calcpow(minpop); nn > 0; nn--) {
(*entry)[n] = '0' + ((minpop % power(10, nn)) / power(10, (nn - 1)));
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
int nn = 0;
while (rulespace.minrule[nn]) {
(*entry)[n] = rulespace.minrule[nn];
nn++;
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
nn = 0;
while (rulespace.maxrule[nn]) {
(*entry)[n] = rulespace.maxrule[nn];
nn++;
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
nn = 0;
while (rle[nn]) {
(*entry)[n] = rle[nn];
nn++;
n++;
}
(*entry)[n] = ' '; n++;
(*entry)[n] = ':'; n++;
(*entry)[n] = ' '; n++;
for (int nn = calcpow(id); nn > 0; nn--) {
(*entry)[n] = '0' + ((id % power(10, nn)) / power(10, (nn - 1)));
n++;
}
(*entry)[n] = ','; n++;
(*entry)[n] = '\n';
}
void write(char entry[200000]) {
int n = 0;
FILE * gliders;
gliders = fopen("/Users/mamaral/Sites/gliders/GlidINT.json", "a");
while (entry[n]) {
putc(entry[n], gliders);
n++;
}
fclose(gliders);
}
int main(int argc, char * argv[]) {
int bx = 0, by = 0;
int bbx, bby;
int maxid = getid();
int minpop;
int list[65536] = {0};
char rle[RLE] = {0};
char entry[200000] = "";
if (argc == 1) {
printf("Usage: commit (filepath)\n");
return 0;
}
Speed speed;
Rulespace rulespace;
Conds conds;
Conds minc;
Conds maxc;
for (int cn = 0; cn < 117; cn++) {
minc.bconds[cn] = conds.bconds[cn];
minc.sconds[cn] = conds.sconds[cn];
maxc.bconds[cn] = conds.bconds[cn];
maxc.sconds[cn] = conds.sconds[cn];
}
open(argv[1], &speed, &rulespace, &rle);
makebb(rle, &bx, &by);
bbx = bx + (2 * speed.period);
bby = by + (2 * speed.period);
int world[bby][bbx];
for (int y = 0; y < bby; y++) for (int x = 0; x < bbx; x++) world[y][x] = 0;
makeworld(rle, bbx, bby, &world, speed);
if (!verify(bbx, bby, world, speed, conds)) return 0; /* Removes faulty spaceships */
if (!getpop(bbx, bby, world)) return 0; /* Filters zero-population ships */
if (!isnotable(maxid, bbx, bby, world, speed, rulespace)) return 0; /* Filters duplicates or completely suboptimal ships */
getredundantgliders(&list, maxid, bbx, bby, world, speed, rulespace);
move(&list, maxid);
system("/Users/mamaral/Sites/gliders/ mv buffer.json GlidINT.json");
getminrule(bbx, bby, world, speed, &minc);
getmaxrule(bbx, bby, world, speed, &maxc);
writerule(&(rulespace.minrule), minc);
writerule(&(rulespace.maxrule), maxc);
minpop = getminpop(bbx, bby, world, &world, speed, conds); /* Assigns the ship's minpop to "minpop" and shifts the ship to the minpop phase */
makerle(bbx, bby, world, &rle);
maxid++;
compose(&entry, minpop, maxid, speed, rulespace, rle);
write(entry);
/* Format: dx : dy : period : minpop : minrule : maxrule : rle : entrynum, */
}
.
Fixes of any size are welcome.