game playing - github pages
TRANSCRIPT
![Page 1: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/1.jpg)
slide 1
Game PlayingPart 1 Minimax Search
Yingyu [email protected]
Computer Sciences DepartmentUniversity of Wisconsin, Madison
[based on slides from A. Moore, C. Dyer, J. Skrentny, Jerry Zhu]
![Page 2: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/2.jpg)
slide 2
Not playing these games (not in this course) …
![Page 3: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/3.jpg)
slide 3
Instead, learn principles of how machines play
![Page 4: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/4.jpg)
slide 4
Overview• Important characteristics of games two-player zero-sum discrete finite deterministic
game of perfect information• Minimax search• Alpha-beta pruning
![Page 5: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/5.jpg)
slide 5
Game Examples
![Page 6: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/6.jpg)
slide 6
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.
![Page 7: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/7.jpg)
slide 7
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
![Page 8: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/8.jpg)
slide 8
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
![Page 9: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/9.jpg)
slide 9
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
Zero-sum: one player’s gain is the other player’s loss. Does not mean fair.
![Page 10: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/10.jpg)
slide 10
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
Zero-sum: one player’s gain is the other player’s loss. Does not mean fair.
Discrete: states and decisions have discrete values
![Page 11: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/11.jpg)
slide 11
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
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
![Page 12: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/12.jpg)
slide 12
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
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
![Page 13: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/13.jpg)
slide 13
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
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.
![Page 14: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/14.jpg)
slide 14
Which of these are: Two-player zero-sum discrete finite deterministic games of perfect information?
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.
![Page 15: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/15.jpg)
slide 16
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)
![Page 16: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/16.jpg)
slide 17
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
![Page 17: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/17.jpg)
slide 18
II-Nim: one trajectory of the game(ii, ii)
![Page 18: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/18.jpg)
slide 19
II-Nim: one trajectory of the game(ii, ii)
Max takes one stick from one pile
(i, ii)
![Page 19: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/19.jpg)
slide 20
II-Nim: one trajectory of the game(ii, ii)
Max takes one stick from one pile
(i, ii)Min takes two sticks from the other pile
(i,-)
![Page 20: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/20.jpg)
slide 21
II-Nim: one trajectory of the game(ii, ii)
Max takes one stick from one pile
(i, ii)Min takes two sticks from the other pile
(i,-)Max takes the last stick
(-,-)Max gets score -1
![Page 21: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/21.jpg)
slide 22
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 scoreMin wants the smallest score
![Page 22: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/22.jpg)
slide 23
The game tree for II-Nim
(ii ii) Max
(i ii) Min (- ii) MinSymmetry(i ii) = (ii i)
Two players: Max and Min
Max wants the largest scoreMin wants the smallest score
![Page 23: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/23.jpg)
slide 24
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 scoreMin wants the smallest score
![Page 24: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/24.jpg)
slide 25
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 scoreMin wants the smallest score
![Page 25: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/25.jpg)
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 (- -) Min-1
Two players: Max and Min
Max wants the largest scoreMin wants the smallest score
![Page 26: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/26.jpg)
slide 27
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 scoreMin wants the smallest score
![Page 27: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/27.jpg)
slide 28
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 scoreMin wants the smallest score
![Page 28: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/28.jpg)
slide 29
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 scoreMin wants the smallest score
![Page 29: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/29.jpg)
slide 30
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 scoreMin wants the smallest score
![Page 30: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/30.jpg)
slide 31
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 scoreMin wants the smallest score
![Page 31: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/31.jpg)
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.
![Page 32: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/32.jpg)
slide 33
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 scoreMin wants the smallest score
![Page 33: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/33.jpg)
slide 34
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 scoreMin wants the smallest score
(- -) Min-1
(- i) Min+1
![Page 34: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/34.jpg)
slide 35
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 scoreMin wants the smallest score
(- -) Min-1
(- -) Min-1
![Page 35: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/35.jpg)
slide 36
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 scoreMin wants the smallest score
(- -) Min-1
(- -) Min-1
(- ii) Min -1
(i ii) Min -1
![Page 36: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/36.jpg)
slide 37
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 scoreMin wants the smallest score
(- -) Min-1
(- -) Min-1
(- ii) Min -1
(i ii) Min -1
(ii ii) Max -1
![Page 37: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/37.jpg)
slide 38
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 scoreMin wants the smallest score
(- -) Min-1
(- -) Min-1
(- ii) Min -1
(i ii) Min -1
(ii ii) Max -1
![Page 38: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/38.jpg)
slide 39
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
Two players: Max and Min
Max wants the largest scoreMin wants the smallest score
The first player always loses, if the second player plays optimally
![Page 39: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/39.jpg)
slide 40
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
Two players: Max and Min
Max wants the largest scoreMin wants the smallest score
The first player always loses, if the second player plays optimally
![Page 40: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/40.jpg)
slide 42
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
![Page 41: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/41.jpg)
slide 43
Minimax algorithmfunction Max-Value(s)inputs:
s: current state in game, Max about to playoutput: 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)output: 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?
![Page 42: Game Playing - GitHub Pages](https://reader034.vdocument.in/reader034/viewer/2022051306/62799db15ae7f011f558852a/html5/thumbnails/42.jpg)
slide 44
Minimax algorithmfunction Max-Value(s)inputs:
s: current state in game, Max about to playoutput: 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)output: 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)