TilePosition

class BWAPI.TilePosition

Indicates a position that is 32x32 pixels in size. Typically used for building placement.

See also

BWAPI.TilePositions, BWAPI.TILEPOSITION_SCALE

Constructors

TilePosition()

Default constructor.

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

A constructor to convert a WalkPosition to a TilePosition.

Parameters:walkPos (BWAPI.WalkPosition) – The position to be converted.
TilePosition(pos)

A constructor to convert a Position to a TilePosition.

Parameters:pos (BWAPI.Position) – 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() → TilePosition

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.TilePosition

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.TilePosition) – 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.TilePosition) – 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) → TilePosition

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.TilePosition

See also

setMin()

setMax(max) → TilePosition

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.TilePosition) – Point containing the maximum x and y values.
Returns:Itself.
Return type:BWAPI.TilePosition
setMin(max_x, max_y) → TilePosition

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.TilePosition

See also

setMax()

setMin(max) → TilePosition

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.TilePosition) – Point containing the minimum x and y values.
Returns:Itself.
Return type:BWAPI.TilePosition