mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-01-20 06:03:01 +00:00
rulegen:: faster shortcuts
This commit is contained in:
parent
68949a4ea4
commit
0f0aef8dd9
32
rulegen.cpp
32
rulegen.cpp
@ -263,14 +263,16 @@ int solid_errors;
|
|||||||
|
|
||||||
int get_parent_dir(tcell *c);
|
int get_parent_dir(tcell *c);
|
||||||
|
|
||||||
|
#if HDR
|
||||||
struct shortcut {
|
struct shortcut {
|
||||||
vector<int> pre;
|
vector<int> pre;
|
||||||
vector<int> post;
|
vector<int> post;
|
||||||
tcell *sample;
|
tcell *sample;
|
||||||
int delta;
|
int delta;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
map<int, vector<shortcut> > shortcuts;
|
map<int, vector<unique_ptr<shortcut>> > shortcuts;
|
||||||
|
|
||||||
vector<int> root_path(twalker cw) {
|
vector<int> root_path(twalker cw) {
|
||||||
cw += wstep;
|
cw += wstep;
|
||||||
@ -355,18 +357,24 @@ void check_solid(tcell *c, int d) {
|
|||||||
|
|
||||||
int delta = at1.to_spin(walkers2.back().spin);
|
int delta = at1.to_spin(walkers2.back().spin);
|
||||||
|
|
||||||
for(auto s: shortcuts[c->id]) if(s.pre == pre && s.post == post) return;
|
for(auto& s: shortcuts[c->id]) if(s->pre == pre && s->post == post) return;
|
||||||
|
|
||||||
if(debugflags & DF_GEOM)
|
if(debugflags & DF_GEOM)
|
||||||
println(hlog, "new shortcut found, pre = ", pre, " post = ", post, " pre reaches ", at1, " post reaches ", walkers2.back(), " of type ", at1.at->id, " sample = ", c);
|
println(hlog, "new shortcut found, pre = ", pre, " post = ", post, " pre reaches ", at1, " post reaches ", walkers2.back(), " of type ", at1.at->id, " sample = ", c);
|
||||||
|
|
||||||
shortcuts[c->id].emplace_back(shortcut{pre, post, c, delta});
|
shortcuts[c->id].emplace_back(unique_ptr<shortcut> (new shortcut));
|
||||||
|
auto& sh = shortcuts[c->id].back();
|
||||||
|
sh->pre = pre;
|
||||||
|
sh->post = post;
|
||||||
|
sh->sample = c;
|
||||||
|
sh->delta = delta;
|
||||||
|
auto& sh1 = *sh;
|
||||||
|
|
||||||
if(debugflags & DF_GEOM) println(hlog, "exhaustive search:");
|
if(debugflags & DF_GEOM) println(hlog, "exhaustive search:");
|
||||||
indenter ind(2);
|
indenter ind(2);
|
||||||
tcell* c1 = first_tcell;
|
tcell* c1 = first_tcell;
|
||||||
while(c1) {
|
while(c1) {
|
||||||
if(c1->id == c->id) look_for_shortcuts(c1);
|
if(c1->id == c->id) look_for_shortcuts(c1, sh1);
|
||||||
c1 = c1->next;
|
c1 = c1->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,9 +452,8 @@ void be_solid(tcell *c) {
|
|||||||
c->is_solid = true;
|
c->is_solid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EX void look_for_shortcuts(tcell *c) {
|
EX void look_for_shortcuts(tcell *c, shortcut& sh) {
|
||||||
if(c->dist > 0) for(int i=0; i<isize(shortcuts[c->id]); i++) {
|
if(c->dist <= 0) return;
|
||||||
auto sh = shortcuts[c->id][i];
|
|
||||||
if(1) {
|
if(1) {
|
||||||
twalker tw0(c, 0);
|
twalker tw0(c, 0);
|
||||||
twalker tw(c, 0);
|
twalker tw(c, 0);
|
||||||
@ -458,8 +465,8 @@ EX void look_for_shortcuts(tcell *c) {
|
|||||||
for(auto& v: sh.pre) {
|
for(auto& v: sh.pre) {
|
||||||
opath.push_back(tw.at);
|
opath.push_back(tw.at);
|
||||||
tw += v;
|
tw += v;
|
||||||
if(!tw.peek()) goto next_shortcut;
|
if(!tw.peek()) return;
|
||||||
if(tw.peek()->dist != tw.at->dist-1) goto next_shortcut;
|
if(tw.peek()->dist != tw.at->dist-1) return;
|
||||||
ufind(tw);
|
ufind(tw);
|
||||||
tw += wstep;
|
tw += wstep;
|
||||||
}
|
}
|
||||||
@ -486,9 +493,12 @@ EX void look_for_shortcuts(tcell *c) {
|
|||||||
|
|
||||||
ufindc(c);
|
ufindc(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
next_shortcut: ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EX void look_for_shortcuts(tcell *c) {
|
||||||
|
if(c->dist > 0)
|
||||||
|
for(int i=0; i<isize(shortcuts[c->id]); i++)
|
||||||
|
look_for_shortcuts(c, *shortcuts[c->id][i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** which neighbor will become the parent of c */
|
/** which neighbor will become the parent of c */
|
||||||
|
Loading…
Reference in New Issue
Block a user