Skip to content

Commit 1cdb420

Browse files
committed
Change distance calculations to conform to OpenBW (@N00byEdge)
1 parent f5e5a1e commit 1cdb420

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/main/java/bwapi/Position.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public Position(final int x, final int y) {
1818
}
1919

2020
private static int getApproxDistance(final int x1, final int y1, final int x2, final int y2) {
21-
int min = Math.abs(x1 - x2);
22-
int max = Math.abs(y1 - y2);
21+
int max = Math.abs(x1 - x2);
22+
int min = Math.abs(y1 - y2);
2323
if (max < min) {
2424
final int temp = min;
2525
min = max;
2626
max = temp;
2727
}
2828

29-
if (min < (max >> 2)) {
29+
if (min <= (max >> 2)) {
3030
return max;
3131
}
3232

src/main/java/bwapi/Unit.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,19 @@ public int getDistance(final Position target) {
164164
}
165165
/////// Compute distance
166166

167-
// retrieve left/top/right/bottom values for calculations
168-
final int left = target.x - 1;
169-
final int top = target.y - 1;
170-
final int right = target.x + 1;
171-
final int bottom = target.y + 1;
172-
173167
// compute x distance
174-
int xDist = getLeft() - right;
168+
int xDist = getLeft() - target.x;
175169
if (xDist < 0) {
176-
xDist = left - getRight();
170+
xDist = target.x - (getRight() + 1);
177171
if (xDist < 0) {
178172
xDist = 0;
179173
}
180174
}
181175

182176
// compute y distance
183-
int yDist = getTop() - bottom;
177+
int yDist = getTop() - target.y;
184178
if (yDist < 0) {
185-
yDist = top - getBottom();
179+
yDist = target.y - (getBottom() + 1);
186180
if (yDist < 0) {
187181
yDist = 0;
188182
}

0 commit comments

Comments
 (0)