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¶
macros : list[Behavior] (optional, default: []) A list of behaviors that should be executed
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¶
structure_needing_addon : Unit The structure type we want the addon for addon_required : UnitID 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¶
base_location : Point2
The base location where supply should be built.
return_true_if_supply_required : bool
Can't afford supply, but it's required, return true?
Useful if creating a MacroPlan
Returns¶
bool : True if this Behavior carried out an action.
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 127 128 129 130 131 132 133 |
|
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¶
base_location : Point2 The base location to build near. structure_id : UnitTypeId The structure type we want to build. wall : bool Find wall placement if possible. (Only main base currently supported) closest_to : Point2 (optional) Find placement at this base closest to
Source code in src/ares/behaviors/macro/build_structure.py
BuildWorkers
dataclass
¶
Bases: MacroBehavior
Finds idle townhalls / larvae and build workers.
Example:
Attributes¶
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¶
to_count : int
The target base count.
can_afford_check : bool, optional
Check we can afford expansion.
Setting this to False will allow worker to move
to location ready to build expansion.
(default is True
)
check_location_is_safe : bool, optional
Check we don't knowingly expand at a dangerous location.
(default is True
)
max_pending : int, optional
Maximum pending townhalls at any time.
(default is 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 117 118 119 120 121 122 123 |
|
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¶
to_count : int How many gas buildings would we like? max_pending : int (optional) How many gas pending at any time? closest_to : Point2 (optional) Find available geyser closest to this location.
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¶
flee_at_health_perc : float, optional If worker is in danger, at what health perc should it flee (default is 0.5). keep_safe : bool, optional Workers flee if they are in danger? (default is True). long_distance_mine : bool, optional If worker has nothing to do, can it long distance mine (default is True). mineral_boost : bool, optional Turn mineral boosting off / on (default is True). vespene_boost : bool, optional Turn vespene boosting off / on (only active when workers_per_gas < 3) WARNING: VESPENE BOOSTING CURRENTLY NOT WORKING (default is True). workers_per_gas : bool, optional (default: 3) Control how many workers are assigned to each gas. self_defence_active : bool, optional (default: True) If set to True, workers will have some basic defence. Certain workers will attack enemy in range. safe_long_distance_mineral_fields : Optional[Units], optional (default is None) Used internally, value is set if a worker starts long distance mining.
Source code in src/ares/behaviors/macro/mining.py
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 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
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¶
army_composition_dict : dict[UnitID: float, bool]
A dictionary that details how an army composition should be made up.
The proportional values should all add up to 1.0.
With a priority integer to give units emphasis.
base_location : Point2
Where abouts do we build production?
add_production_at_bank : Tuple[int, int], optional
When we reach this bank size, work out what extra production
would be useful.
Tuple where first value is minerals and second is vespene.
(default = (300, 300)
)
alpha : float, optional
Controls how much production to add when bank is
higher than add_production_at_bank
.
(default = 0.9
)
unit_pending_progress : float, optional
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.
(default = 0.8)
ignore_below_proportion: float, optional
If we don't want many of this unit, no point adding production.
Will check if possible to build unit first.
Default is 0.05
should_repower_structures: bool, optional
Search for unpowered structures, and build a new
pylon as needed.
Default is True
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 309 310 311 312 313 314 315 316 317 318 319 |
|
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¶
army_composition_dict : dict[UnitID: float, bool] A dictionary that details how an army composition should be made up. The proportional values should all add up to 1.0. With a priority integer to give units emphasis. freeflow_mode : bool (default: False) If set to True, army comp proportions are ignored, and resources will be spent freely. ignore_proportions_below_unit_count : int (default 0) In early game units effect the army proportions significantly. This allows some units to be freely built before proportions are respected. over_produce_on_low_tech : bool (default True) If there is only tech available for one unit, this will allow this unit to be constantly produced. ignored_build_from_tags : set[int] Prevent spawn controller from morphing from these tags Example: Prevent selecting barracks that needs to build an addon maximum : int (default 20) The maximum unit type we can produce in a single step. spawn_target : Union[Point2, None] (default None) Prioritize spawning units near this location.
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 344 |
|
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¶
desired_tech : Union[UpgradeId, UnitTypeId] What is the desired thing we want? base_location : bool The main building location to make tech. ignore_existing_techlabs : bool Will keep building techlabs even if others exist (default = False)
Returns¶
bool : True if this Behavior carried out an action.
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 212 213 214 215 216 217 218 219 |
|
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¶
upgrade_list : list[UpgradeId] List of desired upgrades. base_location : Point2 Where to build upgrade buildings.
Returns¶
bool : True if this Behavior carried out an action.