1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-20 15:40:26 +00:00

expansion analyzer now uses the correct order of children

This commit is contained in:
Zeno Rogue 2018-09-23 02:24:18 +02:00
parent 0294c0acb1
commit 0435c490c3

View File

@ -101,23 +101,32 @@ int expansion_analyzer::sample_id(cell *c) {
return cit; return cit;
} }
template<class T, class U> vector<int> get_children_codes(cell *c, const T& distfun, const U& typefun) {
vector<int> res;
int d = distfun(c);
cellwalker cw(c, 0);
if(d > 0) {
forCellCM(c2, c) if(celldist(cw.peek()) < d) break; else cw++;
}
for(int k=0; k<c->type; k++) {
cell *c1 = cw.cpeek();
cw++;
if(distfun(c1) != d+1) continue;
cell *c2 = cw.cpeek();
if(distfun(c2) != d+1) continue;
res.push_back(typefun(c1));
}
return res;
}
void expansion_analyzer::preliminary_grouping() { void expansion_analyzer::preliminary_grouping() {
samples.clear(); samples.clear();
codeid.clear(); codeid.clear();
children.clear(); children.clear();
sample_id(currentmap->gamestart()); sample_id(currentmap->gamestart());
for(int i=0; i<isize(samples); i++) { // queue for, do not change to range-based for
children.emplace_back(); for(int i=0; i<isize(samples); i++)
auto c = samples[i]; children.push_back(get_children_codes(samples[i], celldist, [this] (cell *c) { return sample_id(c); }));
int d = celldist(c);
for(int k=0; k<c->type; k++) {
cell *c1 = c->cmove(k);
if(celldist(c1) != d+1) continue;
cell *c2 = c->cmove((k+1) % c->type);
if(celldist(c2) != d+1) continue;
children.back().push_back(sample_id(c1));
}
}
N = isize(samples); N = isize(samples);
rootid = 0; rootid = 0;
diskid = N; diskid = N;
@ -138,7 +147,7 @@ void expansion_analyzer::reduce_grouping() {
childgroups[i].second = i; childgroups[i].second = i;
for(int j: children[i]) for(int j: children[i])
childgroups[i].first.push_back(grouping[j]); childgroups[i].first.push_back(grouping[j]);
sort(childgroups[i].first.begin(), childgroups[i].first.end()); // sort(childgroups[i].first.begin(), childgroups[i].first.end());
} }
sort(childgroups.begin(), childgroups.end()); sort(childgroups.begin(), childgroups.end());
int newgroups = 0; int newgroups = 0;
@ -301,28 +310,8 @@ template<class T> int type_in(expansion_analyzer& ea, cell *c, const T& f) {
int ret = ea.N++; int ret = ea.N++;
ea.codeid[res] = ret; ea.codeid[res] = ret;
vector<int> rec(MAX_EDGE, -1);
ea.children.emplace_back(); ea.children.emplace_back();
for(int k=0; k<c->type; k++) { ea.children[ret] = get_children_codes(c, f, [&ea, &f] (cell *c1) { return type_in(ea, c1, f); });
cell *c1 = c->cmove(k);
if(f(c1) != d+1) continue;
cell *c2 = c->cmove((k+1) % c->type);
if(f(c2) != d+1) continue;
auto ti = rec[k] = type_in(ea, c1, f);
// note: ea.children[ret].push_back(type_in(...)) would not work because of invalidation
ea.children[ret].push_back(ti);
}
/*
printf("extra type created: [%d, d=%d]", ret, d); for(auto i: ea.children[ret]) printf(" %d", i); printf("\n");
printf(" list:");
for(int k=0; k<c->type; k++) {
cell *c1 = c->cmove(k);
printf(" %d/%d/%d", k, rec[k], f(c1) - d);
}
printf("\n");
*/
return ret; return ret;
} }