CS325 Artificial Intelligence Ch. 5, Games! Cengiz Gnay, Emory - - PowerPoint PPT Presentation

cs325 artificial intelligence ch 5 games
SMART_READER_LITE
LIVE PREVIEW

CS325 Artificial Intelligence Ch. 5, Games! Cengiz Gnay, Emory - - PowerPoint PPT Presentation

CS325 Artificial Intelligence Ch. 5, Games! Cengiz Gnay, Emory Univ. vs. Spring 2013 Gnay Ch. 5, Games! Spring 2013 1 / 19 AI in Games A lot of work is done on it. Why? Gnay Ch. 5, Games! Spring 2013 2 / 19 AI in Games A lot of


slide-1
SLIDE 1

CS325 Artificial Intelligence

  • Ch. 5, Games!

Cengiz Günay, Emory Univ. vs. Spring 2013

Günay

  • Ch. 5, Games!

Spring 2013 1 / 19

slide-2
SLIDE 2

AI in Games

A lot of work is done on it. Why?

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-3
SLIDE 3

AI in Games

A lot of work is done on it. Why? Fun, provide entertainment Also, simpler than life: toy problems

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-4
SLIDE 4

AI in Games

A lot of work is done on it. Why? Fun, provide entertainment Also, simpler than life: toy problems Types of game AIs:

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-5
SLIDE 5

AI in Games

zerg rush A lot of work is done on it. Why? Fun, provide entertainment Also, simpler than life: toy problems Types of game AIs: Adversaries

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-6
SLIDE 6

AI in Games

zerg rush A lot of work is done on it. Why? Fun, provide entertainment Also, simpler than life: toy problems Types of game AIs: Adversaries Simulated reality (non-playable characters, world reaction to player).

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-7
SLIDE 7

AI in Games

zerg rush A lot of work is done on it. Why? Fun, provide entertainment Also, simpler than life: toy problems Types of game AIs: Adversaries Simulated reality (non-playable characters, world reaction to player). Game theory (next class)

Günay

  • Ch. 5, Games!

Spring 2013 2 / 19

slide-8
SLIDE 8

Entry/Exit Surveys

Exit survey: Hidden Markov Models

In the mining robot example, when is the uncertainty of the robot’s trajectories 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 two different 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

slide-9
SLIDE 9

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-10
SLIDE 10

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-11
SLIDE 11

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-12
SLIDE 12

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-13
SLIDE 13

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-14
SLIDE 14

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-15
SLIDE 15

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-16
SLIDE 16

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium)

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-17
SLIDE 17

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium) MDPs, Reinforcement Learning:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-18
SLIDE 18

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium) MDPs, Reinforcement Learning: pathfinding, optimal strategy for zerg

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-19
SLIDE 19

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium) MDPs, Reinforcement Learning: pathfinding, optimal strategy for zerg HMMs, Particle Filter:

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-20
SLIDE 20

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium) MDPs, Reinforcement Learning: pathfinding, optimal strategy for zerg HMMs, Particle Filter: state estimation and future prediction, partially

  • bservable environment with traps (sonic?)

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-21
SLIDE 21

Previously on AI for Games. . .

Can previous algorithms help in games? Single-state agent: vacuum world, solving a maze Bayes Nets: card games Machine Learning: guessing games, learning user moves Logic, planning: board game with complex rules (Machinarium) MDPs, Reinforcement Learning: pathfinding, optimal strategy for zerg HMMs, Particle Filter: state estimation and future prediction, partially

  • bservable environment with traps (sonic?)

None for adversaries?

Günay

  • Ch. 5, Games!

Spring 2013 4 / 19

slide-22
SLIDE 22

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game Chess, Checkers Robot Soccer Poker Hide-and-go-seek Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-23
SLIDE 23

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers Robot Soccer Poker Hide-and-go-seek Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-24
SLIDE 24

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer Poker Hide-and-go-seek Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-25
SLIDE 25

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker Hide-and-go-seek Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-26
SLIDE 26

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker X X X X Hide-and-go-seek Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-27
SLIDE 27

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker X X X X Hide-and-go-seek X X Starcraft Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-28
SLIDE 28

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker X X X X Hide-and-go-seek X X Starcraft X X X Battle for Wesnoth Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-29
SLIDE 29

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker X X X X Hide-and-go-seek X X Starcraft X X X Battle for Wesnoth X X X Halo/CoD/MoH Solitaire Minesweeper Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-30
SLIDE 30

