Skip to content

Combat and Unit Micro

DrInfy edited this page Aug 29, 2021 · 12 revisions

Combat Micro

GroupCombatManager handles how units micro during combat. Combat micro is managed in the following 5 phases:


Base implementation, that could be modified and adjusted by the user:


combat micro phases

Before assigning units to combat, you should set their role to what your bot is trying to do with them.

# Add units to combat manager
self.combat.add_unit(unit)

# Order the units in combat manager to do something.
self.combat.execute(self.knowledge.gather_point, MoveType.Assault)

# Unit list in combat manager is automatically cleared.

Combat manager attempts to group units and first tries to combine groups of units together and then move units by their types and finally micro the units individually based on their micro type.

Overriding group management and regrouping

Managing and grouping units is a critical process in how your micro works and it gives your bot a lot of personality on how it fights. There is a decent group management code in sharpy by default, but bot authors using sharpy should eventually write their own that matches the scenarios they want their bot to work best with.

A super aggressive bot might want to stream all of their units to enemy base as fast as they are out. Another bot might have a timing attack build that is reliant on colossus being with the army. For handle group method to work correctly, each group must be assigned a command within the combat manager. Available commands are:

combat.move_to(group, position_to_move, move_type)
combat.attack_to(group, position_to_attack, move_type)
combat.regroup(group, position)

Example handle groups override

def handle_groups_method(combat: "GroupCombatManager", target: Point2, move_type=MoveType.Assault):
    for group in combat.own_groups:
        if move_type == MoveType.PanicRetreat:
            combat.move_to(group, target, move_type)
        else:
            combat.attack_to(group, target, move_type)

class ProtossBot(KnowledgeBot):
    def configure_managers(self) -> Optional[List[ManagerBase]]:
        # When using default regrouping method, this is used to indicate how spread out the units can be
        # Percentage 0 - 1 on how many of the attacking units should actually be together when attacking
        self.combat.default_rules.regroup_percentage = 0.75
        # How much distance must be between units to consider them to be in different groups
        self.combat.default_rules.own_group_threshold = 9
        # This overrides the default unit regrouping
        self.combat.default_rules.handle_groups_func = handle_groups_method
Clone this wiki locally