Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf ·...

55
Logic Programming General Game Playing Michael Genesereth Computer Science Department Stanford University

Transcript of Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf ·...

Page 1: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Logic ProgrammingGeneral Game Playing

Michael GeneserethComputer Science Department

Stanford University

Page 2: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Human Game Playing• Intellectual Activity• Skill Comparison

Computer Game Playing• Testbed for AI• Limitations

Game Playing

Page 3: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Narrowness Good at one game, not so good at others Cannot do anything else

Not really testing intelligence of machine Programmer does all the interesting analysis / design Machine simply follows the recipe

Limitations of Game Playing for AI

Page 4: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

General Game Players are systems able to play arbitrary games effectively based solely on formal descriptions supplied at “runtime”.

Translation: They don’t know the rules until the game starts.

Must figure out for themselves: legal moves, winning strategy in the face of incomplete info and resource bounds

General Game Playing

Page 5: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Variety of Games

Page 6: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Novelty

Page 7: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

International GGP Competition

Page 8: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

Annual GGP Competition Held at AAAI or IJCAI conference Administered by Stanford University (Stanford folks not eligible to participate)

Annual GGP Competition

Page 9: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

GGP-05 Winner Jim Clune

Page 10: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

Winners 2005 - ClunePlayer - Jim Clune (USA) 2006 - FluxPlayer - Schiffel, Thielscher (Germany) 2007 - CadiaPlayer - Bjornsson, Finsson (Iceland) 2008 - CadiaPlayer - Bjornsson, Finsson (Iceland) 2010 - Ary - Mehat (France) 2011 - TurboTurtle - Schreiber (USA) 2012 - CadiaPlayer - Bjornsson, Finsson (Iceland) 2013 - TurboTurtle - Schreiber (USA)

History

Page 11: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

Carbon versus Silicon

Page 12: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

Human Race Being Defeated

Page 13: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Game Description

Page 14: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Environment Environment with finitely many states One initial state and one or more terminal states Each state has a unique goal value for each player

Players Fixed, finite number of players Each with finitely many moves

Dynamics Finitely many steps All players move on all steps (some no ops) Environment changes only in response to moves

Finite Synchronous Games

Page 15: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

a

a

b a

ab

b b

0 50 50 100

0 25 25 50

a ab ba a

s1 s2 s3 s4

s5 s6 s7 s8

Single Player Game

Page 16: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/42

a / a

a / a

a / a a / a

a / aa / a

b / a a / b

0 / 0 50 / 50 50 / 50 100 / 0

0 / 0 25 / 25 25 / 25 0 / 100

b / a a / bb / a a / bb / a a / b

s1 s2 s3 s4

s5 s6 s7 s8

Multiple Player Game

Page 17: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

17

Good News: Since all of the games that we are considering are finite, it is possible in principle to communicate game information in the form of state graphs.

Direct Description

Page 18: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

18

Problem: Size of description. Even though everything is finite, these sets can be large.

Solution: Exploit regularities / structure in state graphs to produce compact encoding

Problem and Solution

Page 19: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Game Description Language (or GDL) is a formal language for encoding the rules of games.

Game rules written as sentences in Symbolic Logic.

GDL is widely used in the research literature and is used in virtually all General Game Playing competitions.

GDL extensions are applicable in real-world applications such as Enterprise Management and Computational Law.

Game Description Language

Page 20: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Symbols: white, black - roles 1, 2, 3 - indices of rows and columns x, o, b - marks noop - no-op action

Constructors: cell(index,index,mark) --> proposition control(role) --> proposition mark(index,index) --> action

Predicates: row(index,mark) column(index,mark) diagonal(mark) line(mark) open

Game-Specific Vocabulary

Page 21: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

cell(1,1,x)cell(1,2,b)cell(1,3,b)cell(2,1,b)cell(2,2,o)cell(2,3,b)cell(3,1,b)cell(3,2,b)cell(3,3,x)control(black)

XO

X

State Representation

Page 22: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

role(white)role(black)

base(cell(M,N,Z)) :- index(M) & index(N) & filler(Z)

base(control(W)) :- role(W)

input(W,mark(X,Y)) :- role(W) & index(X) & index(Y)

input(W,noop) :- role(W)

init(cell(X,Y,b)) :- index(X) & index(Y)

init(control(white))

legal(P,mark(X,Y)) :- true(cell(X,Y,b)) & true(control(P))