Properties of Games as Agent Environment

Stochastic Part.-Observ. Unknown Adversarial Game X Chess, Checkers X X X Robot Soccer X X Poker X X X X Hide-and-go-seek X X Starcraft X X X Battle for Wesnoth X X X Halo/CoD/MoH X Solitaire X Minesweeper X Zuma

Günay

  • Ch. 5, Games!

Spring 2013 5 / 19

slide-31
SLIDE 31

Single Player Games

→ → → ← ← ← Deterministic, single-state agent → Single-player game using tree search initial state player state possible actions results of actions utility values goal test

Günay

  • Ch. 5, Games!

Spring 2013 6 / 19

slide-32
SLIDE 32

Adversarial Games

Adversarial Games

1 Start by adapting single-state agent to games 2 Define adversary as someone who wants you to lose 3 And makes decisions based on the outcome of your moves Günay

  • Ch. 5, Games!

Spring 2013 7 / 19

slide-33
SLIDE 33

Adversarial Games

Adversarial Games

1 Start by adapting single-state agent to games 2 Define adversary as someone who wants you to lose 3 And makes decisions based on the outcome of your moves

2-player games: Deterministic Zero-sum: Reward distributed between players Minimax algorithm: max & min players choose +/- utility, resp.

Günay

  • Ch. 5, Games!

Spring 2013 7 / 19

slide-34
SLIDE 34

Adversarial Games

Adversarial Games

1 Start by adapting single-state agent to games 2 Define adversary as someone who wants you to lose 3 And makes decisions based on the outcome of your moves

2-player games: Deterministic Zero-sum: Reward distributed between players Minimax algorithm: max & min players choose +/- utility, resp.

Günay

  • Ch. 5, Games!

Spring 2013 7 / 19

slide-35
SLIDE 35

2-Player Value Function

defun value(s): if s is : U(s) if s is △: maxValue(s) if s is ▽: minValue(s)

Günay

  • Ch. 5, Games!

Spring 2013 8 / 19

slide-36
SLIDE 36

2-Player Value Function

defun value(s): if s is : U(s) if s is △: maxValue(s) if s is ▽: 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 8 / 19

slide-37
SLIDE 37

2-Player Value Function

defun value(s): if s is : U(s) if s is △: maxValue(s) if s is ▽: 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

slide-38
SLIDE 38

Time Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb) Günay

  • Ch. 5, Games!

Spring 2013 9 / 19

slide-39
SLIDE 39

Time Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb) Günay

  • Ch. 5, Games!

Spring 2013 9 / 19

slide-40
SLIDE 40

Time Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb)

For chess: b ≃ 30, m ≃ 40 How long would it take with: 1 billion processors ×1 billion/s evals?

1 seconds 2 minutes 3 hours 4 years 5 forever Günay

  • Ch. 5, Games!

Spring 2013 9 / 19

slide-41
SLIDE 41

Time Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb)

For chess: b ≃ 30, m ≃ 40 How long would it take with: 1 billion processors ×1 billion/s evals?

1 seconds 2 minutes 3 hours 4 years 5 forever Günay

  • Ch. 5, Games!

Spring 2013 9 / 19

slide-42
SLIDE 42

Space Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb) Günay

  • Ch. 5, Games!

Spring 2013 10 / 19

slide-43
SLIDE 43

Space Complexity

For a tree with branching factor, b, and depth, m?

1 O(bm) 2 O(bm) 3 O(mb) Günay

  • Ch. 5, Games!

Spring 2013 10 / 19

slide-44
SLIDE 44

Space Complexity

For a tree with branching 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

slide-45
SLIDE 45

Complexity Reduction?

How to do it?

1 Reduce b 2 Reduce m 3 Tree → graph Günay

  • Ch. 5, Games!

Spring 2013 11 / 19

