From 0435c490c329a1a3b638296c4f911477f2371d3f Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 23 Sep 2018 02:24:18 +0200 Subject: [PATCH] expansion analyzer now uses the correct order of children --- expansion.cpp | 57 +++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/expansion.cpp b/expansion.cpp index aa1e6238..6e0e692b 100644 --- a/expansion.cpp +++ b/expansion.cpp @@ -100,24 +100,33 @@ int expansion_analyzer::sample_id(cell *c) { samples.push_back(c); return cit; } + +template vector get_children_codes(cell *c, const T& distfun, const U& typefun) { + vector 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; ktype; 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() { samples.clear(); codeid.clear(); children.clear(); sample_id(currentmap->gamestart()); - for(int i=0; itype; 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)); - } - } + // queue for, do not change to range-based for + for(int i=0; i int type_in(expansion_analyzer& ea, cell *c, const T& f) { int ret = ea.N++; ea.codeid[res] = ret; - vector rec(MAX_EDGE, -1); - ea.children.emplace_back(); - for(int k=0; ktype; k++) { - 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; ktype; k++) { - cell *c1 = c->cmove(k); - printf(" %d/%d/%d", k, rec[k], f(c1) - d); - } - printf("\n"); - */ + ea.children[ret] = get_children_codes(c, f, [&ea, &f] (cell *c1) { return type_in(ea, c1, f); }); return ret; }