forked from conwaylife/ptbsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ptbsearch2.c
138 lines (109 loc) · 4.08 KB
/
ptbsearch2.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
#include <stdio.h>
#include <limits.h>
#include "gen.h"
#include <malloc.h>
#include <assert.h>
#define MAXDEPTH 10
static char out[8000];
Cell perturbPlace[MAXDEPTH];
int perturbGen[MAXDEPTH];
static LifeList reaction[MAXDEPTH], justPerturbs;
static Cell alignstore[100000];
static Cell *aligns=alignstore;
static LifeList tmp;
int ptbPrecedes(int gen1, int ptb1, int pos1,
int gen2, int ptb2, int pos2) {
if (gen1<gen2) return 1;
if (gen1>gen2) return 0;
if (ptb1<ptb2) return 1;
if (ptb1>ptb2) return 0;
if (pos1<pos2) return 1;
return 0;
}
void outTr(int transl) {
int x,y;
unpacktrans(transl, &x, &y);
printf(" (%3d,%3d) ", x,y);
}
void perturbEnum(LifeList *seed, LifeList *perturbs, int nperturbs, int depth,
int maxDepth, int mingen, int maxgencurr, int maxgenall, int maxvanish) {
int i, naligns;
int iperturb, thisgen;
for (iperturb=0; iperturb<nperturbs; iperturb++) {
copyLifeList(seed, reaction+depth);
setValues(reaction[depth].cellList, reaction[depth].ncells, 1);
naligns=placeNewPerturbor(reaction+depth, perturbs,
perturbPlace, depth, iperturb,
mingen, maxgencurr, aligns);
setupPerturbors(perturbs, perturbPlace, depth,
&justPerturbs, reaction+depth);
for (thisgen=0; thisgen<mingen; thisgen++) generate(reaction+depth);
for (; thisgen<maxgencurr; thisgen++) {
for (i=0; i<naligns; i++) {
int j;
int tvanish = maxvanish;
int oldcount;
assert((aligns-alignstore)+i < 100000);
if (aligns[i].value==thisgen &&
(depth<=0 ||
ptbPrecedes(perturbGen[depth-1],
perturbPlace[depth-1].value,
perturbPlace[depth-1].position,
thisgen, iperturb, aligns[i].position)
)
) {
copyLifeList(reaction+depth, &tmp);
justPerturbs.ncells=0;
for (j=0; j<depth; j++) {
mergeLifeLists(&justPerturbs, perturbs+perturbPlace[j].value,
perturbPlace[j].position);
}
resymmetrise(&justPerturbs);
mergeLifeLists(&tmp, perturbs+iperturb, aligns[i].position);
resymmetrise(&tmp);
oldcount=justPerturbs.ncells;
mergeLifeLists(&justPerturbs, perturbs+iperturb,
aligns[i].position);
resymmetrise(&justPerturbs);
// if (iperturb==8) printf("chose a block %d %d\n", perturbs[iperturb].ncells, countGreaterThan(perturbs[iperturb].cellList, perturbs[iperturb].ncells, 1) );
if ( countGreaterThan(perturbs[iperturb].cellList,
perturbs[iperturb].ncells, 1) ==
perturbs[iperturb].ncells) tvanish--;
if (tvanish>=0 &&
oldcount+SYMM*perturbs[iperturb].ncells == justPerturbs.ncells &&
survives(&tmp, &justPerturbs, 0, 10)) {
if (depth >= maxDepth) {
if (restored(&tmp, &justPerturbs, 0, 50)) {
copyLifeList(seed, &tmp);
mergeLifeLists(&tmp, &justPerturbs, 0);
makeString(tmp.cellList, tmp.ncells, out);
// outTr(perturbPlace[0].position);
// outTr(perturbPlace[1].position);
// outTr(aligns[i].position);
printf("%s %d\n", out, thisgen);
/*
printf("%d %d %d ", perturbPlace[0].position,
perturbPlace[0].value,
perturbGen[0]);
printf("%d %d %d\n", aligns[i].position,
iperturb,
aligns[i].value);
*/
fflush(stdout);
}
} else {
perturbPlace[depth].position= aligns[i].position;
perturbPlace[depth].value= iperturb;
perturbGen[depth]= thisgen;
aligns+=naligns;
perturbEnum(seed, perturbs, nperturbs, depth+1, maxDepth,
thisgen, maxgenall, maxgenall, tvanish);
aligns-=naligns;
}
}
}
}
generate(reaction+depth);
}
}
}