220 likes | 235 Views
Learn about search trees, the underlying technique of round-based games with a limited number of moves per round, such as board games. Understand how search trees compute possible moves and evaluate game states.
E N D
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 Max’s move MIN Min’s move MAX
Search Trees MAX Max’s move MIN Min’s move MAX The basic idea: compute (all) possible moves and evaluate the result (the leaves)
Search Trees MAX Max’s move MIN Min’s move MAX 5 7 3 2 Now fill the tree bottom up, using the max. or min. values of the child nodes
Search Trees MAX Max’s move A high value is good for MAX, so MIN would choose the min.-move ! MIN 5 2 Min’s move MAX 5 7 3 2 Now fill the tree bottom up, using the max. or min. values of the child nodes
Search Trees A high value is good for MAX, so MAX would choose the max.-move ! MAX 5 Max’s move MIN 5 2 Min’s move MAX 5 7 3 2 Now fill the tree bottom up, using the max. or min. values of the child nodes
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 Max’s move MIN 5 Min’s move MAX 5 7 3 What happens at this point ?
Alpha beta pruning MAX Max’s move MIN 5 Min’s move MAX 5 7 3 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 Max’s move MIN 5 Min’s move MAX 5 7 3 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 Iteration Steps Total 1 10 10 2 10+100 110 3 10+100+1000 1110 4 10+100+1000+10000 11110 5 10+…+100000 111110 ======= 111110 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)