1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-30 15:39:54 +00:00

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 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 // you can also do -mineadj
EX string fillup(string s) { EX string fillup(string s) {
@ -3401,13 +3409,15 @@ EX namespace ca {
EX void simulate() { EX void simulate() {
if(cwt.at->land != laCA) return; 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); int dcs = isize(allcells);
std::vector<bool> willlive(dcs); std::vector<bool> willlive(dcs);
int old = 0, xold = 0; int old = 0, xold = 0;
for(int i=0; i<dcs; i++) { for(int i=0; i<dcs; i++) {
cell *c = allcells[i]; cell *c = allcells[i];
if(c->land != laCA) return; if(c->land != laCA) continue;
int nei = 0, live = 0; int nei = 0, live = 0;
for(cell *c2: adj_minefield_cells(c)) { for(cell *c2: adj_minefield_cells(c)) {
nei++; if(c2->wall == wlive) live++; nei++; if(c2->wall == wlive) live++;
@ -3418,9 +3428,15 @@ EX namespace ca {
} }
for(int i=0; i<dcs; i++) { for(int i=0; i<dcs; i++) {
cell *c = allcells[i]; cell *c = allcells[i];
auto last = c->wall;
c->wall = willlive[i] ? wlive : waNone; 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 } EX }

View File

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

View File

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