CS 680: GAME AI
WEEK 4: DECISION MAKING IN RTS GAMES
2/6/2012 Santiago Ontañón santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2012/CS680/intro.html
CS 680: GAME AI WEEK 4: DECISION MAKING IN RTS GAMES 2/6/2012 - - PowerPoint PPT Presentation
CS 680: GAME AI WEEK 4: DECISION MAKING IN RTS GAMES 2/6/2012 Santiago Ontan santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2012/CS680/intro.html Reminders Projects: Project 1 is simpler than it seems: 1)
2/6/2012 Santiago Ontañón santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2012/CS680/intro.html
a complete game of S3/Starcraft (whether it wins or not).
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”
possible actions is the best?
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter Decision making is key at these levels
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter And is most important at the high-level strategy level
After training 4 footmen Resource spending: 80% Economy, 20% Military 2 workers wood 1 worker metal Army Composition: 100% footmen Resource spending: 20% Economy, 80% Military 2 workers wood 4 workers metal Army Composition: 100% knights Army Composition: 50% knights 50% archers If enemy has Flying units If enemy has no more flying units
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”
Harvest Minerals Build Barracks Train marines Attack Enemy Explore Train SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen 4 marines & Enemy unseen No marines
switch(state) { case START: if (numSCVs<4) state = TRAIN_SCVs; if (numHarvestingSCVs>=4) state = BUILD_BARRACKS; Unit *SCV = findIdleSCV(); Unit *mineral = findClosestMineral(SCV); SCV->harvest(mineral); break; case TRAIN_SCVs: if (numSCVs>=4) state = START; Unit *base = findIdleBase(); base->train(UnitType::SCV); break; case BUILD_BARRACKS: … }
Perception Strategy/ Give Orders Execute Orders Unit Analysis Map Analysis Unit AI Building Placer Pathfinder Unit AI Unit AI
Harvest Minerals Build Barracks Train marines Attack Enemy Explore Train SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen 4 marines & Enemy unseen No marines
Perception Strategy/ Give Orders Execute Orders Unit Analysis Map Analysis Unit AI Building Placer Pathfinder Unit AI Unit AI
Harvest Minerals Build Barracks Train marines Attack Enemy Explore Train SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen 4 marines & Enemy unseen No marines
For Simple games or simple AIs, we could substitute both Strategy and “Give Orders” layers by a FSM
Perception Strategy/ Give Orders Execute Orders Unit Analysis Map Analysis Unit AI Building Placer Pathfinder Unit AI Unit AI
Harvest Minerals Build Barracks Train marines Attack Enemy Explore Train SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen 4 marines & Enemy unseen No marines
For mode complex AIs, FMSs are too restrictive, and it’s better to use the architecture as we explained it in Week 2 of class
state!
Harvest Minerals Build Barracks Train 4 marines Attack Enemy Explore Train 4 SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen Enemy unseen No marines Attack Inside Enemy Enemy Inside Base
Standard Strategy
Attack Inside Enemy Enemy Inside Base No Enemy Inside Base
Harvest Minerals Build Barracks Train 4 marines Attack Enemy Explore Train 4 SCVs 4 SCVs harvesting 4 SCVs Less than 4 SCVs barracks 4 marines & Enemy seen Enemy seen Enemy unseen No marines
Attack Inside Enemy Enemy Inside Base No Enemy Inside Base
a easy and organized way
kind of units to build
units than him, then attack
units, then build air units
Enemy Seen Does he have Air Units Do we have Antiair units Do we have More units Than him Do we have More units Than him Build Antiair units Attack! Build more units Attack! Build more units Build more units no no no no no yes yes yes yes yes
be easily captured in a decision tree
think about the problem, and then just use nested if-then-else statements
editors to game designers
state to go next
S1 C1 C2 S2 S3
Finite-State Machine used as an example in Week 2 of class
After training 4 footmen Resource spending: 80% Economy, 20% Military 2 workers wood 1 worker metal Army Composition: 100% footmen Resource spending: 20% Economy, 80% Military 2 workers wood 4 workers metal Army Composition: 100% knights Army Composition: 50% knights 50% archers If enemy has Flying units If enemy has no more flying units
systems)
there’s many of them)
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”
Trees, etc. are useful to hardcode decisions:
(except for bugs)
be used to let the AI autonomously take decisions
foreseen by game designers
depending on the desirability of its immediate outcome
function
points per knight or bishop + 1 point per pawn.
can be improved by adding:
t
t
t
AI can decide what to do
since utility function has less information (only WHAT, not HOW)
we can only estimate the result of an action:
(e is the information we know about s)
the result of a
s0
Player = blue Enemy = red
Player = blue Enemy = red
the barracks, the enemy footman can kill our 2 footmen
Player = blue Enemy = red
the lumber mill, the enemy footman can kill our 2 footmen
Player = blue Enemy = red
Player = blue Enemy = red
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter Decision Theory can be useful at these three levels. Notice that, as presented here, it only considers one action at a time. If used in the Attack module, it is more natural to have
module” per “squad”, so each can take individual decisions.
exploring?
unknown variable E (that can take k different values e1, …, ek)
VPI e(E) = X
k
P(E = ek)EU (a∗
k|e, E = ek)
! − EU (a∗|e)
4 marines command center
4 marines command center
4 marines command center
EU(Attack | Defenses) = -500 EU(Attack | no Defenses) = 240
VPI(defenses) = (0.5 * EU(More Marines | Defenses) + 0.5 * EU(Attack | No Defenses) ) – (EU(Attack))
4 marines command center
VPI(defenses) = (0.5 * -380 + 0.5 * 240 ) – (-130) = -70 + 130 = 60
4 marines command center
“fun play”
player in a given period of time, in order to let the player breathe.
adversarial planning:
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”
Attack module)
made if the AI could plan for future actions:
into the upper defenses, and annihilate them with my 8 tanks.
Current Situation Player 1 action U(s) U(s) U(s)
Current Situation Player 1 action U(s) U(s) U(s)
Pick the action that leads to the state with maximum expected utility
Current Situation Player 1 action Player 2 action U(s) U(s) U(s) U(s) U(s) U(s)
executions:
Current Situation Player 1 action Player 2 action U(s) U(s) U(s) U(s) U(s) U(s)
executions:
Pick the action that leads to the state with maximum expected utility after taking into account what the other players might do
Current Situation Player 1 action Player 2 action U(s) U(s) U(s) U(s) U(s) U(s)
executions:
In this example, we look ahead only one player 1 action and
But we could grow the tree arbitrarily deep
Current Situation Player 1 action Player 2 action U(s) = -1 U(s) = 0 U(s) = -1 U(s) = 0 U(s) = 0 U(s) = 0
actions that minimize U
Current Situation Player 1 action Player 2 action (min) U(s) = -1 U(s) = 0 U(s) = -1 U(s) = 0 U(s) = 0 U(s) = 0
actions that minimize U
Current Situation Player 1 action Player 2 action (min) U(s) = -1 U(s) = 0 U(s) = -1 U(s) = 0 U(s) = 0 U(s) = 0
actions that minimize U
U(s) = -1 U(s) = -1 U(s) = 0
Current Situation Player 1 action (max) Player 2 action (min) U(s) = -1 U(s) = 0 U(s) = -1 U(s) = 0 U(s) = 0 U(s) = 0
actions that minimize U
U(s) = -1 U(s) = -1 U(s) = 0
Minimax(state, player, MAX_DEPTH) IF MAX_DEPTH == 0 RETURN U(state) BestAction = null BestScore = null FOR Action in actions(player, state) (Score,Action2) = Minimax(result(action, state), nextplayer(player), MAX_DEPTH-1) IF BestScore == null || (player == 1 && Score>BestScore) || (player == 2 && Score<BestScore) BestScore = Score BestAction = Action ENDFOR RETURN (BestScore, BestAction)
state
(2007):
are rated between 1 to 9 dan)
(max^n algorithm)
starting with each action
the action
variant of Monte-Carlo Search, responsible for the recent success of Computer Go programs
there
Minimax: Monte-Carlo:
U U U U U U U U U U U U U U U U
Minimax: Monte-Carlo:
U U U U U U U U U U U U U U U U Minimax opens the complete tree (all possible moves) up to a fixed depth. Then, the Utility function is applied to the leaves.
Minimax: Monte-Carlo:
U U U U U U U U U U U U U U U U Monte-Carlo search runs for each possible move at the root node a fixed number K of random complete games. No need for a Utility function (but it can be used), Complete Game
0/0 Tree Search Monte-Carlo Search Current state w/t is the account of how many games starting from this state have be found to be won out of the total games explored in the current search Current State
1/1 Tree Search Monte-Carlo Search win
1/2 Tree Search Monte-Carlo Search 0/1 loss At each iteration, one node of the tree (upper part) is selected and expanded (one node added to the tree). From this new node a complete game is played out at random (Monte-Carlo)
2/3 Tree Search Monte-Carlo Search 0/1 At each iteration, one node of the tree (upper part) is selected and expanded (one node added to the tree). From this new node a complete game is played out at random (Monte-Carlo) 1/1 win
3/4 Tree Search Monte-Carlo Search 0/1 2/2 1/1 win The counts w/t are used to determine which nodes to explore next. Exploration/Exploitation: 50% expand the best node in the tree 50% expand a node at random
3/5 Tree Search Monte-Carlo Search 0/1 2/3 1/1 0/1 loss The tree ensures all relevant actions are explored (greatly alleviates the randomness that affects Monte-Carlo methods)
3/5 Tree Search Monte-Carlo Search 0/1 2/3 1/1 0/1 loss The random games played from each node of the tree serve to estimate the Utility function. They can be random, or use an
time is over), UCT analyzes the resulting trees, and the selected action is that with the highest win ratio.
than minimax. It is the standard algorithms for modern (from 2008 to present) Go playing programs
an RTS AI game
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter
an RTS AI game
that make sense for the game. For example, in S3:
“strategy” to each player, and simulate it until completion:
Player 1, Action 1 Player 2, Action 2 Player 1, Action 3 Player 1: S2 (ETA 240) Player 2: S3 (ETA 400) Player 1: S1 (ETA 400) Player 2: S3 (ETA 160) Player 1: S1 (ETA 240) Player 2: S1 (ETA 400) Player 1: S1 Player 2: S1 Standard Minimax Strategy Simulation
units (taking into account air/ground units)
count the number of unit types in each region
Monte-Carlo
retreat, etc.
happened (e.g. new enemy sighted)
to author the exact behavior they want the AI to have
control, Attack module)
the AI will figure out HOW automatically
games where the game designers can control what they AI does)
maximize the utility function
Perception Strategy Give Orders Execute Orders Unit Analysis Map Analysis Strategy Economy Logistics Attack Unit AI Building Placer Pathfinder Unit AI Unit AI Arbiter
“Near Optimal Hierarchical Pathfinding”
“Intelligent Moving of Groups in Real-Time Strategy Games”