Skip to content

Commit

Permalink
Change distance calculations to conform to OpenBW, closes #817
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byEdge authored and heinermann committed Feb 8, 2020
1 parent 09b9828 commit f82d119
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
14 changes: 4 additions & 10 deletions bwapi/Backend/1.16.1/BWAPIBackend_1161/Source/BWAPI/UnitImpl.cpp
Expand Up @@ -1308,26 +1308,20 @@ namespace BWAPI4

/////// Compute distance

// retrieve left/top/right/bottom values for calculations
int left = target.x - 1;
int top = target.y - 1;
int right = target.x + 1;
int bottom = target.y + 1;

// compute x distance
int xDist = this->getLeft() - right;
int xDist = this->getLeft() - target.x;
if (xDist < 0)
{
xDist = left - this->getRight();
xDist = target.x - (this->getRight() + 1);
if (xDist < 0)
xDist = 0;
}

// compute y distance
int yDist = this->getTop() - bottom;
int yDist = this->getTop() - target.y;
if (yDist < 0)
{
yDist = top - this->getBottom();
yDist = target.y - (this->getBottom() + 1);
if (yDist < 0)
yDist = 0;
}
Expand Down
14 changes: 4 additions & 10 deletions bwapi/Frontend/BWAPILIB/Source/Unit.cpp
Expand Up @@ -182,26 +182,20 @@ int Unit::getDistance(Position target) const

/////// Compute distance

// retrieve left/top/right/bottom values for calculations
int left = target.x - 1;
int top = target.y - 1;
int right = target.x + 1;
int bottom = target.y + 1;

// compute x distance
int xDist = this->getLeft() - right;
int xDist = this->getLeft() - target.x;
if (xDist < 0)
{
xDist = left - this->getRight();
xDist = target.x - (this->getRight() + 1);
if (xDist < 0)
xDist = 0;
}

// compute y distance
int yDist = this->getTop() - bottom;
int yDist = this->getTop() - target.y;
if (yDist < 0)
{
yDist = top - this->getBottom();
yDist = target.y - (this->getBottom() + 1);
if (yDist < 0)
yDist = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions bwapi/include/BWAPI/Position.h
Expand Up @@ -275,12 +275,12 @@ namespace BWAPI
/// @see getDistance
int getApproxDistance(const Point<T,Scale> &position) const
{
unsigned int min = abs((int)(this->x - position.x));
unsigned int max = abs((int)(this->y - position.y));
unsigned int max = abs((int)(this->x - position.x));
unsigned int min = abs((int)(this->y - position.y));
if ( max < min )
std::swap(min, max);

if ( min < (max >> 2) )
if ( min <= (max >> 2) )
return max;

unsigned int minCalc = (3*min) >> 3;
Expand Down

0 comments on commit f82d119

Please sign in to comment.