From 3051f597466e0a9148d405a164fd275de57cae0f Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 22 Jun 2024 01:39:04 +0200 Subject: [PATCH] simplified and improved the implementation of Goldberg --- goldberg.cpp | 131 +++++++++++++-------------------------------------- 1 file changed, 34 insertions(+), 97 deletions(-) diff --git a/goldberg.cpp b/goldberg.cpp index c652995d..1b6141bd 100644 --- a/goldberg.cpp +++ b/goldberg.cpp @@ -103,6 +103,7 @@ EX namespace gp { signed char mindir; loc start; transmatrix adjm; + signed char rdir1; }; EX int fixg6(int x) { return gmod(x, SG6); } @@ -177,6 +178,7 @@ EX namespace gp { goldberg_map[y][x].cw.at = NULL; goldberg_map[y][x].rdir = -1; goldberg_map[y][x].mindir = 0; + goldberg_map[y][x].rdir1 = -1; } } @@ -459,18 +461,21 @@ EX namespace gp { } // then we set the edges of our big equilateral triangle (in a symmetric way) + // rdir describes a loop on the boundary of that triangle, and rdir1 is the same loop in reverse direction for(int i=0; i= 2 && (S3 == 3 ? rel.first >= 2 - rel.second : true)) { build(start, 0, true); @@ -494,18 +499,10 @@ EX namespace gp { rel.first -= 2; } if(S3 == 4 && rel == loc(1,1)) { - if(param == loc(3,1) || param == loc(5,1)) { - build(start, 1, true); - build(end, 2, false); - rel.first--; - rel.second--; - } - else { - build(start, 0, true); - build(end, 3, false); - rel.first--; - rel.second--; - } + build(start, 1, true); + build(end, 2, false); + rel.first--; + rel.second--; } for(int k=0; k all_locations; + set visited; + auto visit = [&] (loc x) { + if(visited.count(x)) return; + visited.insert(x); + all_locations.push_back(x); + }; + for(int i=0; i= 0) { + if(m.rdir1 > m.rdir && !(j >= m.rdir && j <= m.rdir1)) continue; + if(m.rdir1 < m.rdir && !(j >= m.rdir || j <= m.rdir1)) continue; } - case 1: { - auto at2 = at + eudir(dx+1); - auto& wc2 = get_mapping(at2); - if(wc2.cw.at) { at = at1; continue; } - wc.rdir = (dx+1) % 6; - conn(at, (dx+1) % 6); - conn(at1, (dx+2) % 6); - conn(at2, (dx+0) % 6); - wc1.rdir = -1; - wc2.rdir = dx; - break; - } - default: - println(hlog, "case unhandled ", df); - exit(1); - } - else switch(df) { - case 0: - case 3: - at = at1; - continue; - case 1: - auto at2 = at + eudir(dx+1); - auto& wc2 = get_mapping(at2); - if(wc2.cw.at) { - auto at3 = at1 + eudir(wc1.rdir); - auto& wc3 = get_mapping(at3); - auto at4 = at3 + eudir(wc3.rdir); - if(at4 == at2) { - wc.rdir = (dx+1)%4; - wc1.rdir = -1; - wc3.rdir = -1; - conn(at, (dx+1)%4); - } - else { - at = at1; - } - } - else { - wc.rdir = (dx+1)%4; - wc1.rdir = -1; - wc2.rdir = dx%4; - int bdir = -1; - int bdist = 100; - for(int d=0; d<4; d++) { - auto &wcm = get_mapping(at2 + eudir(d)); - if(wcm.cw.at && length(wcm.start - at2) < bdist) - bdist = length(wcm.start - at2), bdir = d; - } - if(bdir != -1) conn(at2 + eudir(bdir), bdir ^ 2); - conn(at, (dx+1)%4); - conn(at2, dx%4); - - at = param * loc(1,0) + at * loc(0, 1); - } - break; + auto at1 = at + eudir(j); + conn(at, j); + visit(at1); } } - DEBB(DF_GP, ("DONE")) }