Position

class BWAPI.Position

Indicates a position that is 1x1 pixel in size. This is the most precise position type.

See also

BWAPI.Positions, BWAPI.POSITION_SCALE

Constructors

Position()

Default constructor.

Position(x, y)
Parameters:
  • x (int) – The x coordinate.
  • y (int) – The y coordinate.
Position(walkPos)

A constructor to convert a WalkPosition to a Position.

Parameters:walkPos (BWAPI.WalkPosition) – The position to be converted.
Position(tilePos)

A constructor to convert a TilePosition to a Position.

Parameters:tilePos (BWAPI.TilePosition) – The position to be converted.

Member Variables

x

(integer) The x coordinate.

y

(integer) The y coordinate.

Member Functions

isValid() → boolean

Checks if this point is within the game’s map bounds.

Returns:true If it is a valid position and on the map/playing field, or false If this is not a valid position.
Return type:boolean

Note

If the Broodwar pointer is not initialized, this function will check validity against the largest (256x256) map size.

makeValid() → Position

Checks if this point is within the game’s map bounds, if not, then it will set the x and y values to be within map bounds. For example, if x is less than 0, then x is set to 0.

Returns:Itself
Return type:BWAPI.Position

Note

If the Broodwar pointer is not initialized, this function will check validity against the largest (256x256) map size.

See also

isValid()

getDistance(pos) → double

Gets an accurate distance measurement from this point to the given position.

Note

This is a direct distance calculation that ignores all collision.

Note

This function impedes performance. In most cases you should use getApproxDistance().

Parameters:pos (BWAPI.Position) – The target position to get the distance to.
Returns:A double representing the distance between this point and position.
Return type:double
getLength() → double

Gets the length of this point from the top left corner of the map.

Note

This function impedes performance. In most cases you should use getApproxDistance().

Returns:A double representing the length of this point from (0,0).
Return type:double
getApproxDistance(pos) → int

Retrieves the approximate distance using an algorithm from Starcraft: Broodwar.

Note

This is a direct distance calculation that ignores all collision.

Note

This function is desired because it uses the same “imperfect” algorithm used in Broodwar, so that calculations will be consistent with the game. It is also optimized for performance.

Parameters:pos (BWAPI.Position) – The target position to get the distance to.
Returns:A integer representing the distance between this point and position.
Return type:int

See also

getDistance()

setMax(max_x, max_y) → Position

Sets the maximum x and y values.

If the current x or y values exceed the given maximum, then values are set to the maximum.

Parameters:
  • max_x (int) – Maximum x value.
  • max_y (int) – Maximum y value.
Returns:

Itself.

Return type:

BWAPI.Position

See also

setMin()

setMax(max) → Position

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:max (BWAPI.Position) – Point containing the maximum x and y values.
Returns:Itself.
Return type:BWAPI.Position
setMin(max_x, max_y) → Position

Sets the minimum x and y values.

If the current x or y values are below the given minimum, then values are set to the minimum.

Parameters:
  • max_x (int) – Minimum x value.
  • max_y (int) – Minimum y value.
Returns:

Itself.

Return type:

BWAPI.Position

See also

setMax()

setMin(max) → Position

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:max (BWAPI.Position) – Point containing the minimum x and y values.
Returns:Itself.
Return type:BWAPI.Position