1 / 22

Introduction to Search Trees in Game Programming

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.

jpease
Download Presentation

Introduction to Search Trees in Game Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 350 – I Game Programming Instructor: Rolf Lakaemper

  2. Classic AI: Search Trees

  3. Overview Search Trees are the underlying techniques of round based games with a (very) limited number of moves per round, e.g. BOARDGAMES

  4. 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’ .

  5. Search Trees MAX Max’s move MIN Min’s move MAX

  6. Search Trees MAX Max’s move MIN Min’s move MAX The basic idea: compute (all) possible moves and evaluate the result (the leaves)

  7. 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

  8. 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

  9. 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

  10. Search Trees Problem: Lots of nodes to evaluate. Example: CHESS has an average branching factor of 35, so …

  11. Search Trees Optimizing Tree Search Idea 1: Limit Depth The easiest idea, the worst playing skills.

  12. Search Trees Optimizing Tree Search Idea 2: alpha-beta pruning A safe idea and a pure win !

  13. Alpha beta pruning MAX Max’s move MIN 5 Min’s move MAX 5 7 3 What happens at this point ?

  14. 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

  15. Alpha beta pruning MAX Max’s move MIN 5 Min’s move MAX 5 7 3 We can stop searching for this branch !

  16. 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

  17. Alpha beta pruning Alpha Beta pruning is a pure win, but it’s highly depending on the move ordering !

  18. 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

  19. 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…

  20. 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)

  21. 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

  22. 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)

More Related