Best First Search and MiniMax - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Best First Search and MiniMax

Description:

V(P) = maxi V(Pi) if P is a MAX-to-move position ... This is not applicable for most games. ... regarding the side should be in Pos (max's turn or min's turn) ... – PowerPoint PPT presentation

Number of Views:258
Avg rating:3.0/5.0
Slides: 17
Provided by: Maj754
Category:
Tags: minimax | best | first | games | max | search

less

Transcript and Presenter's Notes

Title: Best First Search and MiniMax


1
Best First Searchand MiniMax
  • Comp 472/6721
  • Majid Razmara

2
Queue
  • A queue is a first-in-first-out (FIFO) data
    structure
  • It is characterized as a list
  • add_to_queue(E, , E). (enqueue)
  • add_to_queue(E, HT, HT2) - add_to_queue(E,
    T, T2).
  • adds a new element to the back of the queue
  • remove_from_queue(E, ET, T). (dequeue)
  • removes the next element from the queue

3
Priority Queue
  • insert_sort_queue(State, , State).
  • insert_sort_queue(State, H T, State, H T)
    - precedes(State, H).
  • insert_sort_queue(State, H T, H T_new) -
    insert_sort_queue(State, T, T_new).

4
Definition
  • Best First Search
  • Open list
  • Priority Queue
  • Close list
  • Set
  • Heuristic
  • Algorithm A
  • Evaluation Function
  • F G H

5
Best First Search
  • state_record(State, Parent, G, H, F, State,
    Parent, G, H, F).
  • precedes( _,_,_,_,F1 , _,_,_,_,F2 ) - F1
    lt F2.
  • go(Start, Goal) -
  • Closed ,
  • heuristic( Start, Goal, H),
  • state_record( Start, nil, 0, H, H,
    First_record),
  • insert_sort_queue( First_record, , Open),
  • best_first ( Open, Closed, Goal).
  • go initializes Open and Closed and calls path
  • best_first performs a best first search,
    maintaining Open as a priority queue, and Closed
    as a set.

6
Best First Search (Contd)
  • best_first (Open, Closed, Goal)
  • Case 1 Open is empty no solution found
  • best_first( , _, _) - write("graph searched,
    no solution found").
  • Case 2 The next record is a goal. print out the
    list of visited states.
  • best_first(Open, Closed, Goal) -
  • remove_sort_queue(Next_record, Open, _ ),
  • state_record(State, _, _, _, _, Next_record),
  • State Goal,
  • write('Solution path is '), nl,
  • printsolution(Next_record, Closed).

7
Best First Search (Contd)
  • Case 3 The next record is not the goal.
    Generate its children, add to open and continue.
  • best_first(Open, Closed, Goal) -
  • remove_sort_queue(Next_record, Open,
    Rest_of_open),
  • findall( Child, moves(Next_record, Open, Closed,
    Child, Goal), Children ),
  • insert_list(Children, Rest_of_open, New_open),
  • add_to_set(Next_record, Closed, New_closed),
  • best_first (New_open, New_closed, Goal).

8
Best First Search (Contd)
  • moves generates one child of a state that is not
    already on open or closed.
  • moves(State_record, Open, Closed, Child, Goal) -
  • state_record(State, _, G, _,_, State_record),
  • mov(State, Next),
  • state_record(Next, _, _, _, _, Test),
  • not(member(Test, Open)),
  • not(member(Test, Closed)),
  • G_new is G 1,
  • heuristic(Next, Goal, H),
  • F is G_new H,
  • state_record(Next, State, G_new, H, F, Child).

9
Best First Search (Contd)
  • insert_list inserts a list of states obtained
    from a call to bagof and inserts them in a
    priority queue, one at a time
  • insert_list ( , L, L).
  • insert_list (H T, L, New_L) -
  • insert_sort_queue(H, L, L2), insert_list(T, L2,
    New_L).
  • add_to_set adds an element to a set if the
    element is not already in the set
  • add_to_set (X, S, S) - member(X, S), !.
  • add_to_set (X, S, XS).

10
Best First Search (Contd)
  • Printsolution prints out the solution path by
    tracing back through the states on closed using
    parent links.
  • printsolution(Next_record, _)-
  • state_record(State, nil, _, _,_,
    Next_record), write(State), nl.
  • printsolution(Next_record, Closed) -
  • state_record(State, Parent, _, _,_,
    Next_record),
  • state_record(Parent, _, _, _, _, Parent_record),
  • member(Parent_record, Closed),
  • printsolution(Parent_record, Closed),
  • write(State), nl.

11
Example
12
MiniMax
  • Two heuristic values
  • Terminal-level values ? static value
  • Backed-up values ? dynamic values
  • Let P1 Pn be legal successor positions of P
  • The backed-up value of each node,
  • V(P) heuristic(P) if P is a terminal node in
    a search tree
  • V(P) maxi V(Pi) if P is a MAX-to-move
    position
  • V(P) mini V(Pi) if P is a MIN-to-move
    position
  • We define minimax(Pos, BestSucc, Val) , where
  • Val is the minimax value of a position Pos and
  • BestSucc is the best successor position of Pos

13
MiniMax (Contd)
  • moves (Pos, PosList)
  • PosList is the list of legal successor positions
    of Pos
  • best (PosList, BestPos, BestVal)
  • Selects the best position BestPos from a list of
    candidate positions PosList
  • BestVal is the value of BestPos
  • best here is either minimum or maximum depending
    on the side to move
  • betterof(Pos0, Value0, Pos1, Value1, BetterPos,
    BetterVal)
  • BetterPos and BetterVal are the better position
    and value between Pos0 and Pos1

14
MiniMax (Contd)
  • minimax( Pos, BestSucc, Val) -
  • moves( Pos, PosList), !,
  • best( PosList, BestSucc, Val)
  • heuristic( Pos, Val). Pos has no successors
    evaluate statically
  • best( Pos, Pos, Val) - minimax( Pos, _,
    Val), !.
  • best( Pos1 PosList, BestPos, BestVal) -
  • minimax( Pos1, _, Val1),
  • best( PosList, Pos2, Val2),
  • betterof( Pos1, Val1, Pos2, Val2, BestPos,
    BestVal).

15
MiniMax (Contd)
  • betterof( Pos0, Val0, Pos1, Val1, Pos0, Val0) -
    Pos0 better than Pos1
  • min_to_move( Pos0), MINs
    turn to move in Pos0
  • Val0 gt Val1, !
    MAX prefers the greater value
  • max_to_move( Pos0), MAX to
    move in Pos0
  • Val0 lt Val1, !.
    MIN prefers the lesser value
  • betterof( Pos0, Val0, Pos1, Val1, Pos1, Val1).
    Otherwise Pos1 better than Pos0

16
More About Minimax
  • This version of minimax program visits all the
    positions in the search tree up to its terminal
    positions. This is not applicable for most games.
    We probably need to have a fixed ply depth in our
    minimax program
  • moves(Pos, PosList) should be defined using
    bagof, setof or findall
  • heuristic(Pos, Val) is defined based on the
    problem
  • For defining min_to_move(Pos) and
    max_to_move(Pos), the information regarding the
    side should be in Pos (maxs turn or mins turn)
Write a Comment
User Comments (0)
About PowerShow.com