1 / 40

How computers play games with you

How computers play games with you. CS161, Spring ‘02 Nathan Sturtevant. Outline. Overview Classes of Games Algorithms Minimax - pruning Other techniques. Overview - Types of Games. You have studied single-agent problems so far 1 player v. a difficult problem Defined by:

Télécharger la présentation

How computers play games with you

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. How computers play games with you CS161, Spring ‘02 Nathan Sturtevant

  2. Outline • Overview • Classes of Games • Algorithms • Minimax • - pruning • Other techniques

  3. Overview - Types of Games • You have studied single-agent problems so far • 1 player v. a difficult problem • Defined by: • Start state • Successor function • Heuristic function • Goal test

  4. Overview - Types of Games • This lecture deals primarily with 2-player games • Defined by: • Initial State • Successor function (operators) • Terminal Test • Utility / payoff function • Similar to heuristics in single agent problems

  5. Overview - Types of Games • Multi-Player games • Defined similarly to two-player games • Use different algorithms to play • Refers to games with 3 or more indepant players • Game with 2 teams is equivalent to a 2-player game • See HW 5.8

  6. Chinese Checkers • Based on European game Halma • Americans called it Chinese Checkers • 1 player game? • 2 player game? • Multi-player game?

  7. Classes of Games • Deterministic v. Non-deterministic • Chess v. backgammon • Perfect Information v. Imperfect information • Checkers v. Bridge • Zero-sum (strictly competitive) • Prisoners dilemna

  8. Classes of Games

  9. Classes of Games

  10. Classes of Games

  11. Classes of Games

  12. Classes of Games

  13. Me Opponent Tic-Tac-Toe

  14. How do we get an algorithm? • Apply utility function at the leaves of the tree • In tic-tac-toe, count how many rows and columns are occupied by each player and subtract

  15. Me Opponent Tic-Tac-Toe Utility = 3 x: 2r 2c 2d o: 2r 2c 0d x: 2r 2c 2d o: 2r 1c 1d x: 2r 3c 2d o: 2r 1c 1d x: 3r 3c 2d o: 2r 2c 0d Utility = 3 Utility = ∞ Utility = 2 Utility = 3 Utility = ∞ Utility = 2

  16. How do we get an algorithm? • Apply utility function at the leaves of the tree • In tic-tac-toe, count how many rows and columns are occupied by each player and subtract • Back-up values in the tree • This calculates the “minimax” value of a tree

  17. Maximizer Minimizer 2 3 ∞ 2 Minimizers strategy Minimax 3 1 - ply 3 ∞ 1 - ply

  18. Minimax - Properties • Complete? • Yes - if tree is finite • Optimal? • Yes - against an optimal opponent • Time Complexity? • O(bd) • Space Complexity? • O(bd)

  19. Minimax • Assume our computer can expand 105 nodes/sec • Assume we have 100 seconds to move • 107 nodes/move • Tic-tac-toe • 9! = 362880 (naïve) ways to play a game (b=4) • 29 = 512 complete states (upper bound) on a board • Chess • b = 35, d = 100, must search 2154 nodes

  20. Minimax - issues • Evaluation function • Where does it come from? • Expert knowledge • Chess: material value • Othello (reversi): positional strength • Learned information • Pre-computed tables • Quiescence

  21. quiescence

  22. Minimax - issues • Quiescence • We don’t see the consequences of our bad choices • quiescence search • Horizon problem • We avoid dealing with a bad situation

  23. Minimax • In Chess • b = 35 • 107 nodes/move • Can search 4-ply into tree (human novice) • Good humans can search 8-ply • Kasparov searches about 12-ply • What to do? • - pruning

  24. - pruning •  = lower bound on Maximizer’s score • Start at -∞ •  = upper bound on Minimizer’s score • Start at ∞

  25. Maximizer Minimizer 1  = -∞  = ∞  = -∞  = ∞  = -∞  = ∞ ≥1   -∞ ∞

  26. Maximizer Minimizer 1 2  = -∞  = ∞  = -∞  = ∞  = 1  = ∞ ≥1 2 -∞ ∞

  27. Maximizer Minimizer 1 2  = -∞  = ∞  = -∞  = ∞  = 2  = ∞ 2   -∞ ∞

  28. Maximizer Minimizer 1 3  = -∞  = ∞  = -∞  = 2 ≤ 2  = -∞  = 2 ≥ 3 2 2   -∞ ∞

  29. Maximizer Minimizer 1 3  = -∞  = ∞ ≥ 2  = -∞  = 2 2  = 3  = 2 ≥ 3 2 2   -∞ ∞

  30. Maximizer Minimizer  = 2  = ∞  = 2  = ∞ 5  = 2  = ∞ ≥ 2 2 ≥ 3 ≥ 5 2 1 2 3   -∞ ∞

  31. Maximizer Minimizer  = 2  = ∞  = 5  = ∞ 5 6  = 2  = ∞ ≥ 2 2 ≥ 3 ≥ 5 2 6 1 2 3   -∞ ∞

  32. Maximizer Minimizer  = 2  = ∞ ≥ 2  = 2  = 6 ≤ 6 2  = 2  = 6 ≥ 3 ≥7 2 6 1 2 3 5 6 7   -∞ ∞

  33. Maximizer Minimizer  = 2  = ∞ ≥ 2 6  = 2  = 6 ≤ 6 2 6  = 7  = 6 ≥ 3 ≥7 2 6 1 2 3 5 6 7   -∞ ∞

  34. - pruning MAX-VAL(state, game, ,  ) if CUTOFF-TEST(state) return EVAL(state) foreachsin SUCCESSOR(state)  = MAX(, MIN-VAL(s, game, , )) if ( ≥ ) return return

  35. - pruning • Complete? • Yes - if tree is finite • Optimal? • Computes same value as minimax • Time Complexity? • Best case O(bd/2) • Average case O(b3d/4)

  36. - pruning • Effectiveness depends on order of moves in tree • In practice, we can usually get best-case performance • Chess • Before we could search 4-ply into tree • Now we can search 8-ply into tree

  37. Other Techniques • Transposition tables • Opening / Closing book

  38. Transposition Tables • Only using linear about of memory • Search only takes a few kb of memory • Most games aren’t trees but graphs • A lot of duplicated effort • Store results from nodes in the trees & reuse

  39. Transposition Tables

  40. Transposition Tables • Transposition tables hash game states into table • Store saved minimax value in table

More Related