Docsity

Minimax and Alpha-Beta Reduction: Optimal Game Strategies, Essays (university) of Abnormal Psychology

Partial preview of the text

Download Minimax and Alpha-Beta Reduction: Optimal Game Strategies and more Essays (university) Abnormal Psychology in PDF only on Docsity!

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

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

 The positions of all the pieces

 Whose turn it is

●

Operators

 Legal moves the player can make

●

Terminal Test

 Determines if a state is a final state

●

Utility Function

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

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

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

F(S)=1 F(S)=

F(S)= F(S)=1 F(S)= MAX MIN

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

Algorithm

N = 4

K =

K = K = K = K = K = K =

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

F(S)=0 1 F(S)=0 F(S)=

F(S)= F(S)= F(S)=1 F(S)= MAX MIN α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β = α = β =

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

Example

N = 2 K = 8. K = 5 K = 11 K = 2 K = 7 K = .45 + .611 = 8. Random Node K = .42 + .67 = 5 0 1 0 1 Weighted coin .6 Heads (1) .4 Tails (0)