Game Playing Part 1 Minimax Search Yingyu Liang yliang@cs.wisc.edu - - PowerPoint PPT Presentation

game playing
SMART_READER_LITE
LIVE PREVIEW

Game Playing Part 1 Minimax Search Yingyu Liang yliang@cs.wisc.edu - - PowerPoint PPT Presentation

Game Playing Part 1 Minimax Search Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison [based on slides from A. Moore http://www.cs.cmu.edu/~awm/tutorials , C. Dyer, J. Skrentny, Jerry Zhu] slide 1


slide-1
SLIDE 1

slide 1

Game Playing

Part 1 Minimax Search

Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison

[based on slides from A. Moore http://www.cs.cmu.edu/~awm/tutorials , C. Dyer, J. Skrentny, Jerry Zhu]

slide-2
SLIDE 2

slide 2

Sadly, not these games (not in this course) …

slide-3
SLIDE 3

slide 3

Overview

  • two-player zero-sum discrete finite deterministic

game of perfect information

  • Minimax search
  • Alpha-beta pruning
  • Large games
  • two-player zero-sum discrete finite NON-deterministic

game of perfect information

slide-4
SLIDE 4

slide 4

Two-player zero-sum discrete finite deterministic games of perfect information

Definitions:

  • Zero-sum: one player’s gain is the other player’s loss.

Does not mean fair.

  • Discrete: states and decisions have discrete values
  • Finite: finite number of states and decisions
  • Deterministic: no coin flips, die rolls – no chance
  • Perfect information: each player can see the

complete game state. No simultaneous decisions.

slide-5
SLIDE 5

slide 5

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

slide-6
SLIDE 6

slide 6

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

slide-7
SLIDE 7

slide 7

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

Zero-sum: one player’s gain is the other player’s loss. Does not mean fair. Discrete: states and decisions have discrete values

slide-8
SLIDE 8

slide 8

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

Zero-sum: one player’s gain is the other player’s loss. Does not mean fair. Discrete: states and decisions have discrete values Finite: finite number of states and decisions

slide-9
SLIDE 9

slide 9

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

Zero-sum: one player’s gain is the other player’s loss. Does not mean fair. Discrete: states and decisions have discrete values Finite: finite number of states and decisions Deterministic: no coin flips, die rolls – no chance

slide-10
SLIDE 10

slide 10

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

Zero-sum: one player’s gain is the other player’s loss. Does not mean fair. Discrete: states and decisions have discrete values Finite: finite number of states and decisions Deterministic: no coin flips, die rolls – no chance Perfect information: each player can see the complete game state. No simultaneous decisions.

slide-11
SLIDE 11

slide 11

Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?

[Shamelessly copied from Andrew Moore]

Zero-sum: one player’s gain is the other player’s loss. Does not mean fair. Discrete: states and decisions have discrete values Finite: finite number of states and decisions Deterministic: no coin flips, die rolls – no chance Perfect information: each player can see the complete game state. No simultaneous decisions.

slide-12
SLIDE 12

slide 13

II-Nim: Max simple game

  • There are 2 piles of sticks. Each pile has 2 sticks.
  • Each player takes one or more sticks from one pile.
  • The player who takes the last stick loses.

(ii, ii)

slide-13
SLIDE 13

slide 14

II-Nim: Max simple game

  • There are 2 piles of sticks. Each pile has 2 sticks.
  • Each player takes one or more sticks from one pile.
  • The player who takes the last stick loses.

(ii, ii)

  • Two players: Max and Min
  • If Max wins, the score is +1; otherwise -1
  • Min’s score is –Max’s
  • Use Max’s as the score of the game
slide-14
SLIDE 14

slide 15

The game tree for II-Nim

(ii ii) Max Convention: score is w.r.t. the first player Max. Min’s score = – Max who is to move at this state

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-15
SLIDE 15

slide 16

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min Symmetry (i ii) = (ii i)

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-16
SLIDE 16

slide 17

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-17
SLIDE 17

slide 18

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-18
SLIDE 18

slide 19

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-19
SLIDE 19

slide 20

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

(- i) Min

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-20
SLIDE 20

slide 21

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

(- i) Min (- -) Min

  • 1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-21
SLIDE 21

slide 22

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

(- i) Min (- -) Min

  • 1

(- -) Min

  • 1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-22
SLIDE 22

slide 23

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

(- i) Min (- -) Min

  • 1

(- -) Min

  • 1

(- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-23
SLIDE 23

slide 24

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min (- -) Min

  • 1

(- i) Min (- -) Min

  • 1

(- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

slide-24
SLIDE 24

slide 25

Game theoretic value

  • Game theoretic value (a.k.a. minimax value) of a

node = the score of the terminal node that will be reached if both players play optimally.

slide-25
SLIDE 25

slide 26

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max (- ii) Max (- i) Max (- i) Max (- -) Max +1 (- i) Min +1 (- -) Min

  • 1

(- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

(- -) Min

  • 1

(- i) Min +1

slide-26
SLIDE 26

slide 27

The game tree for II-Nim

(ii ii) Max (i ii) Min (- ii) Min (i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- i) Min +1 (- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

(- -) Min

  • 1

(- -) Min

  • 1
slide-27
SLIDE 27

slide 28

The game tree for II-Nim

(ii ii) Max (i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- i) Min +1 (- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

(- -) Min

  • 1

(- -) Min

  • 1

(- ii) Min

  • 1

(i ii) Min -

  • 1
slide-28
SLIDE 28

slide 29

The game tree for II-Nim

(i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- i) Min +1 (- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

(- -) Min

  • 1

(- -) Min

  • 1

(- ii) Min

  • 1

(i ii) Min -

  • 1

(ii ii) Max

  • 1
slide-29
SLIDE 29

slide 30

The game tree for II-Nim

(i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- i) Min +1 (- -) Min

  • 1

(- -) Max +1 (- -) Max +1

Two players: Max and Min Max wants the largest score Min wants the smallest score

(- -) Min

  • 1

(- -) Min

  • 1

(- ii) Min

  • 1

(i ii) Min -

  • 1

(ii ii) Max

  • 1
slide-30
SLIDE 30

slide 31

The game tree for II-Nim

(ii ii) Max

  • 1

(i ii) Min

  • 1

(- ii) Min

  • 1

(i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- -) Min - 1 (- i) Min +1 (- -) Min

  • 1

(- -) Min - 1 (- -) Max +1 (- -) Max +1 Symmetry (i ii) = (ii i) Convention: score is w.r.t. the first player Max. Min’s score = – Max who is to move at this state

Two players: Max and Min Max wants the largest score Min wants the smallest score The first player always loses, if the second player plays optimally

slide-31
SLIDE 31

slide 32

Game theoretic value

  • Game theoretic value (a.k.a. minimax value) of a

node = the score of the terminal node that will be reached if both players play optimally.

  • = The numbers we filled in.
  • Computed bottom up

▪ In Max’s turn, take the max of the children (Max will pick that maximizing action) ▪ In Min’s turn, take the min of the children (Min will pick that minimizing action)

  • Implemented as a modified version of DFS: minimax

algorithm

slide-32
SLIDE 32

slide 33

Minimax algorithm

function Max-Value(s) inputs: s: current state in game, Max about to play

  • utput: best-score (for Max) available from s

if ( s is a terminal state ) then return ( terminal value of s ) else α := –  for each s’ in Succ(s) α := max( α , Min-value(s’)) return α function Min-Value(s)

  • utput: best-score (for Min) available from s

if ( s is a terminal state ) then return ( terminal value of s) else β :=  for each s’ in Succs(s) β := min( β , Max-value(s’)) return β

  • Time complexity?
  • Space complexity?
slide-33
SLIDE 33

slide 34

Minimax algorithm

function Max-Value(s) inputs: s: current state in game, Max about to play

  • utput: best-score (for Max) available from s

if ( s is a terminal state ) then return ( terminal value of s ) else α := –  for each s’ in Succ(s) α := max( α , Min-value(s’)) return α function Min-Value(s)

  • utput: best-score (for Min) available from s

if ( s is a terminal state ) then return ( terminal value of s) else β :=  for each s’ in Succs(s) β := min( β , Max-value(s’)) return β

  • Time complexity?

O(bm)  bad

  • Space complexity?

O(bm)

slide-34
SLIDE 34

slide 35

Minimax example

A O W

  • 3

B N

4

F G

  • 5

X

  • 5

E D C R P

9

Q

  • 6

S

3

T

5

U

  • 7

V

  • 9

K M H

3

I

8

J L

2

max min max min max What are the game theoretic values? In particular, A’s

slide-35
SLIDE 35

slide 37

Against a dumber opponent?

  • Max surely loses!
  • If Min not optimal,
  • Which way?
  • Why?

(ii ii) Max

  • 1

(i ii) Min

  • 1

(- ii) Min

  • 1

(i i) Max +1 (- ii) Max +1 (- i) Max

  • 1

(- i) Max

  • 1

(- -) Max +1 (- i) Min +1 (- -) Min

  • 1

(- i) Min +1 (- -) Min

  • 1

(- -) Min

  • 1

(- -) Max +1 (- -) Max +1