games: efficiency

44
Games: Efficiency Andrea Danyluk September 23, 2013

Upload: nelia

Post on 22-Feb-2016

56 views

Category:

Documents


0 download

DESCRIPTION

Games: Efficiency. Andrea Danyluk September 23, 2013. Announcements. Programming Assignment 1: Search Autograding done Please sign up for a code review Programming Assignment 2: Games Remove your print statements before turning it in - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Games: Efficiency

Games:Efficiency

Andrea DanylukSeptember 23, 2013

Page 2: Games: Efficiency

Announcements

• Programming Assignment 1: Search– Autograding done– Please sign up for a code review

• Programming Assignment 2: Games– Remove your print statements before turning it in– Need help with buggy code? If I’m not in the

office, email me your code and a description of the problem.

Page 3: Games: Efficiency

Today’s Lecture

• Heuristic evaluation functions for minimax• Making the search more efficient:– α-β pruning

Page 4: Games: Efficiency

Minimax Reality• Can rarely explore entire search space to terminal nodes.• Choose a depth cutoff – i.e., a maximum ply• Need an evaluation function

– Returns an estimate of the expected utility of the game from a given position

– Must order the terminal states in the same way as the true utility function

– Must be efficient to compute• Trading off plies for heuristic computation• More plies makes a difference

• Consider iterative deepening

Page 5: Games: Efficiency

Evaluation Functions

• Ideal: returns the utility of the position• In practice: typically weighted linear sum of

features:• Eval(s) = w1f1(s) + w2f2(s) + … + wnfn(s)

Page 6: Games: Efficiency

Exercise

• Evaluation function for Connect Four?

Page 7: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

Page 8: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7

Page 9: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

Page 10: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

Page 11: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

Wow! 0 is a great score!

Page 12: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

I wonder if I can do even

better!

Page 13: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

Too bad the maximizer

won’t ever let me get here!

Page 14: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

Better not to waste my

time!

Page 15: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

Page 16: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

Page 17: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

Page 18: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

9

Wow! 9!

Page 19: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

9

Oh, wait!

Page 20: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

9

Min won’t let

me go here!

Page 21: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

9

Min won’t let

me go here!

6

Page 22: Games: Efficiency

An earlier example revisited

7 26 3 0 6-2 52 96 2

7 3

3

0

0

6

9

Min won’t let

me go here!

6

Page 23: Games: Efficiency

α-β Pruning

• If something looks too good to be true, it probably is.

• One example of the class of branch and bound algorithms with two bounds– α : the value of the best choice for Max– β : the value of the best choice for min

Page 24: Games: Efficiency

α-β Pruning

• Given these two bounds– α : the value of the best choice for Max– β : the value of the best choice for min

• Basic idea of the algorithm– On a minimizing level, if you find a value < α, cut

the search– On a maximizing level, if you find a value > β, cut

the search

Page 25: Games: Efficiency

function αβSEARCH(state) returns an action a v = MAX-VALUE(state, -infinity, +infinity)

return action a in ACTIONS(state) with value v

function MAX-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = -infinity for each a in ACTIONS(state) do v = MAX(v, MIN-VALUE(RESULT(state, a), α, β)) if v ≥ β then return v α = MAX(α, v) return v

function MIN-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = infinity for each a in ACTIONS(state) do v = MIN(v, MAX-VALUE(RESULT(state, a), α, β)) if v ≤ α then return v β = MIN(β, v) return v

Page 26: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

Page 27: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = +inf

Page 28: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = +inf

α = -infΒ = +inf

Page 29: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = +inf

α = 8Β = +inf

Page 30: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = +inf

8

Page 31: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = 8

8

Page 32: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = 8

8α = -infΒ = 8

Page 33: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

α = -infΒ = 8

8 9

Page 34: Games: Efficiency

8 47 381911

2

619 5

α = -infΒ = +inf

8

8 9

Page 35: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

Page 36: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

α = 8Β = +inf

Page 37: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2

Page 38: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2α = 8Β = +inf

Page 39: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2α = 8Β = +inf

α = 8Β = +inf

Page 40: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2α = 8Β = +inf

α = 8Β = +inf

Page 41: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2α = 8Β = +inf

8

Page 42: Games: Efficiency

8 47 381911

2

619 5

α = 8Β = +inf

8

8 9

2α = 8Β = +inf

8

Is there a problem here???

Page 43: Games: Efficiency

function αβSEARCH(state) returns an action a v = MAX-VALUE(state, -infinity, +infinity)

return action a in ACTIONS(state) with value v

function MAX-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = -infinity for each a in ACTIONS(state) do v = MAX(v, MIN-VALUE(RESULT(state, a), α, β)) if v ≥ β then return v α = MAX(α, v) return v

function MIN-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = infinity for each a in ACTIONS(state) do v = MIN(v, MAX-VALUE(RESULT(state, a), α, β)) if v ≤ α then return v β = MIN(β, v) return v

Page 44: Games: Efficiency

Properties of α-β

• Pruning does not affect the final result (but be careful)

• Good move ordering improves effectiveness of pruning

• If search depth is d, what is the time complexity of minimax?– O(bd)

• With perfect pruning, get down to O(b d/2)– Doubles solvable depth

[Adapted from Russell]