You are on page 1of 8

GAME PLAYING

(MINIMAX ALGORITHM)

Dr. Jasmeet Singh


CSED, TIET
GAME PLAYING ALGORITHMS
The game playing algorithms primarily focus on the
games with following characteristics:
Two players
Alternate moves
Zero sum
Complete Information
Deterministic moves
Zero sum means that if one player wins then other
loses or the game draws. So, the scores are 1,-1 and 0
for winning, losing, and draw respectively.
Deterministic games means that there is no elements
of chance. For example, tic-tac-toe or chess. But dice
games or card games are non-deterministic in nature,
GAME TREE
A game is represented by a game tree.
A game tree is a layered tree in which at each
alternating level, one or the other player make
choices.
The layers are called MAX and MIN layers.
Traditionally MAX nodes are represented as squares
and MIN nodes are represented as circles.
The game starts at the root with usually MAX playing
first and ends at the leaf node.
All the leaf nodes are labeled with their utility/
heuristic values.
These values are seen from the perspective of MAX
player.
GAME TREE CONTD…

For instance leaf can be labeled as:

Due to this reason only, the players are named as


MAX ( one who prefers the maximum valued outcome)
and other MIN (one who prefers minimum valued
outcome)
Given a game tree, we can analyze the game and
determine the outcome when both players play
perfectly using MINIMAX algorithm.
MINIMAX ALGORITHM

The MINIMAX algorithm works as follows:


1) Generate the game tree from the current position till
the leaf nodes.
2) Compute the heuristic values of the leaf nodes.

3) Propagate the values to the current position on the


basis of players:
a. If the node is a MAX node, backup the maximum of the
values of its children.
b. If the node is a MIN node, backup the minimum of the
values of its children
EXAMPLE – TIC-TAC-TOE

Consider TIC-TAC-TOE. Assume MAX puts a X


and MIN puts a 0. Calculate the next step of
MAX using MINIMAX procedure. State the
heuristic used.
X 0 X
0 0 X
SOLUTION
Let the heuristic be:

Where M is number of rows/columns/diagonals


available for MAX winning and N is number of
rows/columns/diagonals available for MIN
winning
SOLUTION

You might also like