legal(x,noop) :- true(control(black))

legal(o,noop) :- true(control(white))

terminal :- line(P)terminal :- ~open

row(M,P) :- true(cell(M,1,P)) & true(cell(M,2,P)) & true(cell(M,3,P))

column(N,P) :- true(cell(1,N,P)) & true(cell(2,N,P)) & true(cell(3,N,P))

diagonal(P) :- true(cell(1,1,P)) & true(cell(2,2,P)) & true(cell(3,3,P))

diagonal(P) :- true(cell(1,3,P)) & true(cell(2,2,P)) & true(cell(3,1,P))

line(P) :- row(M,P)line(P) :- column(N,P)line(P) :- diagonal(P)

open :- true(cell(M,N,b))

index(1) filler(x)index(2) filler(o)index(3) filler(b)

next(cell(M,N,x)) :- does(white,mark(M,N))

next(cell(M,N,0)) :- does(black,mark(M,N))

next(cell(M,N,Z)) :- does(P,mark(M,N)) & true(cell(M,N,Z)) & Z!=b

next(cell(M,N,b)) :- does(P,mark(J,K)) & true(cell(M,N,b)) & distinct(M,J)

next(cell(M,N,b)) :- does(P,mark(J,K)) & true(cell(M,N,b)) & distinct(N,K)

next(control(white)) :- true(control(black))

next(control(black)) :- true(control(white))

goal(white,100) :- line(x) & ~line(o)goal(white,50) :- ~line(x) & ~line(o)goal(white,0) :- ~line(x) & line(o)goal(black,100) :- ~line(x) & line(o)goal(black,50) :- ~line(x) & ~line(o)goal(black,0) :- line(x) & ~line(o)

Rules of Tic-Tac-Toe

Page 23: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

role(white)role(black)

Roles

Page 24: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

base(cell(X,Y,W)) :- index(X) & index(Y) & filler(W)

base(control(W)) :- role(W)

index(1)index(2)index(3)

filler(x)filler(o)filler(b)

Propositions

Page 25: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

input(W,mark(X,Y)) :- role(W) & index(X) & index(Y)

input(W,noop) :- role(W)

Actions

Page 26: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

init(cell(1,1,b))init(cell(1,2,b))init(cell(1,3,b))init(cell(2,1,b))init(cell(2,2,b))init(cell(2,3,b))init(cell(3,1,b))init(cell(3,2,b))init(cell(3,3,b))init(control(white))

Initial State

Page 27: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

legal(W,mark(X,Y)) :- true(cell(X,Y,b)) & true(control(W))

legal(white,noop) :- true(control(black))

legal(black,noop) :- true(control(white))

Legality

Page 28: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

next(cell(M,N,x)) :- does(white,mark(M,N))

next(cell(M,N,o)) :- does(black,mark(M,N))

next(cell(M,N,b)) :- does(W,mark(J,K)) & true(cell(M,N,b)) & M!=J

next(cell(M,N,b)) :- does(W,mark(J,K)) & true(cell(M,N,b)) & N!=K

next(cell(M,N,Z)) :- does(W,mark(M,N)) & true(cell(M,N,Z)) & Z!=b

next(control(white)) :- true(control(black))

next(control(black)) :- true(control(white))

Physics

Page 29: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

row(M,W) :- diagonal(W) :- true(cell(M,1,W)) & true(cell(1,1,W)) & true(cell(M,2,W)) & true(cell(2,2,W)) & true(cell(M,3,W)) true(cell(3,3,W))

column(N,W) :- diagonal(W) :- true(cell(1,N,W)) & true(cell(1,3,W)) & true(cell(2,N,W)) & true(cell(2,2,W)) & true(cell(3,N,W)) true(cell(3,1,W))

line(W) :- row(M,W)line(W) :- column(N,W)line(W) :- diagonal(W)

open :- true(cell(M,N,b))

Supporting Concepts

Page 30: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

goal(white,100) :- line(x)goal(white,50) :- ~line(x) & ~line(o)goal(white,0) :- line(o)

goal(black,100) :- line(o)goal(black,50) :- ~line(x) & ~line(o)goal(black,0) :- line(x)

terminal :- line(W)terminal :- ~open

Goals and Termination

Page 31: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Game Management

Page 32: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/54

Game Management is the process of administering a game in General Game Playing.

Match = instance of a game.

Components: Game Manager Game Playing Protocol

Game ManagementGame Management

Page 33: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Game ManagerGame Manager

Page 34: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/54

Start Manager sends Start message to players Start(id, role, description, startclock, playclock)

Game Playing ProtocolGeneral Game Playing Protocol

Page 35: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/54

Start Manager sends Start message to players Start(id, role, description, startclock, playclock)

Play Manager sends Play messages to players Play(id, actions) Receives plays in response

General Game Playing Protocol

Page 36: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

/54

Start Manager sends Start message to players start(id, role, description, startclock, playclock)

Play Manager sends Play messages to players play(id, actions) Receives plays in response

Stop Manager sends Stop message to players stop(id, actions)

General Game Playing Protocol

Page 37: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Game Playing

Page 38: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

cell(1,1,b)cell(1,2,b)cell(1,3,b)cell(2,1,b)cell(2,2,b)cell(2,3,b)cell(3,1,b)cell(3,2,b)cell(3,3,b)control(x)

Initial State

Page 39: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

White’s moves: Black’s moves: mark(1,1) noop mark(1,2) mark(1,3) mark(2,1) mark(2,2) mark(2,3) mark(3,1) mark(3,2) mark(3,3)

Legal Moves

Page 40: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

mark(1,3)

noop

State Update

cell(1,1,b) cell(1,1,b)cell(1,2,b) cell(1,2,b)cell(1,3,b) cell(1,3,x)cell(2,1,b) cell(2,1,b)cell(2,2,b) cell(2,2,b)cell(2,3,b) cell(2,3,b)cell(3,1,b) cell(3,1,b)cell(3,2,b) cell(3,2,b)cell(3,3,b) cell(3,3,b)control(x) control(o)

Page 41: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Complete Game Graph Search

X O X

O XO

X O X

O

X O X

O XOX

X O X

O XO X

X O X

O XOX

X O X

O X

X O X

OX

X O X

OX

X O X

OX

X O X

O X

Page 42: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Incomplete Game Tree Search

How do we evaluate non-terminal states?

X O X

O

X O X

O X

X O X

OX

X O X

OX

X O X

OX

X O X

O X

Page 43: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

First Generation GGP (2005-2006)

General Heuristics Goal proximity (everyone) Maximize mobility (Barney Pell) Minimize opponent’s mobility (Jim Clune)

Page 44: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

GGP-06 Final - Cylinder Checkers

Page 45: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Second Generation GGP (2007 on)

Monte Carlo Search

Monte Carlo Tree Search UCT - Uniform Confidence Bounds on Trees

Page 46: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

25 50 0 75

100 0 0 0 0 100 100 0 0 0 0 0 100 0 100 100

Second Generation GGP

Monte Carlo Search

Page 47: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Offline Processing of Game Descriptions Reformulate problem to decrease size of search space Compile to do the search faster

What human programmers do in creating game players

Third Generation GGP

Page 48: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

48

Conversion of logic to traditional programming language Simple, widely published algorithms several orders or magnitude speedup no asymptotic change

Conversion to Field Programmable Gate Arrays (FPGAs) several more orders of magnitude improvement

Compilation

Page 49: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Hodgepodge = Chess + Othello

Branching factor: a Branching factor: b

Analysis of joint game: Branching factor as given to players: a*b Fringe of tree at depth n as given: (a*b)n

Fringe of tree at depth n factored: an+bn

Game Factoring

Page 50: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Examples Factoring, e.g Hodgepodge Bottlenecks, e.g. Triathalon Symmetry detection, e.g. Tic-Tac-Toe Dead State Removal

Trade-off - cost of finding and using structure vs savings Sometimes cost proportional to size of description Sometimes savings proportional to size of game tree

Reformulation Opportunities

Page 51: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Automatic Programming

∀x.∀y.(p(x,y) ⇒ q(x,y))

p(a,b) q(b,c)

~p(b,d)∃x.p(x,d)p(c,b)∨ p(c,d)

Page 52: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

Expertise in a Box

Page 53: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

53

a b

a4

4

3

3

b2

2

1

1

a b

a4

4

1

1

b3

3

2

2

Opponent Modeling

Page 54: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

54

XOX

O

OX

Demoralizing the Opponent

Page 55: Logic Programming General Game Playinglogicprogramming.stanford.edu/lectures/ggp.pdf · 2019-04-20 · General Game Players are systems able to play arbitrary games effectively based

55