CA for infinite

This commit is contained in:
Zeno Rogue 2020-04-12 20:33:53 +02:00
parent 43e1204e18
commit 11d119766d
3 changed files with 30 additions and 7 deletions

View File

@ -3347,6 +3347,14 @@ EX namespace ca {
EX eWall wlive = waFloorA;
EX unordered_set<cell*> changed;
EX void list_adj(cell *c) {
changed.insert(c);
for(cell* c1: adj_minefield_cells(c))
changed.insert(c1);
}
// you can also do -mineadj
EX string fillup(string s) {
@ -3401,13 +3409,15 @@ EX namespace ca {
EX void simulate() {
if(cwt.at->land != laCA) return;
vector<cell*>& allcells = currentmap->allcells();
vector<cell*> allcells;
for(cell *c: changed) allcells.push_back(c);
changed.clear();
int dcs = isize(allcells);
std::vector<bool> willlive(dcs);
int old = 0, xold = 0;
for(int i=0; i<dcs; i++) {
cell *c = allcells[i];
if(c->land != laCA) return;
if(c->land != laCA) continue;
int nei = 0, live = 0;
for(cell *c2: adj_minefield_cells(c)) {
nei++; if(c2->wall == wlive) live++;
@ -3418,9 +3428,15 @@ EX namespace ca {
}
for(int i=0; i<dcs; i++) {
cell *c = allcells[i];
auto last = c->wall;
c->wall = willlive[i] ? wlive : waNone;
if(c->wall != last) {
dynamicval<ld> d(prob, 0);
setdist(c, 7, nullptr);
list_adj(c);
}
}
println(hlog, tie(dcs, old, xold));
println(hlog, make_tuple(dcs, old, xold, isize(changed)));
}
EX }

View File

@ -559,10 +559,14 @@ EX hookset<bool(cell*)> *hooks_mark;
EX void performMarkCommand(cell *c) {
if(!c) return;
if(callhandlers(false, hooks_mark, c)) return;
if(c->land == laCA && c->wall == waNone)
c->wall = waFloorA;
else if(c->land == laCA && c->wall == waFloorA)
if(c->land == laCA && c->wall == waNone) {
c->wall = ca::wlive;
ca::list_adj(c);
}
else if(c->land == laCA && c->wall == ca::wlive) {
c->wall = waNone;
ca::list_adj(c);
}
if(c->land != laMinefield) return;
if(c->item) return;
if(!mightBeMine(c)) return;

View File

@ -1054,8 +1054,11 @@ EX void giantLandSwitch(cell *c, int d, cell *from) {
break;
case laCA:
if(fargen)
if(fargen) {
c->wall = (hrand(1000000) < ca::prob * 1000000) ? ca::wlive : waNone;
if(c->wall == ca::wlive)
ca::list_adj(c);
}
break;
case laLivefjord: