ASL Reference
ASL (AlfredStar Language) is the policy language for programming SC2 strategy. Authors declare what game state must hold by when, how to react to situations, and how to control units — the compiler transforms this into a build order.
For a guided introduction, see Tutorials.
Grammar
// Program structure
program ::= strategy
strategy ::= 'strategy' STRING 'for' RACE 'on' 'patch' VERSION '{' section* '}'
section ::= trajectory | situations | tactics | vocabulary
// Trajectory — state-by-time contracts
trajectory ::= 'trajectory' '{' traj_item* '}'
traj_item ::= state | branch
state ::= 'state' STRING 'by' TIME '{' requirement* '}'
branch ::= 'branch' '{' branch_arm* '}'
branch_arm ::= 'when' IDENT '->' '{' traj_item* '}'
| 'otherwise' '->' '{' traj_item* '}'
// Requirements — what must be true in a state
requirement ::= 'have' IDENT ':' INT
| 'workers' CMP INT
| 'upgrade' IDENT
| 'army' 'at' LOCATION
| 'scout' LOCATION
| 'workers' 'saturated' 'at' LOCATION
| 'attack' LOCATION ('priority' priority_list)?
// Priority targeting for attack goals
priority_list ::= '[' target (',' target)* ']'
target ::= 'army' | 'workers' | 'supply' | 'production'
| 'base' | 'buildings' | IDENT
// Situations — runtime conditions for branching
situations ::= 'situations' '{' situation_def* '}'
situation_def ::= IDENT '=' expr ('persists' TIME)?
| IDENT ':' IDENT '=' categorical_def
// Tactics — runtime reactions and unit control
tactics ::= 'tactics' '{' tactic_def* '}'
tactic_def ::= 'on' IDENT '{' tactic_action* '}'
| 'every' TIME '{' tactic_action* '}'
| 'always' 'when' IDENT '{' tactic_action* '}'
// Vocabulary — named expressions for reuse
vocabulary ::= 'vocabulary' '{' vocab_def* '}'
vocab_def ::= IDENT '=' expr
// Expressions
expr ::= or_expr
or_expr ::= and_expr ('or' and_expr)*
and_expr ::= cmp_expr ('and' cmp_expr)*
cmp_expr ::= add_expr (('==' | '!=' | '<' | '<=' | '>' | '>=') add_expr)?
add_expr ::= mul_expr (('+' | '-') mul_expr)*
mul_expr ::= unary_expr (('*' | '/' | '%') unary_expr)*
unary_expr ::= ('-' | 'not') unary_expr | primary
primary ::= INT | FLOAT | TIME | STRING | 'true' | 'false' | IDENT | '(' expr ')'
// Tokens
RACE ::= 'Protoss' | 'Terran' | 'Zerg'
VERSION ::= [0-9]+ '.' [0-9]+ '.' [0-9]+
CMP ::= '>=' | '<=' | '==' | '>' | '<'
TIME ::= [0-9]+ ':' [0-9][0-9] // e.g., 3:30, 0:15
INT ::= [0-9]+
FLOAT ::= [0-9]+ '.' [0-9]+
STRING ::= '"' [^"]* '"'
IDENT ::= [a-zA-Z_][a-zA-Z0-9_]* Complete Example
A full policy using trajectory, situations, tactics, and vocabulary:
strategy "Adaptive Stalker" for Protoss on patch 4.10.0 {
trajectory {
state "opener" by 3:30 {
have Gateway: 1
have CyberneticsCore: 1
have Stalker: 2
workers >= 16
scout enemy_main
}
branch {
when early_aggression -> {
state "defense" by 5:30 {
have Gateway: 3
have Stalker: 6
have ShieldBattery: 1
army at natural_ramp
}
}
otherwise -> {
state "expand" by 6:00 {
have RoboticsFacility: 1
have Gateway: 2
have Stalker: 4
workers >= 22
}
state "tech" by 9:00 {
have Colossus: 2
have Stalker: 6
upgrade ExtendedThermalLance
workers >= 28
}
}
}
}
situations {
early_aggression = army_supply > 10 and time < 4:00
under_attack = enemy_units_near_base > 0 persists 0:10
}
tactics {
on under_attack {
rally_to natural_ramp
set_production_rally natural_ramp
}
every 0:30 {
chrono_boost highest_priority_production
}
}
vocabulary {
natural_ramp = ramp("main", "natural")
enemy_main = enemy_base(0)
highest_priority_production = first_idle_production
}
} Sections
trajectory
The core of a policy. Declares a sequence of states — each is a set of requirements (buildings, units, upgrades, worker counts) that must be achieved by a deadline. The compiler plans the build order for each state segment. States chain: segment N+1 inherits everything from segment N and only plans the delta.
branch
Placed inside a trajectory between states. Contains when arms that reference situations and an otherwise default. The compiler pre-plans all branches from the preceding state's end economy. At runtime, the first matching situation selects the branch.
situations
Named boolean or categorical conditions evaluated at runtime. Used by branches to select paths and by tactics to trigger reactions. Boolean situations can persist for a duration to prevent rapid toggling.
tactics
Runtime reactions: on triggers when a situation becomes true, every runs periodically, always when runs continuously while a condition holds. Tactics control unit behavior, rallying, and ability usage.
vocabulary
Named expressions for map locations, unit groups, and computed values. Provides readable aliases that other sections reference.