430 likes | 508 Views
Explore managing search strategies in game tree search, with a focus on incremental approaches and resource limitations. Learn practical applications and compare various search strategies, including depth-first and breadth-first search. Understand the benefits and drawbacks of different methods for effective gameplay.
E N D
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 O O X O X O X X 100 X O X 100 O X 100 100 100 100 100 100
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)
Managing Search Search Direction Search Strategy Incremental Game Tree Search Game Graph Search
Forward Search e b f g l a c h m n i d j k
Backward Search e f b g a b h c n c i j d k
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
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
Time Comparison Branching 2 and depth d and solution at depth k
Time Comparison Analysis for branching b and depth d and solution at depth k.
Space Comparison Total depth d and solution depth k.
Iterative Deepening Run depth-limited search repeatedly, starting with a small initial depth, incrementing on each iteration, until success or run out of alternatives.
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
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.
Game Tree Search Problem: The clock may be too short to permit complete search on a single move. Approach: Incremental Tree Search
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.
Single Player Game Graph s2 s1 s3 s4
Multiple Player Game Graph s2 aa ba s1 s3 ab bb s4
Bipartite Game Graph s2 aa a ab s1 s3 ba b bb s4
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))))
Players classplayer (thing) {varmatch nil; varrole nil; varroles nil; vartheory nil; varstartclock 0; varplayclock 0 varhasher nil; varaction nil; varroot nil; varfringe nil}
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}
Nodes classnode (thing) {varplayer nil; vardata nil; vartheory nil; varparent nil; varalist nil; varscore nil}
Single Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.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)}
Multiple Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.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); blacons(j, new, bl)} alacons(a, nreverse(bl), al)} node.alistnreverse(al); returnnreverse(nl)}
Multiple Player Node Expansion functionexpand (node) {varmatch node.match; varrolematch.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); blacons(j, new, bl)} alacons(a, nreverse(bl), al)} node.alistnreverse(al); returnnreverse(nl)}
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}
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}
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}
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}
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}
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)}
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)}
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}}