CIS 350 – I Game Programming Instructor: Rolf Lakaemper
Classic AI: Search Trees
Overview Search Trees are the underlying techniques of round based games with a (very) limited number of moves per round, e.g. BOARDGAMES
Overview A search tree contains a certain game state (position) in a single node, the children contain the possible moves of the single active player. Let’s name player 1 ‘MAX’, player 2 ‘MIN’.
Search Trees MAX MIN MAX Min’s move Max’s move
Search Trees MAX MIN MAX Min’s move Max’s move The basic idea: compute (all) possible moves and evaluate the result (the leaves)
Search Trees 5732 MAX MIN MAX Min’s move Max’s move Now fill the tree bottom up, using the max. or min. values of the child nodes
Search Trees MAX MIN MAX Min’s move Max’s move Now fill the tree bottom up, using the max. or min. values of the child nodes A high value is good for MAX, so MIN would choose the min.-move !
Search Trees MAX MIN MAX Min’s move Max’s move Now fill the tree bottom up, using the max. or min. values of the child nodes A high value is good for MAX, so MAX would choose the max.-move !
Search Trees Problem: Lots of nodes to evaluate. Example: CHESS has an average branching factor of 35, so …
Search Trees Optimizing Tree Search Idea 1:Limit Depth The easiest idea, the worst playing skills.
Search Trees Optimizing Tree Search Idea 2:alpha-beta pruning A safe idea and a pure win !
Alpha beta pruning MAX MIN MAX Min’s move Max’s move What happens at this point ?
Alpha beta pruning MAX MIN MAX Min’s move Max’s move Since 3<5 and evaluation of the next nodes would only lead to values < 3, 3’s parent node would NEVER be chosen by MAX
Alpha beta pruning MAX MIN MAX Min’s move Max’s move We can stop searching for this branch !
Alpha beta pruning Alpha values: the best values achievable for MAX, hence the max. value so far Beta values: the best values achievable for MIN, hence the min. value so far At MIN level: compare result V of node to alpha value. If V>alpha, pass value to parent node and BREAK At MAX level: compare result V of node to beta value. If V<beta, pass value to parent node and BREAK
Alpha beta pruning Alpha Beta pruning is a pure win, but it’s highly depending on the move ordering !
Improvements Further Improvements: Quiescent search ‘Don’t leave a mess strategy’ For evaluating the leaves at depth 0, instead of the evaluation function a special function is called that evaluates special moves (e.g. captures) only down to infinit depth Guarantees e.g. that the Queen will not be captured at move in depth 0
Improvements Iterative deepening: First try depth n=1 If time left, try depth n+1 Order moves of depth n when trying depth n+1 ! Since alpha beta is order sensitive, this can speed up the process Fills time and doesn’t need predefined depth parameter Drawback: creates same positions over and over, but…
Improvements Example for multiply generated moves: Assumption: worst case: no alpha bet pruning. Branching factor 10 IterationStepsTotal … ======= position 123,450 positions 123,450 / 111,110 = 1.11 => only 11% additional pos. (worst case)
Improvements Improvement: Aspiration Windows Extension of iterative deepening Basic Idea: feed alpha beta values of previous search into current search Assumption: new values won’t differ too much Extend alpha beta by +/- window value
Improvements Improvement: Null Move Forward Pruning Idea: if the fighter can’t knock down the opponent with a free shot, the position should be pretty good ! Don’t evaluate player’s move, but opponent’s move again (free shot) If value is still good enough, don’t continue search Do this on a lower level than defined (D-2)