mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-21 08:00:25 +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
|
#endif
|
||||||
|
|
||||||
int celldistance3(cell *c1, cell *c2) {
|
int celldistance3(cell *c1, cell *c2) { // [untested]
|
||||||
int steps = 0;
|
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) {
|
while(c1 != c2) {
|
||||||
int d1 = celldistAlt(c1), d2 = celldistAlt(c2);
|
dx.push_back((c1->c.spin(8) & 1) - (c2->c.spin(8) & 1));
|
||||||
if(d1 >= d2) c1 = c1->cmove(8), steps++;
|
dy.push_back((c1->c.spin(8) >> 1) - (c2->c.spin(8) >> 1));
|
||||||
if(d2 >= d1) c2 = c2->cmove(8), steps++;
|
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;
|
return steps;
|
||||||
}
|
}
|
||||||
|
2
cell.cpp
2
cell.cpp
@ -805,7 +805,7 @@ int heptdistance(cell *c1, cell *c2) {
|
|||||||
#if CAP_CRYSTAL
|
#if CAP_CRYSTAL
|
||||||
if(geometry == gCrystal) return crystal::space_distance(c1, c2);
|
if(geometry == gCrystal) return crystal::space_distance(c1, c2);
|
||||||
#endif
|
#endif
|
||||||
if(!hyperbolic || quotient) return celldistance(c1, c2);
|
if(!hyperbolic || quotient || DIM == 3) return celldistance(c1, c2);
|
||||||
else return heptdistance(c1->master, c2->master);
|
else return heptdistance(c1->master, c2->master);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user