managing search general game playinglecture 5 michael genesereth / nat love spring 2006
Post on 22-Dec-2015
213 views
TRANSCRIPT
![Page 1: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/1.jpg)
Managing Search
General Game Playing Lecture 5
Michael Genesereth / Nat Love Spring 2006
![Page 2: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/2.jpg)
2
Game Tree SearchX O X
O
X O X
O X
X O X
O X
O
X O X
O X
OX
X O X
O X
O X
X O X
O X
O
X
100
100
100
100
100100 100
100
X O X
O
X
X O X
O
X
X O X
O
X
X O X
O X
![Page 3: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/3.jpg)
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)
![Page 4: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/4.jpg)
4
Managing Search
Search Direction
Search Strategy
Incremental Game Tree Search
Game Graph Search
![Page 5: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/5.jpg)
5
Search Direction
![Page 6: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/6.jpg)
6
Forward Search
f
j
k
c
d
a
e
g
m
b
l
n
h
i
![Page 7: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/7.jpg)
7
Backward Search
f
j
k
c
d
n
e
g
b
b
a
c
h
i
![Page 8: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/8.jpg)
8
Bidirectional Search
ma
![Page 9: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/9.jpg)
9
Search Strategy
![Page 10: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/10.jpg)
10
Depth First Search
a
c
hg
d
ji
b
fe
a b e f c g h d i j
Advantage: Small intermediate storageDisadvantage: Susceptible to garden pathsDisadvantage: Susceptible to infinite loops
![Page 11: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/11.jpg)
11
Breadth First Search
a b c d e f g h i j
a
c
hg
d
ji
b
fe
Advantage: Finds shortest pathDisadvantage: Consumes large amount of space
![Page 12: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/12.jpg)
12
Time Comparison
Branching 2 and depth d and solution at depth k
Time Best Worst
Depth k 2d −2d−k
Breadth 2k−1 2k−1
![Page 13: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/13.jpg)
13
Time Comparison
Analysis for branching b and depth d and solution at depth k.
Time Best Worst
Depth kbd−bd−k
b−1
Breadthbk−1−1b−1
+1bk−1b−1
![Page 14: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/14.jpg)
14
Space Comparison
Total depth d and solution depth k.
Space Binary General
Depth d (b−1)×(d−1)+1
Breadth 2k−1 bk−1
![Page 15: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/15.jpg)
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.
![Page 16: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/16.jpg)
16
Example
a
c
hg
d
ji
b
fe
aa b c da b e f c g h d i j
Advantage: Small intermediate storageAdvantage: Finds shortest pathAdvantage: Not susceptible to garden pathsAdvantage: Not susceptible to infinite loops
![Page 17: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/17.jpg)
17
Time Comparison
Depth Iterative Depth
1 1 1
2 4 3
3 11 7
4 26 15
5 57 31
n 2n+1−n−2 2n−1
![Page 18: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/18.jpg)
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.
![Page 19: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/19.jpg)
19
Incremental Game Tree Search
![Page 20: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/20.jpg)
20
Game Tree Search
Problem: The clock may be too short to permit complete search on a single move.
Approach: Incremental Tree Search
![Page 21: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/21.jpg)
21
Incremental Game Graph Search
![Page 22: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/22.jpg)
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.
![Page 23: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/23.jpg)
23
Single Player Game Graph
s3s1
s2
s4
![Page 24: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/24.jpg)
24
Multiple Player Game Graph
s3s1
s2
s4
aa
bb
baab
![Page 25: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/25.jpg)
25
Bipartite Game Graph
s3
s1
a
b
s2
s4
aa
bb
ba
ab
![Page 26: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/26.jpg)
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))))
![Page 27: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/27.jpg)
27
Incremental Tree Search Code
![Page 28: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/28.jpg)
28
Players
class player (thing) {var match nil; var role nil; var roles nil; var theory nil; var startclock 0; var playclock 0 var hasher nil; var action nil; var root nil; var fringe nil}
![Page 29: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/29.jpg)
29
Tree Expansion
function expands (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))}; return done}
![Page 30: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/30.jpg)
30
Nodes
class node (thing) {var player nil; var data nil; var theory nil; var parent nil; var alist nil; var score nil}
![Page 31: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/31.jpg)
31
Single Player Node Expansion
function expand (node) {var match node.match; var role match.role; var old; var data; var al; var nl; for a in legals(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) if termp(new) then new.score reward(role, new); nl cons(new, nl); al acons(a, new, al)} node.alist nreverse(al) return nreverse(nl)}
![Page 32: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/32.jpg)
32
Multiple Player Node Expansion
function expand (node) {var match node.match; var role match.role; var old; var data; var al; var nl; for a in legals(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) if termp(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); return nreverse(nl)}
![Page 33: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/33.jpg)
33
Multiple Player Node Expansion
function expand (node) {var match node.match; var role match.role; var old; var data; var al; var nl; for a in legals(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) if termp(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); return nreverse(nl)}
![Page 34: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/34.jpg)
34
Subroutines
function consactions (roles, actions, data) {var nl; for role in roles, action in actions nl cons(does(role,action), nl) return nreverse(nl)}
function joints (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}
![Page 35: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/35.jpg)
35
Best Move
function bestmove (node) {var best; var score; for pair in node.alist do {score maxscore(pair.right); if score = 100 then return pair.left; else if score = 0; else if null(best) then best pair.left} return best or car(node.alist).left}
![Page 36: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/36.jpg)
36
Node Evaluation
function maxscore (node) {var score nil; var max 0; if node.score then node.score; else if null(node.alist) then nil; else for pair in node.alist do {score minscores(pair.right) if score = 100 then return 100 else if not numberp(score) then max nil else if null(max) else if score > max then max score} return max}
![Page 37: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/37.jpg)
37
Node Evaluation
function maxscore (node) {var score nil; var max 0; if node.score then node.score; else if null(node.alist) then nil; else for pair in node.alist do {score minscores(pair.right) if score = 100 then return 100 else if not numberp(score) then max nil else if null(max) else if score > max then max score} return max}
![Page 38: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/38.jpg)
38
Node Evaluation
function minscores (al) {var score nil; var min 100; for pair in al do {score maxscore(pair.right) if score = 0 then return 0 else if not numberp(score) then min nil else if null(min) else if score < min then min score} return min}
![Page 39: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/39.jpg)
39
Graph Search Code
![Page 40: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/40.jpg)
40
Node Expansion
function expand (node) {var player node.player; var old; var data; var al; var nl; for a in legals(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; if new gethash(data,player.hasher) then new else {new makenode(player, data, node.theory, node) gethash(data, player.hasher) new; if termp(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) return nreverse(nl)}
![Page 41: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/41.jpg)
41
Node Expansion With State Collapse
function expand (node) {var match node.match; var old; var data; var al; var nl; for a in legals(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; if new gethash(data, match.hasher) then new else {new makenode(match, data, node.theory, node) gethash(data, match.hasher) new; if termp(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) return nreverse(nl)}
![Page 42: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/42.jpg)
42
Ordering Code
function minlessp (x,y) {if numberp(x) then {if numberp(y) then x<y else true} else if symbolp(x) then {if numberp(y) then nil else if symbolp(y) then x.name<y.name else true} else if numberp(y) then nil else if symbolp(y) then nil else for l 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 return true else if car(l)=car(m) then nil else return nil}}
![Page 43: Managing Search General Game PlayingLecture 5 Michael Genesereth / Nat Love Spring 2006](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5ee2f/html5/thumbnails/43.jpg)
43