Individual Combat Behaviors
CombatManeuver
dataclass
¶
Bases: Behavior
Execute behaviors sequentially.
Add behaviors
Example:
from ares import AresBot
from ares.behaviors.combat import CombatManeuver
from ares.behaviors.combat.individual import (
DropCargo,
KeepUnitSafe,
PathUnitToTarget,
PickUpCargo,
)
class MyBot(AresBot):
mine_drop_medivac_tag: int
async def on_step(self, iteration):
# Left out here, but `self.mine_drop_medivac_tag`
# bookkeeping is up to the user
medivac: Optional[Unit] = self.unit_tag_dict.get(
self.mine_drop_medivac_tag, None
)
if not medivac:
return
air_grid: np.ndarray = self.mediator.get_air_grid
# initiate a new CombatManeuver
mine_drop: CombatManeuver = CombatManeuver()
# then add behaviors in the order they should be executed
# first priority is picking up units
# (will return False if no cargo and move to next behavior)
mine_drop.add(
PickUpCargo(
unit=medivac,
grid=air_grid,
pickup_targets=mines_to_pickup
)
)
# if there is cargo, path to target and drop them off
if medivac.has_cargo:
# path
mine_drop.add(
PathUnitToTarget(
unit=medivac,
grid=air_grid,
target=self.enemy_start_locations[0],
)
)
# drop off the mines
mine_drop.add(DropCargo(unit=medivac, target=medivac.position))
# no cargo and no units to pick up, stay safe
else:
mine_drop.add(KeepUnitSafe(unit=medivac, grid=air_grid))
# register the mine_drop behavior
self.register_behavior(mine_drop)
Attributes:
| Name | Type | Description |
|---|---|---|
micros |
list[Behavior]
|
A list of behaviors that should be executed. Defaults to an empty list. |
add ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
CombatIndividualBehavior | CombatGroupBehavior | CombatManeuver
|
Add a new combat behavior to the current maneuver object. |
required |
Source code in src/ares/behaviors/combat/combat_maneuver.py
AMove
dataclass
¶
Bases: CombatIndividualBehavior
A-Move a unit to a target.
Example:
from ares.behaviors.combat.individual import AMove
self.register_behavior(AMove(unit, self.game_info.map_center))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to stay safe. |
target |
Point2 | Unit
|
Where the unit is going. |
success_at_distance |
float
|
Distance at which we don't need to issue a new move command because it's near the target. |
AttackTarget
dataclass
¶
DropCargo
dataclass
¶
Bases: CombatIndividualBehavior
Handle releasing cargo from a container.
Medivacs, WarpPrism, Overlords, Nydus.
Example:
from ares.behaviors.combat.individual import DropCargo
unit: Unit
target: Unit
self.register_behavior(DropCargo(unit, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The container unit. |
target |
Point2
|
The target position where to drop the cargo. |
GhostSnipe
dataclass
¶
Bases: CombatIndividualBehavior
Very opinionated ghost snipe. Create own behavior based on this if needed.
Attributes: unit: The ghost. close_enemy: All close by allied units we want to heal.
KeepUnitSafe
dataclass
¶
Bases: CombatIndividualBehavior
Get a unit to safety based on the influence grid passed in.
Example:
from ares.behaviors.combat.individual import KeepUnitSafe
unit: Unit
grid: np.ndarray = self.mediator.get_ground_grid
self.register_behavior(KeepUnitSafe(unit, grid))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to stay safe. |
grid |
ndarray
|
2D grid which usually contains enemy influence. |
MedivacHeal
dataclass
¶
Bases: CombatIndividualBehavior
Given close allied units, heal things up.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The siege tank unit. |
close_allied |
list[Unit]
|
All close by allied units we want to heal. |
grid |
ndarray
|
The path for medivac to heal on |
keep_safe |
bool
|
Attempt to stay safe, this may result in not always healing units (Default is True) |
MoveToSafeTarget
dataclass
¶
MoveToSafeTarget(unit, grid, target, use_pathing=True, success_at_distance=1.0, sensitivity=5, smoothing=False, sense_danger=True, danger_distance=20.0, danger_threshold=5.0, radius=12.0)
Bases: CombatIndividualBehavior
Given a destination target, find the nearest safe position and move
unit there.
Example:
from ares.behaviors.combat.individual import MoveToSafeTarget
unit: Unit
grid: np.ndarray = self.mediator.get_ground_grid
target: Point2 = self.game_info.map_center
self.register_behavior(MoveToSafeTarget(unit, grid, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to path. |
grid |
ndarray
|
2D grid to path on. |
target |
Point2
|
Target destination. |
use_pathing |
bool
|
Whether to use pathing or just move directly towards the target. Defaults to True. |
success_at_distance |
float
|
If the unit has gotten this close, consider path behavior complete. Defaults to 0.0. |
sensitivity |
int
|
Path precision. Defaults to 5. |
smoothing |
bool
|
Whether to smooth out the path. Defaults to False. |
sense_danger |
bool
|
Whether to check for dangers. If none are present, the pathing query is skipped. Defaults to True. |
danger_distance |
float
|
If |
danger_threshold |
float
|
Influence at which a danger is respected. Defaults to 5.0. |
radius |
float
|
How far to look for a safe spot around the target. Defaults to 12.0. |
PathUnitToTarget
dataclass
¶
PathUnitToTarget(unit, grid, target, success_at_distance=0.0, sensitivity=5, smoothing=False, sense_danger=True, danger_distance=20.0, danger_threshold=5.0)
Bases: CombatIndividualBehavior
Path a unit to its target destination.
Example:
from ares.behaviors.combat.individual import PathUnitToTarget
unit: Unit
grid: np.ndarray = self.mediator.get_ground_grid
target: Point2 = self.game_info.map_center
self.register_behavior(PathUnitToTarget(unit, grid, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to path. |
grid |
ndarray
|
2D grid to path on. |
target |
Point2
|
Target destination. |
success_at_distance |
float
|
If the unit has gotten this close, consider path behavior complete. Defaults to 0.0. |
sensitivity |
int
|
Path precision. Defaults to 5. |
smoothing |
bool
|
Whether to smooth out the path. Defaults to False. |
sense_danger |
bool
|
Whether to check for dangers. If none are present, the pathing query is skipped. Defaults to True. |
danger_distance |
float
|
If |
danger_threshold |
float
|
Influence at which a danger is respected. Defaults to 5.0. |
PickUpAndDropCargo
dataclass
¶
PickUpAndDropCargo(unit, grid, pickup_targets, target, cargo_switch_to_role=None, should_drop_units=True, keep_dropship_safe=True, success_at_distance=2.0)
Bases: CombatIndividualBehavior
Combines PickUpCargo and DropCargo behaviors.
Medivacs, WarpPrism, Overlords.
Example:
from ares.behaviors.combat.individual import PickUpAndDropCargo
unit: Unit # medivac for example
grid: np.ndarray = self.mediator.get_ground_grid
pickup_targets: Units | list[Unit] = self.workers
self.register_behavior(
PickUpAndDropCargo(unit, grid, pickup_targets, self.ai.game_info.map_center)
)
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The container unit. |
grid |
ndarray
|
Pathing grid for the container unit. |
pickup_targets |
list[Unit] | Units
|
Units we want to load into the container. |
target |
Point2
|
Drop at this target |
cargo_switch_to_role |
UnitRole | None
|
Sometimes useful to switch cargo to a new role immediately after loading. Defaults to None. |
should_drop_units |
bool
|
Whether to drop units once they are loaded. Defaults to True. |
keep_dropship_safe |
bool
|
If true, will keep dropship safe if nothing else to do. Defaults to True. |
success_at_distance |
float
|
Distance at which pathing to target stops being checked. Defaults to 2.0. |
PickUpCargo
dataclass
¶
Bases: CombatIndividualBehavior
Handle loading cargo into a container.
Medivacs, WarpPrism, Overlords, Nydus.
Example:
from ares.behaviors.combat.individual import PickUpCargo
unit: Unit # medivac for example
grid: np.ndarray = self.mediator.get_ground_grid
pickup_targets: Units | list[Unit] = self.workers
self.register_behavior(PickUpCargo(unit, grid, pickup_targets))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The container unit. |
grid |
ndarray
|
Pathing grid for the container unit. |
pickup_targets |
list[Unit] | Units
|
Units we want to load into the container. |
cargo_switch_to_role |
UnitRole | None
|
Sometimes useful to switch cargo to a new role immediately after loading. Defaults to None. |
PlacePredictiveAoE
dataclass
¶
PlacePredictiveAoE(unit, path, enemy_center_unit, aoe_ability, ability_delay, reaper_grenade_range=5.0)
Bases: CombatIndividualBehavior
Predict an enemy position and fire AoE accordingly.
Warning: Use this at your own risk. Work in progress.
Guess where the enemy is going based on how it's been moving.
Cythonize this.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to fire the AoE. |
path |
list[Point2]
|
How we're getting to the target position (the last point in the list). |
enemy_center_unit |
Unit
|
Enemy unit to calculate positions based on. |
aoe_ability |
AbilityId
|
AoE ability to use. |
ability_delay |
int
|
Amount of frames between using the ability and the ability occurring. |
QueenSpreadCreep
dataclass
¶
Bases: CombatIndividualBehavior
Attempt to spread creep along a path, from
start to target.
Example:
from ares.behaviors.combat.individual import QueenSpreadCreep
target: Point2 = self.ai.enemy_start_locations[0]
self.register_behavior(QueenSpreadCreep(queen, queen.position, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
Unit |
cancel_if_close_enemy |
bool
|
if on route to spread creep, and queen in danger. |
pre_move_queen_to_tumor |
bool
|
move queen to tumor placement even if not enough energy to spread creep. |
RavenAutoTurret
dataclass
¶
Bases: CombatIndividualBehavior
Drop a turret, opinionated and could be improved Create own behavior based on this if needed.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
Unit |
all_close_enemy |
list[Unit]
|
All close by allied units we want to heal. |
ReaperGrenade
dataclass
¶
ReaperGrenade(unit, enemy_units, retreat_target, grid, place_predictive=True, reaper_grenade_range=5.0)
Bases: CombatIndividualBehavior
Do reaper grenade.
Example:
from ares.behaviors.combat.individual import ReaperGrenade
unit: Unit
target: Unit
self.register_behavior(DropCargo(unit, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The container unit. |
enemy_units |
Units | list[Unit]
|
The enemy units. |
retreat_target |
Point2
|
The target position where reaper would retreat. |
grid |
ndarray
|
The grid used to predicatively place the grenade. |
place_predictive |
bool
|
Whether to predicatively place the grenade. |
reaper_grenade_range |
float
|
The range at which to use the grenade. |
SiegeTankDecision
dataclass
¶
SiegeTankDecision(unit, close_enemy, target, stay_sieged_near_target=False, remain_sieged=False, force_unsiege=False)
Bases: CombatIndividualBehavior
Decide if a tank should either siege or unsiege.
VERY OPINIONATED, recommend to write own version based on this.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The siege tank unit. |
close_enemy |
list[Unit]
|
All close by enemies. |
target |
Point2
|
Intended destination for this tank. |
stay_sieged_near_target |
bool
|
This is useful for tanks in defensive position. If on offensive, might not be needed Default is False. |
remain_sieged |
bool
|
Sometimes we might just want to leave the tank sieged up Default is False. |
force_unsiege |
bool
|
We might want to not ever siege Default is False. |
ShootAndMoveToTarget
dataclass
¶
ShootAndMoveToTarget(unit, enemy_units, target, grid, dist_to_target=4.0, attack_destructables=True)
Bases: CombatIndividualBehavior
We want to move to a specific point on the map, but shoot any in range enemies along the way. Can also optionally shoot destructables. If unit is left near target it gets a moved, so keep in mind when calling this method.
Example:
from ares.behaviors.combat.individual import ShootAndMoveToTarget
self.ai.register_behavior(ShootAndMoveToTarget(
unit=unit,
enemy_units=enemies,
target=target,
grid=grid,
))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit we want tp control. |
enemy_units |
Units | list[Unit]
|
The units that we will shoot at while moving. |
target |
Point2
|
The position where we want our unit to end up. |
grid |
ndarray
|
Grid used for pathfinding. |
dist_to_target |
float
|
Distance away from target where pathfinding stops. Default value of 4.0 means that once within 4 tiles of the target we stop pathfinding. |
attack_destructables |
bool
|
Whether we should shoot destructibles.
Default value is |
ShootTargetInRange
dataclass
¶
Bases: CombatIndividualBehavior
Find something to shoot at.
Currently only picks lowest health.
Might want to pick best one shot KO for example
Example:
from ares.behaviors.combat.individual import ShootTargetInRange
unit: Unit
targets: Units | list[Unit]
self.register_behavior(ShootTargetInRange(unit, targets))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to shoot. |
targets |
list[Unit] | Units
|
Units we want to check. |
extra_range |
float
|
Look outside the unit's weapon range. This might be useful for hunting down low HP units. |
StutterUnitBack
dataclass
¶
Bases: CombatIndividualBehavior
Shoot at the target if possible, else move back.
Example:
from ares.behaviors.combat.individual import StutterUnitBack
unit: Unit
target: Unit
self.register_behavior(StutterUnitBack(unit, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to shoot. |
target |
Unit
|
The unit we want to shoot at. |
kite_via_pathing |
bool
|
Kite back using pathing? Value for |
grid |
ndarray | None
|
Pass in if using |
StutterUnitForward
dataclass
¶
Bases: CombatIndividualBehavior
Shoot at the target if possible, else move back.
Example:
from ares.behaviors.combat.individual import StutterUnitForward
unit: Unit
target: Unit
self.register_behavior(StutterUnitForward(unit, target))
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to shoot. |
target |
Unit
|
The unit we want to shoot at. |
TumorSpreadCreep
dataclass
¶
Bases: CombatIndividualBehavior
Coordinate tumor spread behavior for creep expansion.
Strategy:
-
Try to spread directly to creep edge if within range
-
If 1 fails, spread to random position within range
Example:
from ares.behaviors.combat.individual import TumorSpreadCreep
tumors: Units = self.mediator.get_own_structures_dict[UnitTypeId.CREEPTUMORBURROWED]
for tumor in tumors:
self.register_behavior(
TumorSpreadCreep(tumor, self.enemy_start_locations[0])
)
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The tumor unit executing the tumor creep spread. |
target |
Point2
|
The target point for the tumor placement. |
UseAbility
dataclass
¶
Bases: CombatIndividualBehavior
A-Move a unit to a target.
Example:
from ares.behaviors.combat.individual import UseAbility
from sc2.ids.ability_id import AbilityId
unit: Unit
target: Point2 | Unit
self.register_behavior(
UseAbility(
AbilityId.FUNGALGROWTH_FUNGALGROWTH, unit, target
)
)
Attributes:
| Name | Type | Description |
|---|---|---|
ability |
AbilityId
|
The ability we want to use. |
unit |
Unit
|
The unit to use the ability. |
target |
Point2 | Unit | None
|
Target for this ability. |
UseAOEAbility
dataclass
¶
UseAOEAbility(unit, ability_id, targets, min_targets, avoid_own_flying=False, avoid_own_ground=False, bonus_tags=set(), recalculate=False, stack_same_spell=False)
Bases: CombatIndividualBehavior
Attempt to use AOE ability for a unit.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit that potentially has an AOE ability. |
ability_id |
AbilityId
|
Ability we want to use. |
targets |
list[Unit]
|
The targets we want to hit. |
min_targets |
int
|
Minimum targets to hit with spell. |
avoid_own_flying |
bool
|
Avoid own flying with this spell? Default is False. |
avoid_own_ground |
bool
|
Avoid own ground with this spell? Default is False. |
bonus_tags |
set | None
|
Give more emphasize on this unit tags.
For example, perhaps a ravager can do corrosive bile
Provide enemy tags that are currently fungaled?
Default is empty |
recalculate |
bool
|
If unit is already using ability, should we recalculate this behavior? WARNING: could have performance impact Default is False. |
stack_same_spell |
bool
|
Stack spell in same position? Default is False. |
UseTransfuse
dataclass
¶
Bases: CombatIndividualBehavior
Queen tries to transfuse something
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The queen that should transfuse. |
targets |
list[Unit] | Units
|
Our own units to transfuse. |
extra_range |
float
|
Look a bit further out of transfuse range? Default is 0.0 |
WorkerKiteBack
dataclass
¶
Bases: CombatIndividualBehavior
Shoot at the target if possible, else move back.
This is similar to stutter unit back, but takes advantage of mineral walking.
Example:
from ares.behaviors.combat.individual import WorkerKiteBack
unit: Unit
target: Unit
self.register_behavior(
WorkerKiteBack(
unit, target
)
)
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
Unit
|
The unit to shoot. |
target |
Unit
|
The unit we want to shoot at. |
should_attack |
bool
|
Whether to attack |
retreat_pathing |
bool
|
Precomputed pathing for retreat |