5 Game
5 Game
5 Game
as Search Problem
Tic-Tac-Toe Problem
• Given n x n matrix, the object of the game is to
make three of your symbol in a row, column or
diagonal
– This is a win state for the game.
• One player is designated as player X and makes
the first play by marking an X into any of the n x n
open squares of the board.
– Think a 3 x 3 square board where the player can put an
X in any of the 9 open places
• The second player, "O", then follows suit by
marking an O into any of the other open squares
that remain.
• This continues back-and-forth until one player wins
the game or players fill all squares on the board
without establishing a winner. This is a draw.
Partial Game Tree for Tic-Tac-Toe Problem
Applying MiniMax to tic-tac-toe
• The static evaluation function heuristic
How to play a game
•A way to play a game is to:
–Consider all the legal moves you can make
–Compute the new position resulting from each move
–Evaluate each resulting position and determine which is best
–Make that move
–Wait for your opponent to move and repeat
•Key problems are:
–Representing the “board”
–Generating all legal next boards
–Evaluating a position
•For real problems, the search tree is too big to make it
possible to reach the terminal states
–Example: Chess: 10120 nodes; 8 Puzzle: 105 . How many
nodes to consider in a Tic-Tac-Toe game with 3 x 3 board?
Adversarial Search
• It is used in game playing since one player's attempts
to maximize their fitness (win) is opposed by another
player.
• The search tree in adversarial games such as tic-tac-
toe consist of alternating levels where the moving
(MAX) player tries to maximize fitness and then the
opposing (MIN) player tries to minimize it.
• To find the best move
– The system first generates all possible legal moves, and
applies them to the current board.
– Evaluate each of the positions/states and determine the best
one to move.
– In a game like tic-tac-toe this process is repeated for each
possible move until the game is won, lost, or drawn.
Typical case
• 2-person game: two players alternate moves
e.g. chess playing
• Zero-sum game: one player’s loss is the other’s gain
– The zero-sum assumption allows us to use a single evaluation function to
describe the goodness of a board with respect to both players.
– f(n) > 0: position n good for A and bad for B
– f(n) < 0: position n bad for A and good for B
– f(n) near 0: position n is a neutral position
– f(n) = +infinity: win for A
– f(n) = -infinity: win for B
• Perfect information: both players have access to complete
information about the state of the game. No information is
hidden from either player.
– Board configuration is known completely to both players at all times.
• Any examples of perfect information game:
– Tic-Tac-Toe & Chess.
• Playing cards is not. Cards held by one are not known to others.
Game Tree Search
•Problem spaces for typical games are represented as
trees
•Game tree represents possible moves by both players
given an initial configuration.
– Each node represents a (board) configuration. Ex. Each
node marked by a letter (A, B etc.)
– Root node represents initial configuration
– Children of a node n indicate possible configurations after
the player makes a move from node n
• Ex. B, C, D are children of A. They are possible configurations after
player makes a move from configuration A.
– In case of alternating moves between the players,
alternating levels in a tree have alternating moves.
• Each level of the tree has nodes that are all MAX or all MIN; nodes at
level i are of the opposite kind from those at level i+1.
Example Game tree
•Game between players X and Y. Let us analyze from X's
perspective by looking ahead of two moves.
• H is a winning state for X (marked by plus infinity). If H reached, X wins.
No further moves.
• E, M are losing states for X (marked by minus infinity). If E or M reached,
X loses. No further moves.
MIN
MAX
MIN
MAX
MIN
Alpha-Beta Pruning
• We can improve on the performance of the min-
max algorithm through alpha-beta pruning
MIN
MAX
MIN
MAX
MIN