New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BWAPI distance calculations are wrong #817
Comments
How do you know that OpenBW is correct? I'll have to reverse engineer these in BW again to verify. |
@heinermann I don't know that openBW must be correct. My assumption was that BWAPI was effectively derived from openBW as the calculation code in BWAPI felt more thought out. But I can be certain that BWAPI is wrong on the first issue, as the core issue is the math, not the state of openBW. |
BWAPI and OpenBW were separately derived from Broodwar (BWAPI first). Will check them out after work. |
@heinermann I did a in-game test with two siege tanks(size[32,32], range 224). I set them up with center to center difference in positions of [256,88] this results in a edge to edge difference of [224,56]. If the distance function simply returns max then result is 224, else if calculations are performed the result is 228. 224 / 4 == 56 so according to openBW the tanks are in range of each other, and according to BWAPI the tanks are out of range(228 reported in-game by BWAPI). The tanks shot each other from those positions. Verification would be great, but at this point I am pretty sure openBW is correct. |
@heinermann Another slight issue, though this one would be quite difficult to test in-game. While siding with openBW has been pretty reliable so far, if you are still reverse engineering this would be something to check. BWAPI uses |
First, the function for distance from unit to position
int UnitInterface::getDistance(Position target) const
actually calculates the distance between the unit and an area with size[3,3]. Seems to be the result of a copying code from unit to unit distance. According to openBW, the bounding box adds 1 to the right and bottom of a unit. When we substitute a target position for a target unit, it creates an asymmetric relationship in the calculation, thus the current result is incorrect. I propose the following code as a fix.Second, the function for Starcraft distance from position to position
int getApproxDistance(const Point<T,Scale> &position) const
has a minor difference in conditional logic from openBW.BWAPI:
openBW:
When comparing note that
x
wasmax
in openBW; the reversal in BWAPI is irrelevant because of the swap. The last conditional of each function is where the problem occurs, but let me explain why.The BWAPI version returns when true, otherwise it calculates.
The openBW version calculates when true, otherwise it returns.
Thus the conditional has been negated, between versions. Here are the steps to convert the openBW conditional to the proper BWAPI conditional.( ! at start represents the negation between versions)
!
if ( x / 4 < y)
if ( x / 4 >= y)
if ( max / 4 >= min)
if ( (max >> 2) >= min)
if ( min <= (max >> 2) )
Current BWAPI conditional:
if ( min < (max >> 2) )
It has
<
rather than the expected<=
. The impact of fixing should be about a 1.85% decrease in range for==
cases.The text was updated successfully, but these errors were encountered: