Typical Usage¶
from ares import AresBot
from ares.behaviors.macro.mining import Mining
class MyBot(AresBot):
async def on_step(self, iteration: int) -> None:
await super(MyBot, self).on_step(iteration)
self.register_behavior(Mining())
MacroPlan
dataclass
¶
Bases: Behavior
Execute macro behaviors sequentially.
Idea here is to put macro behaviors in priority order.
Example:
from ares.behaviors.macro import MacroPlan
from ares.behaviors.macro import (
AutoSupply,
SpawnController
)
# initiate a new MacroPlan
macro_plan: MacroPlan = MacroPlan()
# then add behaviors in the order they should be executed
macro_plan.add(AutoSupply())
macro.plan.add(SpawnController(army_composition_dict=self.army_comp))
# register the macro plan
self.ai.register_behavior(macro_plan)
Attributes:
| Name | Type | Description |
|---|---|---|
macros |
list[Behavior]
|
A list of behaviors that should be executed. Defaults to an empty list. |
AddonSwap
dataclass
¶
Bases: MacroBehavior
For Terran only, swap 3x3 structures. Pass in two structures and they will swap positions.
TODO: Extend this to support an exact swap, ie. swap techlab and reactor
Example:
from ares.behaviors.macro import AddonSwap
# factory will find a reactor to fly to, any existing
# structure will fly to the factory's starting position
self.register_behavior(
AddonSwap(factory, UnitTypeId.REACTOR)
)
Attributes:
| Name | Type | Description |
|---|---|---|
structure_needing_addon |
Unit | UnitTypeId
|
The structure type we want the addon for. |
addon_required |
UnitTypeId
|
Type of addon required. |
AutoSupply
dataclass
¶
Bases: MacroBehavior
Automatically build supply, works for all races.
Example:
Attributes:
| Name | Type | Description |
|---|---|---|
base_location |
Point2
|
The base location where supply should be built. |
return_true_if_supply_required |
bool
|
If supply can't be afforded but is
required, return true. Useful for creating a |
closest_to |
Point2 | None
|
Find available supply placement closest to this location. Only applicable to Terran or Protoss. |
BuildStructure
dataclass
¶
BuildStructure(base_location, structure_id, max_on_route=1, first_pylon=False, static_defence=False, wall=False, closest_to=None, to_count=0, to_count_per_base=0, tech_progress_check=0.85, supply_depot=False, missile_turret=False, sensor_tower=False, upgrade_structure=False, production=True, bunker=False, reaper_wall=False, find_alternative=True)
Bases: MacroBehavior
Handy convenience building structure behavior.
Especially combined with Mining and ares built in placement solver.
Finds an ideal mining worker, and an available precalculated placement.
Then removes worker from mining records and provides a new role.
Example:
from ares.behaviors.macro import BuildStructure
# finds available barracks location near spawn base location
# assigns a scv and builds a barracks
self.register_behavior(
BuildStructure(
base_location=self.start_location,
structure_id=UnitTypeId.BARRACKS
)
)
Attributes:
| Name | Type | Description |
|---|---|---|
base_location |
Point2
|
The base location to build near. |
structure_id |
UnitTypeId
|
The structure type we want to build. |
max_on_route |
int
|
The max number of workers on route to build this. Defaults to 1. |
first_pylon |
bool
|
Will look for the first pylon in placements dict. Defaults to False. |
static_defence |
bool
|
Will look for static defense in placements dict. Defaults to False. |
wall |
bool
|
Find wall placement if possible. Only the main base is currently supported. Defaults to False. |
closest_to |
Point2 | None
|
Find placement at this base closest to the given point. Optional. |
to_count |
int
|
Prevent going over this amount in total. Defaults to 0, turning this check off. |
to_count_per_base |
int
|
Prevent going over this amount at this base location. Defaults to 0, turning this check off. |
tech_progress_check |
float
|
Check if tech is ready before trying to build. Defaults to 0.85; setting it to 0.0 turns this check off. |
supply_depot |
bool
|
Choose a predefined supply depot location. Defaults to False. |
missile_turret |
bool
|
Choose a predefined missile turret location. Defaults to False. |
sensor_tower |
bool
|
Choose a predefined sensor tower location. Defaults to False. |
upgrade_structure |
bool
|
Choose a predefined upgrade structurer location. Defaults to False. |
production |
bool
|
Choose a predefined production location. Defaults to False. |
bunker |
bool
|
Choose a predefined bunker location. Defaults to False. |
reaper_wall |
bool
|
Choose a predefined reaper wall location. Defaults to False. |
find_alternative |
bool
|
If no placements are available at this base, optionally search nearby bases. Defaults to True. |
BuildWorkers
dataclass
¶
ExpansionController
dataclass
¶
ExpansionController(to_count, can_afford_check=True, check_location_is_safe=True, max_pending=1, prioritize=False)
Bases: MacroBehavior
Manage expanding.
Example:
from ares.behaviors.macro import ExpansionController
self.register_behavior(
ExpansionController(to_count=8, max_pending=2)
)
Attributes:
| Name | Type | Description |
|---|---|---|
to_count |
int
|
The target base count. |
can_afford_check |
bool
|
Check if we can afford expansion. Setting this to False will allow the worker to move to a location ready to build the expansion. Defaults to True. |
check_location_is_safe |
bool
|
Check if we don't knowingly expand at a dangerous location. Defaults to True. |
max_pending |
int
|
Maximum pending townhalls at any time. Defaults to 1. |
prioritize |
bool
|
Will return True for this behavior if we can't afford expansion. Default is False |
GasBuildingController
dataclass
¶
Bases: MacroBehavior
Maintain gas building count. Finds an ideal mining worker, and an available geyser. Then removes worker from mining records and provides a new role.
Example:
from ares.behaviors.macro import GasBuildingController
self.register_behavior(
GasBuildingController(to_count=len(self.townhalls)*2)
)
Attributes:
| Name | Type | Description |
|---|---|---|
to_count |
int
|
How many gas buildings would we like? |
max_pending |
int
|
How many gas buildings can be pending at any time? Defaults to 1. |
closest_to |
Point2 | None
|
Find available geyser closest to this location.
Optional, defaults to |
Mining
dataclass
¶
Mining(flee_at_health_perc=0.5, keep_safe=True, long_distance_mine=True, mineral_boost=True, vespene_boost=True, workers_per_gas=3, self_defence_active=True, safe_long_distance_mineral_fields=None, locked_action_tags=dict(), weight_safety_limit=12.0)
Bases: MacroBehavior
Handle worker mining control.
Note: Could technically be CombatBehavior, but is treated here as a
MacroBehavior since many tasks are carried out.
Example:
Attributes:
| Name | Type | Description |
|---|---|---|
flee_at_health_perc |
float
|
If worker is in danger, at what health percentage should it flee? Defaults to 0.5. |
keep_safe |
bool
|
Should workers flee if they are in danger? Defaults to True. |
long_distance_mine |
bool
|
Can the worker long distance mine if it has nothing to do? Defaults to True. |
mineral_boost |
bool
|
Turn mineral boosting on or off. Defaults to True. |
vespene_boost |
bool
|
Turn vespene boosting on or off (only active when workers_per_gas < 3). Defaults to True. |
workers_per_gas |
int
|
Control how many workers are assigned to each gas. Defaults to 3. |
self_defence_active |
bool
|
If set to True, workers will have some basic defence. Certain workers will attack enemy in range. Defaults to True. |
safe_long_distance_mineral_fields |
Units | None
|
Used internally, set when a worker starts long distance mining. Defaults to None. |
weight_safety_limit |
float
|
Workers will flee if enemy influence is above this number. Defaults to 12.0 |
ProductionController
dataclass
¶
ProductionController(army_composition_dict, base_location, add_production_at_bank=(400, 400), alpha=0.9, unit_pending_progress=0.75, ignore_below_proportion=0.05, should_repower_structures=True, max_production_structures=12)
Bases: MacroBehavior
Handle creating extra production facilities based on an army composition dictionary. This dictionary should be structured the same as the one passed into SpawnController
Terran / Protoss only
Example bot code:
from ares.behaviors.production_controller import ProductionController
# Note: This does not try to build production facilities and
# will ignore units that are impossible to currently spawn.
army_composition: dict[UnitTypeId: {float, bool}] = {
UnitTypeId.MARINE: {"proportion": 0.6, "priority": 2}, # lowest priority
UnitTypeId.MEDIVAC: {"proportion": 0.25, "priority": 1},
UnitTypeId.SIEGETANK: {"proportion": 0.15, "priority": 0}, # highest priority
}
# where `self` is an `AresBot` object
self.register_behavior(ProductionController(
army_composition, self.ai.start_location))
Attributes:
| Name | Type | Description |
|---|---|---|
army_composition_dict |
dict[UnitTypeId, dict[str, float | int]]
|
A dictionary detailing how an army composition should be made up. The proportional values should all add up to 1.0, with a priority integer for unit emphasis. |
base_location |
Point2
|
The location where production should be built. |
add_production_at_bank |
tuple[int, int]
|
When the bank reaches this size, calculate what
extra production would be useful. |
alpha |
float
|
Controls how much production to add when the bank is higher than
|
unit_pending_progress |
float
|
Check for production structures almost ready.
For example, a marine might almost be ready, meaning we don't need to
add extra production just yet. Defaults to |
ignore_below_proportion |
float
|
If we don't want many of a unit, there's no point
adding production. Checks if it's possible to build a unit first.
Defaults to |
should_repower_structures |
bool
|
Search for unpowered structures and build a
new pylon if needed. Defaults to |
max_production_structures |
int
|
Stop adding production at this number Defaults to 12 |
RestorePower
dataclass
¶
Bases: MacroBehavior
Restore power for protoss structures.
Note: ProductionController is set to call this automatically
configured via should_repower_structures parameter.
Though this behavior may also be used separately.
Example:
SpawnController
dataclass
¶
SpawnController(army_composition_dict, freeflow_mode=False, ignore_proportions_below_unit_count=0, over_produce_on_low_tech=True, ignored_build_from_tags=set(), maximum=20, spawn_target=None, __build_dict=dict(), __excluded_structure_tags=set(), __supply_available=0.0)
Bases: MacroBehavior
Handle spawning army compositions.
Example bot code:
from ares.behaviors.spawn_controller import SpawnController
# Note: This does not try to build production facilities and
# will ignore units that are impossible to currently spawn.
army_composition: dict[UnitTypeId: {float, bool}] = {
UnitTypeId.MARINE: {"proportion": 0.6, "priority": 2}, # lowest priority
UnitTypeId.MEDIVAC: {"proportion": 0.25, "priority": 1},
UnitTypeId.SIEGETANK: {"proportion": 0.15, "priority": 0}, # highest priority
}
# where `self` is an `AresBot` object
self.register_behavior(SpawnController(army_composition))
Attributes:
| Name | Type | Description |
|---|---|---|
army_composition_dict |
dict[UnitTypeId, dict[str, float | int]]
|
A dictionary detailing how an army composition should be made up. The proportional values should all add up to 1.0, with a priority integer for unit emphasis. |
freeflow_mode |
bool
|
If set to True, army composition proportions are ignored,
and resources will be spent freely.
Defaults to |
ignore_proportions_below_unit_count |
int
|
In early game, units affect the
army proportions significantly. This allows some units to be freely
built before proportions are respected. Defaults to |
over_produce_on_low_tech |
bool
|
If only one tech is available for a unit,
this allows that unit to be constantly produced.
Defaults to |
ignored_build_from_tags |
set[int]
|
A set of tags to prevent the spawn controller from morphing from these tags. Example: Prevent selecting barracks that need to build an addon. |
maximum |
int
|
The maximum number of a unit type that can be produced
in a single step. Defaults to |
spawn_target |
Point2 | None
|
A location to prioritize spawning units near.
Defaults to |
TechUp
dataclass
¶
Bases: MacroBehavior
Automatically tech up so desired upgrade/unit can be built.
Example:
from ares.behaviors.macro import TechUp
from sc2.ids.upgrade_id import UpgradeId
self.register_behavior(
TechUp(UpgradeId.BANSHEECLOAK, base_location=self.start_location)
)
Attributes:
| Name | Type | Description |
|---|---|---|
desired_tech |
UpgradeId | UnitTypeId
|
The desired upgrade or unit type. |
base_location |
Point2
|
The main building location to make tech. |
ignore_existing_techlabs |
bool
|
If set to |
UpgradeController
dataclass
¶
Bases: MacroBehavior
Research upgrades, if the upgrade is not currently researchable this behavior will automatically make the tech buildings required.
Examples
from ares.behaviors.macro import UpgradeController
from sc2.ids.upgrade_id import UpgradeId
desired_upgrades: list[UpgradeId] = [
UpgradeId.TERRANINFANTRYWEAPONSLEVEL1,
UpgradeId.TERRANINFANTRYWEAPONSLEVEL2,
UpgradeId.BANSHEECLOAK,
UpgradeId.PERSONALCLOAKING
]
self.register_behavior(
UpgradeController(desired_upgrades, base_location=self.start_location)
)
Attributes:
| Name | Type | Description |
|---|---|---|
upgrade_list |
list[UpgradeId]
|
List of desired upgrades. |
base_location |
Point2
|
Location to build upgrade buildings. |
auto_tech_up_enabled |
bool
|
bool |
prioritize |
bool
|
If True and there is an Upgrade ready to go, but we can't afford it yet, this behavior will return True. This is useful in a MacroPlan as it will prevent other spending actions occurring. Default is False |