1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-03 06:54:08 +00:00

rulegen:: optimized smart shortcuts

This commit is contained in:
Zeno Rogue 2021-12-25 21:32:08 +01:00
parent d74edf07db
commit 71fd8eccf5

View File

@ -433,6 +433,7 @@ struct shortcut {
vector<int> post; vector<int> post;
tcell *sample; tcell *sample;
int delta; int delta;
int last_dir;
}; };
#endif #endif
@ -490,6 +491,7 @@ EX void shortcut_found(tcell *c, tcell *alt, vector<twalker> &walkers, vector<tw
sh->post = post; sh->post = post;
sh->sample = c; sh->sample = c;
sh->delta = delta; sh->delta = delta;
sh->last_dir = c->any_nearer;
auto& sh1 = *sh; auto& sh1 = *sh;
if(debugflags & DF_GEOM) println(hlog, "exhaustive search:"); if(debugflags & DF_GEOM) println(hlog, "exhaustive search:");
@ -719,25 +721,28 @@ EX void look_for_shortcuts(tcell *c, shortcut& sh) {
calc_distances(tw.at); calc_distances(tw.at);
} }
int expected_dist = c->dist - isize(sh.pre); int more_steps = isize(sh.post);
int d = arb::current.shapes[c->id].cycle_length;
if(sh.last_dir % d < c->any_nearer % d) more_steps--;
tw += sh.delta; tw += sh.delta;
for(auto it = sh.post.rbegin(); it != sh.post.rend(); it++) { for(auto it = sh.post.rbegin(); it != sh.post.rend(); it++) {
auto& v = *it; auto& v = *it;
if(tw.at->dist > expected_dist && !tw.peek() && !(flags & w_less_smart_advance)) return;
ufind(tw); ufind(tw);
if(!tw.peek() && tw.at->dist + more_steps > c->dist && !(flags & w_less_smart_advance)) return;
tw += wstep; tw += wstep;
calc_distances(tw.at); calc_distances(tw.at);
expected_dist++; more_steps--;
tw -= v; tw -= v;
} }
process_fix_queue();
if(tw.at->dist < c->dist) { if(tw.at->dist < c->dist) {
if(debugflags & DF_GEOM) if(debugflags & DF_GEOM)
println(hlog, "smart shortcut updated ", c->dist, " to ", tw.at->dist); println(hlog, "smart shortcut updated ", c->dist, " to ", tw.at->dist);
push_unify(tw, tw0);
} }
push_unify(tw, tw0);
process_fix_queue(); process_fix_queue();
} }