mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-20 23:50:27 +00:00
3d:: binary:: celldistance [untested]
This commit is contained in:
parent
170648a367
commit
a6094f7b0c
@ -343,12 +343,30 @@ auto bt_config = addHook(hooks_args, 0, [] () {
|
||||
});
|
||||
#endif
|
||||
|
||||
int celldistance3(cell *c1, cell *c2) {
|
||||
int celldistance3(cell *c1, cell *c2) { // [untested]
|
||||
int steps = 0;
|
||||
int d1 = celldistAlt(c1);
|
||||
int d2 = celldistAlt(c2);
|
||||
while(d1 > d2) c1 = c1->cmove(8), steps++, d1--;
|
||||
while(d2 > d1) c2 = c2->cmove(8), steps++, d2--;
|
||||
vector<int> dx, dy;
|
||||
while(c1 != c2) {
|
||||
int d1 = celldistAlt(c1), d2 = celldistAlt(c2);
|
||||
if(d1 >= d2) c1 = c1->cmove(8), steps++;
|
||||
if(d2 >= d1) c2 = c2->cmove(8), steps++;
|
||||
dx.push_back((c1->c.spin(8) & 1) - (c2->c.spin(8) & 1));
|
||||
dy.push_back((c1->c.spin(8) >> 1) - (c2->c.spin(8) >> 1));
|
||||
c1 = c1->cmove(8);
|
||||
c2 = c2->cmove(8);
|
||||
steps += 2;
|
||||
}
|
||||
int xsteps = steps, sx = 0, sy = 0;
|
||||
while(isize(dx)) {
|
||||
xsteps -= 2;
|
||||
sx *= 2;
|
||||
sy *= 2;
|
||||
sx += dx.back(); sy += dy.back();
|
||||
dx.pop_back(); dy.pop_back();
|
||||
int ysteps = xsteps + abs(sx) + abs(sy);
|
||||
if(ysteps < steps) steps = ysteps;
|
||||
if(sx >= 8 || sx <= -8 || sy >= 8 || sy <= -8) break;
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
2
cell.cpp
2
cell.cpp
@ -805,7 +805,7 @@ int heptdistance(cell *c1, cell *c2) {
|
||||
#if CAP_CRYSTAL
|
||||
if(geometry == gCrystal) return crystal::space_distance(c1, c2);
|
||||
#endif
|
||||
if(!hyperbolic || quotient) return celldistance(c1, c2);
|
||||
if(!hyperbolic || quotient || DIM == 3) return celldistance(c1, c2);
|
||||
else return heptdistance(c1->master, c2->master);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user