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,
Mining
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. |
Source code in src/ares/behaviors/macro/macro_plan.py
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, UnitID.REACTOR)
)
Attributes:
Name | Type | Description |
---|---|---|
structure_needing_addon |
Unit
|
The structure type we want the addon for. |
addon_required |
UnitTypeId
|
Type of addon required. |
Source code in src/ares/behaviors/macro/addon_swap.py
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 |
Source code in src/ares/behaviors/macro/auto_supply.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
BuildStructure
dataclass
¶
Bases: MacroBehavior
Handy behavior for Terran and Protoss.
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
self.register_behavior(
BuildStructure(self.start_location, 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 |
Optional[Point2]
|
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. |
Source code in src/ares/behaviors/macro/build_structure.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
BuildWorkers
dataclass
¶
Bases: MacroBehavior
Finds idle townhalls / larvae and build workers.
Example:
Attributes:
Name | Type | Description |
---|---|---|
to_count |
int
|
The target count of workers we want to hit. |
Source code in src/ares/behaviors/macro/build_workers.py
ExpansionController
dataclass
¶
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. |
Source code in src/ares/behaviors/macro/expansion_controller.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
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 |
Optional[Point2]
|
Find available geyser closest to this location.
Optional, defaults to |
Source code in src/ares/behaviors/macro/gas_building_controller.py
Mining
dataclass
¶
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). WARNING: VESPENE BOOSTING CURRENTLY NOT WORKING. 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 |
Optional[Units]
|
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 |
Source code in src/ares/behaviors/macro/mining.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
ProductionController
dataclass
¶
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[UnitID: {float, bool}] = {
UnitID.MARINE: {"proportion": 0.6, "priority": 2}, # lowest priority
UnitID.MEDIVAC: {"proportion": 0.25, "priority": 1},
UnitID.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, str, 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. Tuple where the first value is
minerals and the second is vespene. Defaults to |
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 |
Source code in src/ares/behaviors/macro/production_controller.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
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:
Source code in src/ares/behaviors/macro/restore_power.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
SpawnController
dataclass
¶
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[UnitID: {float, bool}] = {
UnitID.MARINE: {"proportion": 0.6, "priority": 2}, # lowest priority
UnitID.MEDIVAC: {"proportion": 0.25, "priority": 1},
UnitID.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, str, 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 |
Optional[Point2]
|
A location to prioritize spawning units near. |
Source code in src/ares/behaviors/macro/spawn_controller.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
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 |
Union[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 |
Source code in src/ares/behaviors/macro/tech_up.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
UpgradeController
dataclass
¶
Bases: MacroBehavior
Research upgrades, if the upgrade is not currently researchable this behavior will automatically make the tech buildings required.
Example:
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. |