Regionset¶
-
class
BWAPI.Regionset¶ A container that holds a set of
Regionobjects.Constructors
-
Regionset()¶ Default constructor.
-
Regionset(set) Copy constructor.
Parameters: set (BWAPI.Regionset) – The Regionset to copy.
-
Regionset(tbl) Constructor to convert a Lua table to a set. Any values in the table that are of type
Regionare added to the set.Parameters: tbl (table) – A table containing Regionobjects.
Member Functions
-
getCenter() → Position¶ Retrieves the center of the region.
This position is used as the node of the region.
Returns: A Position indicating the center location of the Regionset, in pixels.Return type: BWAPI.Position
-
getUnits([pred = nil]) → Unitset¶ Retrieves a
Unitsetcontaining all the units that are in this region.Also has the ability to filter the units before the creation of the
Unitset.Parameters: pred (function) – (optional) A predicate function that takes a Unitand returnstruefor units that satisfy the intended filter andfalseotherwise (can be a BWAPI.Filter unary filter). Defaults tonil, which means no filter.Returns: A Unitsetcontaining all units in this region that have met the requirements ofpred.Return type: BWAPI.Unitset
-
iterator() → iteratorFunction¶ Returns an iterator function intended to be used in
forloops (e.g.for item in set:iterator() do).Returns: An iterator function that will return the next value in the set with each successive call. Return type: function
-
asTable() → table¶ Returns the values of the set as an array-like Lua table.
Note
The ordering of the returned table is arbitrary (due to sets being unordered in the C++ implementation).
Returns: An array-like Lua table containing each value in the set. Return type: table
-
count(val) → int¶ Searches the set for elements with a value of
valand returns the number of elements found. Because sets do not allow for duplicate values, this means that the function will return either1or0. Because of this, it’s recommended to usecontains()instead.See also
-
contains(val) → boolean¶ Checks if this set contains a specific value.
Returns: trueif the set contains the specified value, orfalseotherwise.Return type: boolean
-
size() → int¶ Returns: The number of values in the set. Return type: int Note
set:size()is exactly equivalent to#set
-
empty() → boolean¶ Returns: trueif the set is empty (size() == 0), orfalseotherwise.Return type: boolean
-
insert(val)¶ Inserts the value into the set.
Note
Sets cannot contain duplicate values. If the value already exists in the set, the set will not be modified.
-
erase(val) → numElementsErased¶ Removes
valfrom the set if it exists.Returns: The number of elements removed. Because sets do not allow for duplicate values, this means that the function will return either 1or0.Return type: int
-
clear()¶ Removes all elements from the set, leaving it with a size of 0.
-
eraseIf(pred)¶ Iterates the set and erases each element x where pred(x) returns true. The set is modified in place.
Parameters: pred (function) – A predicate function that takes a value and returns truefor values that should be erased andfalseotherwise.
-
filter(pred)¶ Iterates the set and erases each element x where pred(x) returns false. The set is modified in place.
Parameters: pred (function) – A predicate function that takes a value and returns truefor values that should be kept andfalsefor elements that should be erased.
-