You are on page 1of 29

GAMES!!!!

Two people games


Solved games
Tic-tac-toe
Four In A Line
Checkers

Impressive games played by robots


Othello bot is much stronger than any human
player
Computer chess beat the human world champions
TD-Gammon ranked among top 3 players in the
backgammon world

Future bot challenges to humans


Poker bots play respectfully at world-class level
Computer bridge programs play competitively at
national level
Go bots are getting more serious in the amateur
ranking

Complete game tree for


Nim-7

7 coins are placed


on a table between
the two opponents
A move consists of
dividing a pile of
coins into two
nonempty piles of
different sizes
For example, 6
coins can be
divided into piles
of 5 and 1 or 4 and
2, but not 3 and 3
The first player
who can no longer
make a move loses

P1 starts

P2 replies

P1

P2

P2 loses
P1

P2 loses

P1 loses

MIN vs. MAX in a Nim game


The best that MIN (Player1) can
do is to lose unless Player2
makes a mistake.

moves first to minimize

to maximize

Node score = 0
means MIN wins.
1 means MAX wins.
Bold edges indicate
forced win for MAX,
Player2.

MIN wins

MAX wins

MIN wins

Minimax to fixed ply depth


Instead of Nim-7, image the chess game tree.
Chess game tree is too deep.
cannot expand the current node to terminating
(leaf) nodes for checkmate.

Use fixed ply depth look-ahead.

Search from current position to all possible


positions that are, e.g., 3-plies ahead.

Use heuristic to evaluate all these future


positions.

P=1, N=B=3, R=5, Q=9


Assign certain weight to certain features of the
position (dominance of the center, mobility of
the queen, etc.)
summarize these factors into a single number.

Then propagating the scores back to the


current node.

Minimax
Create a utility function
Evaluation of board/game state to determine
how strong the position of player 1 is.
Player 1 wants to maximize the utility function
Player 2 wants to minimize the utility function

Minimax tree
Generate a new level for each move
Levels alternate between max (player 1
moves) and min (player 2 moves)

Minimax tree
Max

Min

Max

Min

Minimax Tree Evaluation


Assign utility values to leaves
Sometimes called board evaluation
function
If leaf is a final state, assign the
maximum or minimum possible utility
value (depending on who would win)
If leaf is not a final state, must use
some other heuristic, specific to the
game, to evaluate how good/bad the
state is at that point

Minimax tree
Max

Min

Max

100

Min
23 28

21

-3

12 4

70 -3

-12 -70 -5

-100 -73 -14 -8 -24

Minimax Tree Evaluation


At each min node, assign the
minimum of all utility values at
children
Player 2 chooses the best available
move

At each max node, assign the


maximum of all utility values at
children
Player 1 chooses best available move

Push values from leaves to top of

Minimax tree
Max

Min

Max

28

-3

12

70

-3

100

-73

-14

-8

Min
23 28

21

-3

12 4

70 -3

-12 -70 -5

-100 -73 -14 -8 -24

Minimax tree
Max

Min

Max

-4

-3

21

-3

12

70

-4

-73

100

-73

-14

-8

Min
23 28

21

-3

12 4

70 -4

-12 -70 -5

-100 -73 -14 -8 -24

Minimax tree
Max

-3

Min

Max

-4

-3

21

-3

12

70

-4

-73

100

-73

-14

-8

Min
23 28

21

-3

12 4

70 -4

-12 -70 -5

-100 -73 -14 -8 -24

Minimax Evaluation
Given average branching factor b,
and depth m:
A complete evaluation takes time bm
A complete evaluation takes space bm

Usually, we cannot evaluate the


complete state, since its too big
Instead, we limit the depth based on
various factors, including time
available.

Pruning the Minimax Tree


Since we have limited time available,
we want to avoid unnecessary
computation in the minimax tree.
Pruning: ways of determining that
certain branches will not be useful

Cuts
If the current max value is greater
than the successors min value, dont
explore that min subtree any more

Cut example
Max

-3

Min

Max

-3

21

-3

-4

12

70

-4

-73

100

-73

-14

Cut example
Max

Min

Max

21

-3

12

-70

-4

100

-73

Depth first search along path 1

-14

Cut example
Max

Min

Max

21

21

-3

12

-70

-4

100

-73

-14

21 is minimum so far (second level)


Cant evaluate yet at top level

Cut example
Max

Min

Max

-3

-3

21

-3

12

-70

-4

100

-73

-14

-3 is minimum so far (second level)


-3 is maximum so far (top level)

Cut example
Max

Min

Max

-3

12

-3

21

-3

12

-70

-4

100

-73

-14

12 is minimum so far (second level)


-3 is still maximum (cant use second
node yet)

Cut example
Max

Min

Max

-3

-70

-3

21

-3

12

-70

-4

100

-73

-14

-70 is now minimum so far (second level)


-3 is still maximum (cant use second
node yet)

Cut example
Max

Min

Max

-3

-70

-3

21

-3

12

-70

-4

100

-73

-14

Since second level node will never be > -70,


it will never be chosen by the previous level
We can stop exploring that node

Cut example
Max

Min

Max

-3

-70

-3

21

-3

12

-73

-70

-4

100

-73

-14

Evaluation at second level is -73

Cut example
Max

Min

Max

-3

-70

-3

21

-3

12

-73

-70

-4

100

-73

-14

Again, can apply cut since the


second level node will never be >
-73, and thus will never be chosen by
the previous level

Cut example
Max

Min

Max

-3

-70

-3

21

-3

12

-73

-70

-4

100

-73

-14

As a result, we evaluated the Max


node without evaluating several of
the possible paths

cuts
Similar idea to cuts, but the other
way around
If the current minimum is less than
the successors max value, dont look
down that max tree any more

Cut example
Min

Max

Min

21

21

21

70

-3

12

73

70

-4

100

73

-14

Some subtrees at second level


already have values > min from
previous, so we can stop evaluating
them.

Tic tac Toe

You might also like