Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
CS325 Artificial IntelligenceCh. 5, Games!
Cengiz Günay, Emory Univ.
vs.
Spring 2013
Günay Ch. 5, Games! Spring 2013 1 / 19
AI in Games
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
AdversariesSimulated reality (non-playablecharacters, world reaction toplayer).Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
AI in Games
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
AdversariesSimulated reality (non-playablecharacters, world reaction toplayer).Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
AI in Games
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
AdversariesSimulated reality (non-playablecharacters, world reaction toplayer).Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
AI in Games
zerg rush
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
Adversaries
Simulated reality (non-playablecharacters, world reaction toplayer).Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
AI in Games
zerg rush
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
AdversariesSimulated reality (non-playablecharacters, world reaction toplayer).
Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
AI in Games
zerg rush
A lot of work is done on it. Why?
Fun, provide entertainmentAlso, simpler than life: toyproblems
Types of game AIs:
AdversariesSimulated reality (non-playablecharacters, world reaction toplayer).Game theory (next class)
Günay Ch. 5, Games! Spring 2013 2 / 19
Entry/Exit Surveys
Exit survey: Hidden Markov ModelsIn the mining robot example, when is the uncertainty of the robot’strajectories reduced?How is Particle Filtering like and unlike a water filter?
Entry survey: Adversarial Games (0.25 points of final grade)What algorithm would be useful in games? Give examples with twodifferent algorithms you learned in class.How would you help an agent solve a problem against an adversary?Think of a game like chess or checkers for starters.
Günay Ch. 5, Games! Spring 2013 3 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent:
vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a maze
Bayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets:
card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card games
Machine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning:
guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user moves
Logic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning:
board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)
MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning:
pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zerg
HMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter:
state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Previously on AI for Games. . .
Can previous algorithms help in games?Single-state agent: vacuum world, solving a mazeBayes Nets: card gamesMachine Learning: guessing games, learning user movesLogic, planning: board game with complex rules (Machinarium)MDPs, Reinforcement Learning: pathfinding, optimal strategy for zergHMMs, Particle Filter: state estimation and future prediction, partiallyobservable environment with traps (sonic?)
None for adversaries?
Günay Ch. 5, Games! Spring 2013 4 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameChess, CheckersRobot SoccerPokerHide-and-go-seekStarcraftBattle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
Robot SoccerPokerHide-and-go-seekStarcraftBattle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerPokerHide-and-go-seekStarcraftBattle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
Hide-and-go-seekStarcraftBattle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
X X X X Hide-and-go-seekStarcraftBattle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
X X X X Hide-and-go-seekX X Starcraft
Battle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
X X X X Hide-and-go-seekX X Starcraft
X X X Battle for WesnothHalo/CoD/MoHSolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
X X X X Hide-and-go-seekX X Starcraft
X X X Battle for WesnothX X X Halo/CoD/MoH
SolitaireMinesweeperZuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Properties of Games as Agent Environment
Stochastic Part.-Observ. Unknown Adversarial GameX Chess, Checkers
X X X Robot SoccerX X Poker
X X X X Hide-and-go-seekX X Starcraft
X X X Battle for WesnothX X X Halo/CoD/MoH
X SolitaireX MinesweeperX Zuma
Günay Ch. 5, Games! Spring 2013 5 / 19
Single Player Games
→ → → ← ← ←
Deterministic, single-state agent → Single-player game using tree searchinitial stateplayer statepossible actionsresults of actionsutility valuesgoal test
Günay Ch. 5, Games! Spring 2013 6 / 19
Adversarial Games
Adversarial Games1 Start by adapting single-state agent to games2 Define adversary as someone who wants you to lose3 And makes decisions based on the outcome of your moves
2-player games:DeterministicZero-sum: Rewarddistributed between playersMinimax algorithm:max & min playerschoose +/- utility, resp.
Günay Ch. 5, Games! Spring 2013 7 / 19
Adversarial Games
Adversarial Games1 Start by adapting single-state agent to games2 Define adversary as someone who wants you to lose3 And makes decisions based on the outcome of your moves
2-player games:DeterministicZero-sum: Rewarddistributed between playersMinimax algorithm:max & min playerschoose +/- utility, resp.
Günay Ch. 5, Games! Spring 2013 7 / 19
Adversarial Games
Adversarial Games1 Start by adapting single-state agent to games2 Define adversary as someone who wants you to lose3 And makes decisions based on the outcome of your moves
2-player games:DeterministicZero-sum: Rewarddistributed between playersMinimax algorithm:max & min playerschoose +/- utility, resp.
Günay Ch. 5, Games! Spring 2013 7 / 19
2-Player Value Function
defun value(s):if s is �: U(s)if s is M: maxValue(s)if s is O: minValue(s)
defun m = maxValue(s):m = −∞for (a, s ′) in successors(s):
v = value(s ′)m = maxValue(m, v)
Assumes opponent is perfect!
Günay Ch. 5, Games! Spring 2013 8 / 19
2-Player Value Function
defun value(s):if s is �: U(s)if s is M: maxValue(s)if s is O: minValue(s)
defun m = maxValue(s):m = −∞for (a, s ′) in successors(s):
v = value(s ′)m = maxValue(m, v)
Assumes opponent is perfect!
Günay Ch. 5, Games! Spring 2013 8 / 19
2-Player Value Function
defun value(s):if s is �: U(s)if s is M: maxValue(s)if s is O: minValue(s)
defun m = maxValue(s):m = −∞for (a, s ′) in successors(s):
v = value(s ′)m = maxValue(m, v)
Assumes opponent is perfect!
Günay Ch. 5, Games! Spring 2013 8 / 19
Time Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
For chess: b ' 30, m ' 40How long would it take with:
1 billion processors ×1billion/s evals?
1 seconds2 minutes3 hours4 years5 forever
Günay Ch. 5, Games! Spring 2013 9 / 19
Time Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
For chess: b ' 30, m ' 40How long would it take with:
1 billion processors ×1billion/s evals?
1 seconds2 minutes3 hours4 years5 forever
Günay Ch. 5, Games! Spring 2013 9 / 19
Time Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
For chess: b ' 30, m ' 40How long would it take with:
1 billion processors ×1billion/s evals?
1 seconds2 minutes3 hours4 years5 forever
Günay Ch. 5, Games! Spring 2013 9 / 19
Time Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
For chess: b ' 30, m ' 40How long would it take with:
1 billion processors ×1billion/s evals?
1 seconds2 minutes3 hours4 years5 forever
Günay Ch. 5, Games! Spring 2013 9 / 19
Space Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
Do not need more than total num-ber of nodes.
Günay Ch. 5, Games! Spring 2013 10 / 19
Space Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
Do not need more than total num-ber of nodes.
Günay Ch. 5, Games! Spring 2013 10 / 19
Space Complexity
For a tree withbranching factor, b, and depth, m?
1 O(bm)
2 O(bm)
3 O(mb)
Do not need more than total num-ber of nodes.
Günay Ch. 5, Games! Spring 2013 10 / 19
Complexity Reduction?
How to do it?1 Reduce b2 Reduce m3 Tree → graph
All of the above!
Günay Ch. 5, Games! Spring 2013 11 / 19
Complexity Reduction?
How to do it?1 Reduce b2 Reduce m3 Tree → graph
All of the above!
Günay Ch. 5, Games! Spring 2013 11 / 19
Example
defun value(s):if s is �: U(s)if s is M: maxValue(s)if s is O: minValue(s)
defun m = maxValue(s):m = −∞for (a, s ′) in successors(s):
v = value(s ′)m = maxValue(m, v)
Günay Ch. 5, Games! Spring 2013 12 / 19
Example
defun value(s):if s is �: U(s)if s is M: maxValue(s)if s is O: minValue(s)
defun m = maxValue(s):m = −∞for (a, s ′) in successors(s):
v = value(s ′)m = maxValue(m, v)
Günay Ch. 5, Games! Spring 2013 12 / 19
Reducing Branching Factor, b
Which one to prune?
Günay Ch. 5, Games! Spring 2013 13 / 19
Reducing Branching Factor, b
Which one to prune?
Günay Ch. 5, Games! Spring 2013 13 / 19
Reducing Branching Factor, b
Which one to prune?
Günay Ch. 5, Games! Spring 2013 13 / 19
Reducing Branching Factor, b
Which one to prune?
Günay Ch. 5, Games! Spring 2013 13 / 19
Reducing Branching Factor, b
Which one to prune?
Günay Ch. 5, Games! Spring 2013 13 / 19
Reducing Depth, m
Select a cutoff:Limit m (e.g., plan 3 steps ahead in chess)Estimate terminal nodes’ utility with evaluation function
like heuristics
Learn from experienceIn chess, use board state, value of pieces, etc.For value of pieces:eval(s) =
∑i wipi
can use machine learning for wi
Günay Ch. 5, Games! Spring 2013 14 / 19
Formalize as Alpha-Beta Pruning
defun value(s):cutoff at depth m′: eval(s)if s is �: U(s)if s is M: maxValue(s, depth, α, β)if s is O: minValue(s, depth, α, β)
where α, β are overall max and min values,resp.
defun v = maxValue(s, depth, α, β):v = −∞for (a, s ′) in successors(s):
v = max(v , value(s ′, depth + 1, α, β))if v > β return vα = max(α, v)
Can cut up to O(bm/2)!
Günay Ch. 5, Games! Spring 2013 15 / 19
Formalize as Alpha-Beta Pruning
defun value(s):cutoff at depth m′: eval(s)if s is �: U(s)if s is M: maxValue(s, depth, α, β)if s is O: minValue(s, depth, α, β)
where α, β are overall max and min values,resp.
defun v = maxValue(s, depth, α, β):v = −∞for (a, s ′) in successors(s):
v = max(v , value(s ′, depth + 1, α, β))if v > β return vα = max(α, v)
Can cut up to O(bm/2)!
Günay Ch. 5, Games! Spring 2013 15 / 19
Formalize as Alpha-Beta Pruning
defun value(s):cutoff at depth m′: eval(s)if s is �: U(s)if s is M: maxValue(s, depth, α, β)if s is O: minValue(s, depth, α, β)
where α, β are overall max and min values,resp.
defun v = maxValue(s, depth, α, β):v = −∞for (a, s ′) in successors(s):
v = max(v , value(s ′, depth + 1, α, β))if v > β return vα = max(α, v)
Can cut up to O(bm/2)!
Günay Ch. 5, Games! Spring 2013 15 / 19
Formalize as Alpha-Beta Pruning
defun value(s):cutoff at depth m′: eval(s)if s is �: U(s)if s is M: maxValue(s, depth, α, β)if s is O: minValue(s, depth, α, β)
where α, β are overall max and min values,resp.
defun v = maxValue(s, depth, α, β):v = −∞for (a, s ′) in successors(s):
v = max(v , value(s ′, depth + 1, α, β))if v > β return vα = max(α, v)
Can cut up to O(bm/2)!
Günay Ch. 5, Games! Spring 2013 15 / 19
Complexity Reduction by Tree → Graph
Convert into graph search problem:to reach special opening and closing statesto make and protect from killer-moves
Utility: How many food particles can pacman eat?
2-step limit causes horizon effect?
Günay Ch. 5, Games! Spring 2013 16 / 19
Complexity Reduction by Tree → Graph
Convert into graph search problem:to reach special opening and closing statesto make and protect from killer-moves
Utility: How many food particles can pacman eat?
2-step limit causes horizon effect?
Günay Ch. 5, Games! Spring 2013 16 / 19
Complexity Reduction by Tree → Graph
Convert into graph search problem:to reach special opening and closing statesto make and protect from killer-moves
Utility: How many food particles can pacman eat?
2-step limit causes horizon effect?
Günay Ch. 5, Games! Spring 2013 16 / 19
Complexity Reduction by Tree → Graph
Convert into graph search problem:to reach special opening and closing statesto make and protect from killer-moves
Utility: How many food particles can pacman eat?
2-step limit causes horizon effect?Günay Ch. 5, Games! Spring 2013 16 / 19
Stochastic Games
Günay Ch. 5, Games! Spring 2013 17 / 19
Stochastic Games
defun value(s):cutoff at depth m′: eval(s)if s is �: U(s)if s is M: maxValue(s, depth, α, β)if s is O: minValue(s, depth, α, β)if s is ?: expValue(s, depth, α, β)
Günay Ch. 5, Games! Spring 2013 18 / 19
Coin-flip Game
Günay Ch. 5, Games! Spring 2013 19 / 19
Coin-flip Game
Günay Ch. 5, Games! Spring 2013 19 / 19