0% found this document useful (0 votes)
65 views22 pages

Minimax and Alpha-Beta Reduction: Borrows From Spring 2006 CS 440 Lecture Slides

Minimax and Alpha-Beta Reduction are algorithms used to find the best move for games. Minimax searches a game tree to find the optimal move assuming the opponent plays optimally. Alpha-Beta Reduction prunes parts of the tree that don't affect the result, speeding up Minimax. It uses alpha and beta values to avoid searching subtrees where the result is already known. This allows games like chess to be played by computer in a reasonable time despite the large search space.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views22 pages

Minimax and Alpha-Beta Reduction: Borrows From Spring 2006 CS 440 Lecture Slides

Minimax and Alpha-Beta Reduction are algorithms used to find the best move for games. Minimax searches a game tree to find the optimal move assuming the opponent plays optimally. Alpha-Beta Reduction prunes parts of the tree that don't affect the result, speeding up Minimax. It uses alpha and beta values to avoid searching subtrees where the result is already known. This allows games like chess to be played by computer in a reasonable time despite the large search space.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Minimax and Alpha-Beta Reduction

Borrows from Spring 2006 CS 440 Lecture Slides

Motivation
Want to create programs to play games

Want to play optimally

Want to be able to do this in a reasonable amount of


time

Types of Games
Deterministic

Nondeterministic
(Chance)

Fully
Observable

Chess
Checkers
Go
Othello

Backgammon
Monopoly

Partially
Observable

Battleship

Card Games

Minimax is for deterministic, fully observable games

Basic Idea

Search problem

Searching a tree of the possible moves in order to find


the move that produces the best result
Depth First Search algorithm

Assume the opponent is also playing optimally

Try to guarantee a win anyway!

Required Pieces for Minimax

An initial state

Operators

Legal moves the player can make

Terminal Test

The positions of all the pieces


Whose turn it is

Determines if a state is a final state

Utility Function

Utility Function

Gives the utility of a game state

utility(State)

Examples

-1, 0, and +1, for Player 1 loses, draw, Player 1 wins,


respectively
Difference between the point totals for the two players
Weighted sum of factors (e.g. Chess)

utility(S) = w1f1(S) + w2f2(S) + ... + wnfn(S)

f1(S) = (Number of white queens) (Number of black queens),


w1 = 9
f2(S) = (Number of white rooks) (Number of black rooks),
w2 = 5
...

Two Agents

MAX

Wants to maximize the result of the utility function


Winning strategy if, on MIN's turn, a win is obtainable
for MAX for all moves that MIN can make

MIN

Wants to minimize the result of the evaluation function


Winning strategy if, on MAX's turn, a win is
obtainable for MIN for all moves that MAX can make

Basic Algorithm

Example

Coins game

There is a stack of N coins


In turn, players take 1, 2, or 3 coins from the stack
The player who takes the last coin loses

Coins Game: Formal Definition

Initial State: The number of coins in the stack


Operators:
1. Remove one coin
2. Remove two coins
3. Remove three coins

Terminal Test: There are no coins left on the stack


Utility Function: F(S)

F(S) = 1 if MAX wins, 0 if MIN wins

MAX
MIN

N=4
K=

1
N=3
K=

3
2

3
N=0
K=

2
N=1
K=

F(S)=1

1
N=3
K=

1
N=1
K=

2
N=0
K=

F(S)=0

1
N=0
K=
F(S)=1

F(S)=0

N=2
K=

N=2
K=

N=1
K=

2
N=0
K=

1
N=1
K=

1
N=0
K=

F(S)=1

1
N=0
K=

F(S)=1

F(S)=0

MAX
MIN

1
N=3
K=0

Solution

N=4
K= 1

3
2

3
N=0
K= 1

2
N=1
K=0

F(S)=1

1
N=3
K= 0

1
N=1
K=1

2
N=0
K=0

F(S)=0

1
N=0
K= 1
F(S)=1

F(S)=0

N=2
K=1

N=2
K=0

N=1
K=1

2
N=0
K=1

1
N=1
K=0

1
N=0
K=1

F(S)=1

1
N=0
K=0

F(S)=1

F(S)=0

Analysis

Max Depth: 5
Branch factor: 3
Number of nodes: 15
Even with this trivial example, you can see that
these trees can get very big

Generally, there are O(bd) nodes to search for

Branch factor b: maximum number of moves from each


node
Depth d: maximum depth of the tree

Exponential time to run the algorithm!


How can we make it faster?

Alpha-Beta Pruning

Main idea: Avoid processing subtrees that have


no effect on the result
Two new parameters

: The best value for MAX seen so far


: The best value for MIN seen so far

is used in MIN nodes, and is assigned


in MAX nodes
is used in MAX nodes, and is assigned
in MIN nodes

Alpha-Beta Pruning

MAX (Not at level 0)

If a subtree is found with a value k greater


than the value of , then we do not need to
continue searching subtrees

MAX can do at least as good as k in this node,


so MIN would never choose to go here!

MIN

If a subtree is found with a value k less than


the value of , then we do not need to
continue searching subtrees

MIN can do at least as good as k in this node, so


MAX would never choose to go here!

Algorithm

MAX
MIN

1
N=3 =
K= =

=
=

3
N=0
K=

F(S)=1
=
=

N=4 =
K= =

2
N=1 =
K= =
1
N=3
K=
F(S)=0

2
1

=
=

N=2 =
K= =
1
N=1 =
K= =

3
N=2 =
K= =
2
N=0
K=

2
F(S)=1
N=0 =
K= =

1
F(S)=0
N=0 =
K= =
F(S)=1

=
=

1
N=1 =
K= =

N=1
K=
1
N=0
K=

1
F(S)=1

N=0 =
=
K= =

F(S)=0

MAX
MIN

N=4 =0
K=01 =

=0
=1

= 1
=

3
N=0
K=1

F(S)=1
=0
=1

N=3 =
N=2 =0
K=10 = 10
K = 1 0 = 0
=0
1
2
2
1
=
N=1 =0
N=2 =
N=0
N=1 =0
K=0 = 10 K=1 =0
K=1
K= =0

N=1
K=1
1
N=0
K= 1

1
N=3
K=0

1
2
F(S)=1
N=1 =1 N=0 =
K=1 =0 K= =

1
F(S)=1
N=0 =0 =0
K=0 =0 =

F(S)=0

1
F(S)=0
N=0 =1
K=1 =0
F(S)=1

F(S)=0

Nondeterministic Games

Minimax can also be used for nondeterministic


games (those that have an element of chance)
There is an additional node added (Random node)
Random node is between MIN and MAX (and
vice versa)
Make subtrees over all of the possibilities,and
average the results

Weighted coin
.6 Heads (1)
.4 Tails (0)

Example
N=2
K = 8.6

Random Node

0
K=5

K = .4*5 + .6*11 = 8.6


1
K = 11

K = .4*2 + .6*7 = 5
0
K=2

1
K=7

Our Project

We will focus on deterministic, two-player, fully


observable games
We will be trying to learn the evaluator function,
in order to save time when playing the game

Training on data from Minimax runs (Neural Network)


Having the program play against itself (Genetic
Algorithms)

Conclusion

Minimax finds optimal play for deterministic, fully


observable, two-player games
Alpha-Beta reduction makes it faster

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy