Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

60
INTRODUCTION TO AI STRIPS PLANNING .. and Applications to Video-games! May 2012 Stavros Vassos, University of Athens, Greece [email protected]

description

This is a short course that aims to provide an introduction to the techniques currently used for the decision making of non-player characters (NPCs) in commercial video games, and show how a simple deliberation technique from academic artificial intelligence research can be employed to advance the state-of-the art. For more information and downloading the supplementary material please use the following links: http://stavros.lostre.org/2012/05/19/video-games-sapienza-roma-2012/ http://tinyurl.com/AI-NPC-LaSapienza

Transcript of Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Page 1: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

INTRODUCTION TO AI

STRIPS PLANNING

.. and Applications to Video-games!

May 2012Stavros Vassos, University of Athens, Greece [email protected]

Page 2: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

2

Lecture 1: Game-inspired competitions for AI research,

AI decision making for non-player characters in games

Lecture 2: STRIPS planning, state-space search

Lecture 3: Planning Domain Definition Language (PDDL),

using an award winning planner to solve Sokoban

Lecture 4: Planning graphs, domain independent

heuristics for STRIPS planning

Lecture 5: Employing STRIPS planning in games:

SimpleFPS, iThinkUnity3D, SmartWorkersRTS

Lecture 6: Planning beyond STRIPS

Course overview

Page 3: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

STRIPS planning3

What we have seen so far

The STRIPS formalism for specifying planning problems

Solving planning problems using state-based search

Progression planning

Simple heuristics for progression planning

Can we take advantage of the information that

action schemas hold to do better?

Page 4: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs4

Action schemas provide useful information about the

interaction between actions

E.g., action A cannot take place right after B

because A cancels a precondition of B

There are many more (and more complex)

conditions that would be valuable to identify!

Page 5: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

5

Lecture 1: Game-inspired competitions for AI research,

AI decision making for non-player characters in games

Lecture 2: STRIPS planning, state-space search

Lecture 3: Planning Domain Definition Language (PDDL),

using an award winning planner to solve Sokoban

Lecture 4: Planning graphs, domain independent

heuristics for STRIPS planning

Lecture 5: Employing STRIPS planning in games:

SimpleFPS, iThinkUnity3D, SmartWorkersRTS

Lecture 6: Planning beyond STRIPS

Course overview

Page 6: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

Special data structure

Consists of a sequence of levels

Stores the effects of all applicable actions at every

level as if they were all happening concurrently

Stores some basic mutual exclusion constraints

between actions and literals

6

Page 7: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs7

Move(Β,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

On(Α,Table)On(Β,C)

On(C,Table)Clear(Α)Clear(Β)

Clear(Table)

Α Β C Α

Β

C

s0 s1

Move(Α,Table,Β)

s2

On(Α,Β)On(Β,C)

On(C,Table)Clear(Α)

Clear(Table)

Α

Β

C

Page 8: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs8

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

??????

Α1

??????

Page 9: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs9

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

???

Α1

???

Move(Β,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)On(Β,C)

On(Β,Table)

Clear(C)

Α

Β

C

Page 10: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs10

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

???

Α1

???Move(Α,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)On(Α,C)

On(Α,Table)

Clear(C)

Α

Β C

Page 11: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs11

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

???

Α1

???Move(Α,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)On(Α,C)

On(Α,Table)

Clear(C)

Α

Β C

Move(Β,Table,C)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Page 12: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs12

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

???

Α1

???Move(Α,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)On(Β,C)

On(Β,Table)On(Α,C)

On(Α,Table)

Clear(C)

Move(Β,Table,C)

Page 13: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs13

Α0

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)

Α Β C

s0 s1 s2

???

Α1

???Move(Α,Table,C)

On(Α,Table)On(Β,Table)On(C,Table)

Clear(Α)Clear(Β)Clear(C)On(Α,C)

On(Α,Table)

Clear(C)

Α

Β C

Move(Β,Table,C)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Move(Β,Table,Α)

Move(C,Table,Α)

Move(Α,Table,Β)

Move(C,Table,Β)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Α

Β

C

On(Β,C)

On(Β,Table)

Clear(C)

Page 14: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

Special data structure

Consists of a sequence of levels

Stores the effects of all applicable actions at every

level as if they were all happening concurrently

Stores some basic mutual exclusion constraints

between actions and literals

.. Let’s see an (even) simpler example!

14

Page 15: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Init( Have(Cake) )

Goal( Have(Cake) Eaten(Cake) )

Action( Eat(Cake)PRECONDITIONS: Have(Cake)

EFFECTS: Have(Cake) Eaten(Cake) )

Action( Bake(Cake),PRECONDITIONS: Have(Cake)

EFFECTS: Have(Cake) )

15

Page 16: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

Consists of a sequence of levels that specify how the initial

state is transformed under the effects of actions

At each level i we specify

A list of literals Si

A list of actions Ai

4 kinds of constraints or mutual exclusion links between literals

in Si and actions in Ai

16

Page 17: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs17

Level 0

S0: the positive literals of the initial state as well as the

negative literals implied by the closed world assumption

Α0s0 s1 s2

Α1

Have(C)

Eaten(C)

Page 18: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs18

Level 0

We will see now how to specify Α0 and S1

Α0s0 s1 s2

Α1

Have(C)

Eaten(C)

Page 19: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs19

Level 0

Α0: the applicable actions in the initial state

Α0s0 s1 s2

Α1

Have(C)

E(C)

Eaten(C)

Page 20: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs20

Level 0

S1: the effects of actions that appear in Α0

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C)

Page 21: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

E(C)

Planning graphs21

Level 0

We’re not done yet!

Α0s0 s1 s2

Α1

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Page 22: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs22

Level 0

We’re not done yet!

Also add persistence actions that denote “inaction”

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 23: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs23

Level 0

A persistent action specifies that a literal does not

change truth value between levels, e.g., here Eaten(C)

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 24: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs24

Level 0

We’re not done yet!

Mutual exclusion links

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 25: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs25

Mutual exclusion links (mutex)

Inconsistent effects

Interference

Inconsistent support

Competing needs

Page 26: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs26

Two actions have inconsistent effects when:

One action cancels the effect of the other action

E.g., action E(C) and the persistent action for Have(Cake) have inconsistent effects

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 27: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs27

Two actions have inconsistent effects when:

One action cancels the effect of the other action

Same for action E(C) and the persistent action for Eaten(C)

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 28: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs28

Two actions have an interference when:

One effect of one action is the negation of a precondition for the other action

E.g., action E(C) and the persistent action for Have(C)

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 29: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs29

Two literals have inconsistent support when:

One literal is the negation of the other literal

E.g., Have(C) and Have(C)

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 30: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs30

Two literals have inconsistent support when:

Every possible pair of action that have these literals as

effects are marked as mutually exclusive

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 31: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs31

Two actions have competing needs when:

A precondition of one action is mutually exclusive with a

precondition of the other action

Does not arise in this domain

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 32: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs32

Level 0

We are (finally) done!

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 33: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs33

What kind of information does the graph provide so

far?

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 34: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs34

A pair of mutually exclusive literals cannot be realized

from the actions of Level 0!

E.g., the goal cannot be achieved with these actions

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 35: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs35

Level 1

We will specify A1 and S2

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

Page 36: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs36

Level 1

Α1: the applicable actions in S1 (at least those in Α0)

S2: the effects of actions in Α1 (at least those in S1)

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Page 37: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs37

Level 1

Α1: the applicable actions in S1 (and more!)

S2: the effects of actions in Α1

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 38: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs38

Level 1

Α1: the applicable actions in S1 (and more!)

S2: the effects of actions in Α1

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 39: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs39

Level 1 Mutual exclusive links

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 40: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs40

Level 1 Mutual exclusive links

Inconsistent effects between persistence actions

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 41: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs41

Level 1 Mutual exclusive links

Inconsistent effects between B(C), E(C) and persistence actions

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 42: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs42

Level 1 Mutual exclusive links

Inconsistent effects between B(C), E(C) and persistence actions

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 43: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs43

Level 1 Mutual exclusive links

Competing needs between persistence actions!

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C) Have(C)

Have(C)

Eaten(C)

Eaten(C)

Page 44: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs44

Level 1 Mutual exclusive links

No more mutexes between actions

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 45: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs45

Level 1 Mutual exclusive links

There are mutexes between literals in S2 though

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 46: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs46

Level 1 Mutual exclusive links

Between literals Have(C) and Eaten(C) in S2

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Page 47: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs47

Level 1 Mutual exclusive links

Between literals Have(C) and Eaten(C) in S2

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Page 48: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs48

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Level 1 Mutual exclusive links

Between literals Have(C) and Eaten(C) in S2

Page 49: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs49

Level 1 We are (finally) done!

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 50: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs50

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

Page 51: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs51

What information can we get from the graph now?

Note that literals Have(C) and Eaten(C) are not mutually

exclusive in S2 !!!

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

Page 52: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs52

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

Note that literals Have(C) and Eaten(C) can be realized in A1

by the actions {B(C), persistence of Eaten(C)}

Page 53: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs53

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

In turn actions {B(C), persistence of Eaten(C)} require that

Have(C) and Eaten(C) hold in S1

Page 54: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs54

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

Note that literals Have(C) and Eaten(C) can be realized in A0

by the action E(C)

Page 55: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs55

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

In turn E(C) requires that Have(C) holds in S0 which is true!

Page 56: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs56

Α0s0 s1 s2

Α1

Have(C)

E(C) Have(C)

Eaten(C)

Eaten(C) Eaten(C)

Have(C)

E(C)

Have(C)

Have(C)

Eaten(C)

Eaten(C)

Β(C)

What information can we get from the graph now?

So, actions {E(C)} and {B(C), persistence of Eaten(C)}

can actually achieve the goal!

Page 57: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

57

Page 58: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

When do we stop calculating levels?

When two consecutive levels are identical *

How do we know this will happen at some point?

Literals and actions increase monotonically, while

mutexes decrease monotonically (why is this so?)

58

Page 59: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Planning graphs

Planning graph

Special data structure

Easy to compute: polynomial complexity!

Can be used by the GRAPHPLAN algorithm to search

for a solution (following similar reasoning as in the

example)

Can be used as a guideline for heuristic functions for

progressive planning that are more accurate than the

ones we sketched in Lecture 2

59

Page 60: Intro to AI STRIPS Planning & Applications in Video-games Lecture4-Part1

Bibliography60

Material

Artificial Intelligence: A Modern Approach 2nd Ed. Stuart Russell,

Peter Norvig. Prentice Hall, 2003 Section 11.4