mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-24 15:00:14 +00:00
reg3:: added celldistance_534
This commit is contained in:
parent
581d26ef45
commit
8d5a358b38
45
reg3.cpp
45
reg3.cpp
@ -1254,10 +1254,55 @@ EX int quotient_count() {
|
||||
return isize(regmap()->quotient_map->allh);
|
||||
}
|
||||
|
||||
/** This is a generalization of hyperbolic_celldistance in expansion.cpp to three dimensions.
|
||||
It still assumes that there are at most 4 cells around every edge, and that distances from
|
||||
the origin are known, so it works only in {5,3,4}.
|
||||
*/
|
||||
|
||||
int celldistance_534(cell *c1, cell *c2) {
|
||||
int d1 = celldist(c1);
|
||||
int d2 = celldist(c2);
|
||||
|
||||
vector<cell*> s1 = {c1};
|
||||
vector<cell*> s2 = {c2};
|
||||
int best = 99999999;
|
||||
int d0 = 0;
|
||||
|
||||
auto go_nearer = [&] (vector<cell*>& v, int& d) {
|
||||
vector<cell*> w;
|
||||
for(cell *c: v)
|
||||
forCellEx(c1, c)
|
||||
if(celldist(c1) < d)
|
||||
w.push_back(c1);
|
||||
sort(w.begin(), w.end());
|
||||
d--; d0++;
|
||||
auto last = std::unique(w.begin(), w.end());
|
||||
w.erase(last, w.end());
|
||||
v = w;
|
||||
};
|
||||
|
||||
while(d0 < best) {
|
||||
for(cell *a1: s1) for(cell *a2: s2) {
|
||||
if(a1 == a2) best = min(best, d0);
|
||||
else if(isNeighbor(a1, a2)) best = min(best, d0+1);
|
||||
}
|
||||
|
||||
if(d1 == 0 && d2 == 0) break;
|
||||
|
||||
if(d1 >= d2) go_nearer(s1, d1);
|
||||
if(d1 < d2) go_nearer(s2, d2);
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
EX int celldistance(cell *c1, cell *c2) {
|
||||
if(c1 == c2) return 0;
|
||||
if(c1 == currentmap->gamestart()) return c2->master->distance;
|
||||
if(c2 == currentmap->gamestart()) return c1->master->distance;
|
||||
|
||||
if(geometry == gSpace534) return celldistance_534(c1, c2);
|
||||
|
||||
auto r = regmap();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user