slide-46
SLIDE 46

Complexity Reduction?

How to do it?

1 Reduce b 2 Reduce m 3 Tree → graph

All of the above!

Günay

  • Ch. 5, Games!

Spring 2013 11 / 19

slide-47
SLIDE 47

Example

defun value(s): if s is : U(s) if s is △: maxValue(s) if s is ▽: 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

slide-48
SLIDE 48

Example

defun value(s): if s is : U(s) if s is △: maxValue(s) if s is ▽: 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

slide-49
SLIDE 49

Reducing Branching Factor, b

Günay

  • Ch. 5, Games!

Spring 2013 13 / 19

slide-50
SLIDE 50

Reducing Branching Factor, b

Günay

  • Ch. 5, Games!

Spring 2013 13 / 19

slide-51
SLIDE 51

Reducing Branching Factor, b

Günay

  • Ch. 5, Games!

Spring 2013 13 / 19

slide-52
SLIDE 52

Reducing Branching Factor, b

Günay

  • Ch. 5, Games!

Spring 2013 13 / 19

slide-53
SLIDE 53

Reducing Branching Factor, b

Which one to prune?

Günay

  • Ch. 5, Games!

Spring 2013 13 / 19

slide-54
SLIDE 54

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 experience In 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

slide-55
SLIDE 55

Formalize as Alpha-Beta Pruning

defun value(s): cutoff at depth m′: eval(s) if s is : U(s) if s is △: maxValue(s, depth, α, β) if s is ▽: minValue(s, depth, α, β) where α, β are overall max and min values, resp.

Günay

  • Ch. 5, Games!

Spring 2013 15 / 19

slide-56
SLIDE 56

Formalize as Alpha-Beta Pruning

defun value(s): cutoff at depth m′: eval(s) if s is : U(s) if s is △: maxValue(s, depth, α, β) if s is ▽: 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)

Günay

  • Ch. 5, Games!

Spring 2013 15 / 19

slide-57
SLIDE 57

Formalize as Alpha-Beta Pruning

defun value(s): cutoff at depth m′: eval(s) if s is : U(s) if s is △: maxValue(s, depth, α, β) if s is ▽: 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)

Günay

  • Ch. 5, Games!

Spring 2013 15 / 19

slide-58
SLIDE 58

Formalize as Alpha-Beta Pruning

defun value(s): cutoff at depth m′: eval(s) if s is : U(s) if s is △: maxValue(s, depth, α, β) if s is ▽: 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

slide-59
SLIDE 59

Complexity Reduction by Tree → Graph

Convert into graph search problem: to reach special opening and closing states to make and protect from killer-moves

Günay

  • Ch. 5, Games!

Spring 2013 16 / 19

slide-60
SLIDE 60

Complexity Reduction by Tree → Graph

Convert into graph search problem: to reach special opening and closing states to make and protect from killer-moves Utility: How many food particles can pacman eat?

Günay

  • Ch. 5, Games!

Spring 2013 16 / 19

slide-61
SLIDE 61

Complexity Reduction by Tree → Graph

Convert into graph search problem: to reach special opening and closing states to make and protect from killer-moves Utility: How many food particles can pacman eat?

Günay

  • Ch. 5, Games!

Spring 2013 16 / 19

slide-62
SLIDE 62

Complexity Reduction by Tree → Graph

Convert into graph search problem: to reach special opening and closing states to 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

slide-63
SLIDE 63

Stochastic Games

Günay

  • Ch. 5, Games!

Spring 2013 17 / 19

slide-64
SLIDE 64

Stochastic Games

defun value(s): cutoff at depth m′: eval(s) if s is : U(s) if s is △: maxValue(s, depth, α, β) if s is ▽: minValue(s, depth, α, β) if s is ?: expValue(s, depth, α, β)

Günay

  • Ch. 5, Games!

Spring 2013 18 / 19

slide-65
SLIDE 65

Coin-flip Game

Günay

  • Ch. 5, Games!

Spring 2013 19 / 19

slide-66
SLIDE 66

Coin-flip Game

Günay

  • Ch. 5, Games!

Spring 2013 19 / 19