CPSC 335 - PowerPoint PPT Presentation

About This Presentation
Title:

CPSC 335

Description:

In chess, both players know where the pieces are, they alternate moves, and they ... A chess program selects moves via use of a search function. ... – PowerPoint PPT presentation

Number of Views:81
Avg rating:3.0/5.0
Slides: 16
Provided by: MarinaGa
Category:
Tags: cpsc | chess

less

Transcript and Presenter's Notes

Title: CPSC 335


1
CPSC 335
  • Search Strategies

2
Search strategies
  • Tries for word searchers, spell checking,
    spelling corrections
  • Digital Search Trees for searching for frequent
    keys (in text, databases, applications)
  • Min-max search for optimal move search in
    games
  • Alpha-beta pruning improvement of min-max
    search
  • Branch-and-bound algorithmic technique to limit
    the search

3
Min-Max search
  • In chess, both players know where the pieces are,
    they alternate moves, and they are free to make
    any legal move.  The object of the game is to
    checkmate the other player, to avoid being
    checkmated, or to achieve a draw if that's the
    best thing given the circumstances.
  • A chess program selects moves via use of a search
    function.  A search function is a function that
    is passed information about the game, and tries
    to find the best move for side that the program
    is playing.

4
Min-Max search
  • Min-max search is used on a B-tree like structure
    representing the space of all possible moves.
    Initial state of every game is a large B-tree,
    then a tree-search finds the move that would be
    selected if both sides were to play the best
    possible moves. 

5
The algorithm
  • Let's say that at the root position (the position
    on the board now), it's White's turn to move. 
    The Max function is called, and all of White's
    legal moves are generated.  In each resulting
    position, the "Min" function is called.  The
    "Min" function scores the position and returns a
    value.  Since it is White to move, and White
    wants a more positive score if possible, the move
    with the largest score is selected as best, and
    the value of this move is returned.
  • The "Min" function works in reverse.  The "Min"
    function is called when it's Black's turn to
    move, and black wants a more negative score, so
    the move with the most negative score is
    selected.
  • These functions are dual recursive, meaning that
    they call each other until the desired search
    depth is reached.  When the functions "bottom
    out", they return the result of the "Evaluate"
    function.

6
Alpha-beta pruning
  • Alpha - Beta Pruning
  • a technique that improves upon the minimax
    algorithm by ignoring branches on the game tree
    that do not contribute further to the outcome.

7
Idea
  • The basic idea behind this modification to the
    minimax search algorithm is the following. During
    the process of searching for the next move, not
    every move (i.e. every node in the search tree)
    needs to considered in order to reach a correct
    decision.
  • In other words, if the move being considered
    results in a worse outcome than our current best
    possible choice, then the first move that the
    opposition could make which is less then our best
    move will be the last move that we need to look
    at.

8
Example
9
Pseudo-code
  • function Max-Value(state, game, , ß) returns the
    mimimax value of state
  • inputs
  • state, current state in the gamegame, game
    description, the best score for MAX along the
    path to stateß, the best score for MIN along the
    path to state
  • if CUTOFF-TEST(state) then return EVAL(state)for
    each s in SUCCESSORS(state) do
  • ß then
    return ß
  • endreturn
  • function Min-Value(state, game, , ß) returns the
    mimimax value of state
  • if CUTOFF-TEST(state) then return EVAL(state)for
    each s in SUCCESSORS(state) do
  • ß return
  • endreturn ß

10
Algorithm performance
  • With the previously listed assumptions taken into
    account the following gains\improvements can be
    calculated.
  • With Alpha-Beta Pruning the number of nodes on
    average that need to be examined is O(bd/2) as
    opposed to the Minimax algorithm which must
    examine 0(bd) nodes to find the best move. In the
    worst case Alpha-Beta will have to examine all
    nodes just as the original Minimax algorithm
    does. But assuming a best case result this means
    that the effective branching factor is b(1/2)
    instead of b.
  • For a chess game, which normally has a branching
    factor of 35, the branching factor will be
    reduced to 6! It means that a chess program
    running Alpha - Beta could look ahead twice as
    far in the same amount of time, improving the
    skill level of our chess program from a novice to
    an expert level player.

11
Branch-and-bound
  • Definition An algorithmic technique to find the
    optimal solution by keeping the best solution
    found so far. If a partial solution cannot
    improve on the best, it is abandoned.

12
Branch-and-bound
  • For instance, suppose we want to find the
    shortest route from Zarahemla to Manti, and at
    some time the shortest route found until that
    time is 387 kilometers. Suppose we are to next
    consider routes through Cumeni. If the shortest
    distance from Zarahemla to Cumeni is 350 km and
    Cumeni is 46 km from Manti in a straight line,
    there is no reason to explore possible roads from
    Cumeni they will be at least 396 km (350 46),
    which is worse than the shortest known route. So
    we need not explore paths from Cumeni.

13
Branch-and-bound
  • The method can be implemented as a backtracking
    algorithm, which is a modified depth-first
    search, or using a priority queue ordering
    partial solutions by lower bounds.

14
Applications
  • Chess
  • Checkers
  • Tic-tac-toe
  • Other games

15
Evolution
Write a Comment
User Comments (0)
About PowerShow.com