1 / 43

Managing Search

General Game Playing Lecture 5. Managing Search. Michael Genesereth / Nat Love Spring 2006. Game Tree Search. X. O. X. O. X. X. X. X. O. X. O. X. O. O. X. X. X. X. X. O. O. O. O. X. X. O. X. O. O. X. X. X. X. O. X. O. X. O. X. X. X. O. O.

Télécharger la présentation

Managing Search

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. General Game Playing Lecture 5 Managing Search Michael Genesereth / Nat Love Spring 2006

  2. Game Tree Search X O X O X X X X O X O X O O X X X X X O O O O X X O X O O X X X X O X O X O X X X O O O O X O X O X X 100 X O X 100 O X 100 100 100 100 100 100

  3. Resource Limitations Large state spaces ~5000 states in Tic-Tac-Toe ~1030 states in Chess Even larger game trees ~900,000 nodes in Tic-Tac-Toe Limited Resources Memory Time (start clock, move clock)

  4. Managing Search Search Direction Search Strategy Incremental Game Tree Search Game Graph Search

  5. Search Direction

  6. Forward Search e b f g l a c h m n i d j k

  7. Backward Search e f b g a b h c n c i j d k

  8. Bidirectional Search a m

  9. Search Strategy

  10. Depth First Search a b c d e f g h i j a b e f c g h d i j Advantage: Small intermediate storage Disadvantage: Susceptible to garden paths Disadvantage: Susceptible to infinite loops

  11. Breadth First Search a b c d e f g h i j a b c d e f g h i j Advantage: Finds shortest path Disadvantage: Consumes large amount of space

  12. Time Comparison Branching 2 and depth d and solution at depth k

  13. Time Comparison Analysis for branching b and depth d and solution at depth k.

  14. Space Comparison Total depth d and solution depth k.

  15. Iterative Deepening Run depth-limited search repeatedly, starting with a small initial depth, incrementing on each iteration, until success or run out of alternatives.

  16. Example a b c d e f g h i j a a b c d a b e f c g h d i j Advantage: Small intermediate storage Advantage: Finds shortest path Advantage: Not susceptible to garden paths Advantage: Not susceptible to infinite loops

  17. Time Comparison

  18. General Results Theorem [Korf]: The cost of iterative deepening search is b/(b-1) times the cost of depth-first search (where b is the branching factor). Theorem: The space cost of iterative deepening is no greater than the space cost for depth-first search.

  19. Incremental Game Tree Search

  20. Game Tree Search Problem: The clock may be too short to permit complete search on a single move. Approach: Incremental Tree Search

  21. Incremental Game Graph Search

  22. Nodes Versus States The game tree for Tic-Tac-Toe has approximately 900,000 nodes. There are approximately 5,000 distinct states. Searching the tree requires 180 times more work than searching the graph. One small hitch: The graph is implicit in the state description and must be built in advance or incrementally. Recognizing a repeated state takes time that varies with the size of the graph thus far seen. Solution: Hashing.

  23. Single Player Game Graph s2 s1 s3 s4

  24. Multiple Player Game Graph s2 aa ba s1 s3 ab bb s4

  25. Bipartite Game Graph s2 aa a ab s1 s3 ba b bb s4

  26. Bipartite Association List Simple Association List ((a . s2) (b . s3)) Bipartite Association List: ((a . (((a a) . s2) ((a b) . s1))) (b . (((b a) . s3) ((b b) . s4))))

  27. Incremental Tree Search Code

  28. Players classplayer (thing) {varmatch  nil; varrole  nil; varroles nil; vartheory nil; varstartclock  0; varplayclock  0 varhasher nil; varaction nil; varroot nil; varfringe nil}

  29. Tree Expansion functionexpands (player,count) {var node; for i  1 until i > count or null(player.fringe) do{node  first(player.fringe); player.fringe  rest(player.fringe); unless numberp(node.score) i  i + 1; player.fringe  nconc(player.fringe,expand(node))}; returndone}

  30. Nodes classnode (thing) {varplayer  nil; vardata  nil; vartheory nil; varparent nil; varalist nil; varscore nil}

  31. Single Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.role; varold;vardata; var al; var nl; forainlegals(role,node) {old node.data; node.data cons(does(role,a), old); data simulate(node); node.data old; new makenode(match, data, node.theory, node) iftermp(new)then new.score reward(role, new); nl cons(new, nl); al acons(a, new, al)} node.alist nreverse(al) returnnreverse(nl)}

  32. Multiple Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.role; varold;vardata; var al; var nl; forainlegals(role,node) {for j in joints(role, a, player.roles, node, nil, nil) {old node.data; node.data consactions(match.roles, j, old); data simulate(node); node.data old; new makenode(match, data, node.theory, node) iftermp(new)then new.score reward(role, new); nl cons(new, nl); blacons(j, new, bl)} alacons(a, nreverse(bl), al)} node.alistnreverse(al); returnnreverse(nl)}

  33. Multiple Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.role; varold;vardata; var al; var nl; forainlegals(role,node) {for j in joints(role, a, player.roles, node, nil, nil) {old node.data; node.data consactions(match.roles, j, old); data simulate(node); node.data old; new makenode(match, data, node.theory, node) iftermp(new)then new.score reward(role, new); nl cons(new, nl); blacons(j, new, bl)} alacons(a, nreverse(bl), al)} node.alistnreverse(al); returnnreverse(nl)}

  34. Subroutines functionconsactions (roles, actions, data) {var nl; forroleinroles, action in actions nl  cons(does(role,action), nl) returnnreverse(nl)} functionjoints (role, action, roles, node, xl, nl) {if null(roles) then cons(reverse(xl),nl) else if car(roles) = role then joints(role,action,cdr(roles),node,cons(action,xl),nl) else for x in legals(car(roles),node) nl  joints(role,action,cdr(roles),node, cons(x,xl),nl) return nl}

  35. Best Move functionbestmove (node) {varbest; varscore; forpairinnode.alist do {score maxscore(pair.right); ifscore = 100 then return pair.left; else ifscore = 0; else ifnull(best) then best pair.left} return best or car(node.alist).left}

  36. Node Evaluation functionmaxscore (node) {varscore nil; varmax 0; ifnode.score then node.score; else if null(node.alist) then nil; else for pair in node.alist do {score minscores(pair.right) ifscore = 100 thenreturn 100 else if not numberp(score)thenmax nil else if null(max) else if score > maxthenmax score} returnmax}

  37. Node Evaluation functionmaxscore (node) {varscore nil; varmax 0; ifnode.score then node.score; else if null(node.alist) then nil; else for pair in node.alist do {score minscores(pair.right) ifscore = 100 thenreturn 100 else if not numberp(score)thenmax nil else if null(max) else if score > maxthenmax score} returnmax}

  38. Node Evaluation functionminscores (al) {varscore nil; varmin 100; for pair in al do {score maxscore(pair.right) ifscore = 0 thenreturn 0 else if not numberp(score)thenmin nil else if null(min) else if score < minthenmin score} returnmin}

  39. Graph Search Code

  40. Node Expansion functionexpand (node) {varplayer node.player; varold;vardata; var al; var nl; forainlegals(role,node) {for j in joints(player.role, a, player.roles, node, nil, nil) {old node.data; node.data consactions(player.roles, j, old); data sort(simulate(node)); node.data old; ifnew gethash(data,player.hasher) then new else {new makenode(player, data, node.theory, node) gethash(data, player.hasher) new; iftermp(new)then new.score reward(player.role, new); nl cons(new, nl)}; bl acons(j, new, bl)} al acons(a, nreverse(bl), al)} node.alist nreverse(al) returnnreverse(nl)}

  41. Node Expansion With State Collapse functionexpand (node) {varmatch node.match; varold;vardata; var al; var nl; forainlegals(role,node) {for j in joints(match.role, a, match.roles, node, nil, nil) {old node.data; node.data consactions(match.roles, j, old); data sort(simulate(node),minlessp); node.data old; ifnew gethash(data, match.hasher) then new else {new makenode(match, data, node.theory, node) gethash(data, match.hasher) new; iftermp(new)then new.score reward(match.role, new); nl cons(new, nl)}; bl acons(j, new, bl)} al acons(a, nreverse(bl), al)} node.alist nreverse(al) returnnreverse(nl)}

  42. Ordering Code function minlessp (x,y) {if numberp(x) then{if numberp(y) then x<y elsetrue} else if symbolp(x) then {if numberp(y) thennil else if symbolp(y) then x.name<y.name elsetrue} else if numberp(y) thennil else if symbolp(y) thennil else forl  x then cdr(l) for m  y then cdr(m) do {if null(l) then return not null(m) else if null(m) then return nil else if minlessp(car(l),car(m)) then returntrue else if car(l)=car(m) thennil elsereturn nil}}

More Related