google-code-export / bwapi

Automatically exported from code.google.com/p/bwapi
0 stars 0 forks source link

Correction to GetDistance #169

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

e.g:
1. Place 2 Hydras (115px,117 px) away from each other
2. getDistance(unit* target) will calculate 134,35 px distance, Hydra-
maxrange is 128px
3. Hydra attacks nontheless

What is the expected output? What do you see instead?
expected: not attacking, instead: attacking :)

What version of the product are you using? On what operating system?
BWAPI 2.4, WinXP

Original issue reported on code.google.com by st.ba...@gmail.com on 16 Dec 2009 at 5:51

GoogleCodeExporter commented 9 years ago
I don't understand, what is the exact distance they are apart? 115? 117? 134? 
35?

Original comment by AHeinerm on 17 Dec 2009 at 1:45

GoogleCodeExporter commented 9 years ago

Original comment by AHeinerm on 17 Dec 2009 at 1:45

GoogleCodeExporter commented 9 years ago
sorry:
delta x= 115 px (difference of x-coordinate)
delta y= 117 px (difference of y-coordinate)
results in a distance (calculated by getDistance(unit* target) of 134.35 px

according to the unit->getType().groundWeapon()->maxRange(); the attack range 
of the 
hydra is 128 px, so they are standing 6.25 pixels to far away form each other 
to 
attack - in theory. In game they just attack (without moving closer).

hope that clarifies my previous post, but I'm not really sure if this "bug" is 
related to BWAPI. It just seems, that the game itself calculates the "is in 
range to 
attack" differently (maybe not from edge to edge)

Original comment by st.ba...@gmail.com on 17 Dec 2009 at 2:15

GoogleCodeExporter commented 9 years ago
maybe a is less than 1 at distance = sqrt(x^2 + (a*y)^2)
would make sence since it's kind of a perspective view

Original comment by goo...@teabix.com on 17 Dec 2009 at 3:47

GoogleCodeExporter commented 9 years ago
maybe attack range was rounded down to the nearest multiple of 32.

Original comment by lowerlo...@gmail.com on 17 Dec 2009 at 8:11

GoogleCodeExporter commented 9 years ago
the "round down to the nearest multiple of 32" doesn't really work, because 
with 
different angles (between the two units) 130px distance is "out of range"

Original comment by st.ba...@gmail.com on 17 Dec 2009 at 8:53

GoogleCodeExporter commented 9 years ago
If a unit attacks another unit, does it attack center-to-center,
center-to-collision-box, ... ?

Original comment by Heckl.Jo...@googlemail.com on 17 Dec 2009 at 3:26

GoogleCodeExporter commented 9 years ago
It's not center-center. try attacking a huge unit like a house from different 
angles, you'll see. But I guess it's not the collision-box either rather a hit-
circle which we didn't document yet.

Original comment by goo...@teabix.com on 17 Dec 2009 at 6:12

GoogleCodeExporter commented 9 years ago
No, it's definitely the unit dimensions.

Original comment by AHeinerm on 20 Dec 2009 at 1:41

GoogleCodeExporter commented 9 years ago
Should return a value probably from the outer dimension of the current unit to 
the
outer dimension of the target unit (don't forget units have square dimensions, 
the
square behaviour is seen on units with sizes like 800x25 ).

Original comment by AHeinerm on 25 Dec 2009 at 3:53

GoogleCodeExporter commented 9 years ago
I made a program that tries all the different attack ranges (posistions) for 
probe, 
zealot and dragoon. 
See the screen shot - its rather surprising - the orange pixels indicates that 
the 
outer unit can attack the unit in the center. I have used the move command and 
the used 
the attack command - if the unit attacked (cooldown > 0) and the unit didnt 
move i 
assume that its in attack range.

Original comment by wizuffeg...@gmail.com on 27 Dec 2009 at 7:51

Attachments:

GoogleCodeExporter commented 9 years ago
Looks like its using an approximate distance function, which is common to avoid
computing the square root. From the screen shots I'm guessing its using 
something
like this:

int dist(int dx, int dy)
{
   int max=abs(dx);
   int min=abs(dy);
   if (min>max)
   {
      temp=min;
      min=max;
      max=temp;
   }
   if (min<max*0.25)
      return max;
   return min*0.4+max*0.9;
}

Original comment by lowerlo...@gmail.com on 29 Dec 2009 at 7:00

GoogleCodeExporter commented 9 years ago
Use DatEdit and make a mod with a unit the size of 256 x 32 or something

Original comment by AHeinerm on 30 Dec 2009 at 1:49

GoogleCodeExporter commented 9 years ago
getDistance now uses the approximate distance function described in my previous
comment, and I think this fixes the problem. I tried these 2 cases for 
hydralisks:

In the first case, dx=116, dy=120, the Unit::getDistance(Unit) function returned
distance=126.6, and the hydras could attack each other without walking closer, 
as
expected since the attack range is 128.

In the second case, dx=134,dy=100, the Unit::getDistance(Unit) function returned
distance=133.8, and the hydra had to walk a few steps to attack the other hydra.

Original comment by lowerlo...@gmail.com on 30 Dec 2009 at 10:27

GoogleCodeExporter commented 9 years ago
also tried dx=131, dy=93, Unit::getDistance(Unit)=128.3, and the hydralisk 
walked a
step before attacking the other hydralisk, as expected.

Original comment by lowerlo...@gmail.com on 30 Dec 2009 at 10:42