Toward Real-Time Planning in Games

59
Toward Real-Time Planning in Games Jeff Orkin Monolith Productions

description

Toward Real-Time Planning in Games. Jeff Orkin Monolith Productions. F.E.A.R. Agenda. What Why How. Agenda. What do we mean by planning? Why use planning in games? How can we use planning in practice?. What do we mean by “planning?”. Typical Game AI. Goal-Oriented Planning. - PowerPoint PPT Presentation

Transcript of Toward Real-Time Planning in Games

Page 1: Toward Real-Time Planning in Games

Toward Real-Time Planning in Games

Jeff Orkin

Monolith Productions

Page 2: Toward Real-Time Planning in Games

F.E.A.R.

Page 3: Toward Real-Time Planning in Games

Agenda

WhatWhyHow

Page 4: Toward Real-Time Planning in Games

Agenda

What do we mean by planning?

Why use planning in games?

How can we use planning in practice?

Page 5: Toward Real-Time Planning in Games

What do we mean by “planning?”

Page 6: Toward Real-Time Planning in Games

Typical Game AI

Idle

Chase

Attack

DrawWeapon

Page 7: Toward Real-Time Planning in Games

Goal-Oriented Planning

Idle

Chase

Attack

DrawWeapon

Elim inateT hreat

Page 8: Toward Real-Time Planning in Games

Regressive Planning

Idle

Chase

Attack

DrawWeapon

Elim inateT hreat

Page 9: Toward Real-Time Planning in Games

Dynamic Planning

Idle

Chase

Attack

DrawWeapon

Elim inateT hreat

Page 10: Toward Real-Time Planning in Games

P.Diddy

Page 11: Toward Real-Time Planning in Games

P.D.D.L.

Planning Domain Definition Language Goals

– Desired state

Actions– Preconditions– Effects

Page 12: Toward Real-Time Planning in Games

PDDL

Goal:(define (problem get-paid)

(:domain briefcase-world)(:init (place home) (place office)

(object p) (object d) (object b)(at B home) (at P home) (at D home) (in

P))(:goal (and (at B office) (at D office) (at P home))))

Page 13: Toward Real-Time Planning in Games

PDDL

Action:(:action put-in

:parameters (?x - physob ?l - location):precondition (not (= ?x B)):effect (when (and (at ?x ?l) (at B ?l))

(in ?x)) )

Other actions: take-out, move

Page 14: Toward Real-Time Planning in Games

PDDL

Modular– Goals– Actions

Decoupled Modules Related by symbols– World State– Preconditions– Effects

Applied PDDL’s structure to C++ toolkit in game code.

Page 15: Toward Real-Time Planning in Games

Why use planning in games?

Page 16: Toward Real-Time Planning in Games

Sharing Behavior between NPCs

Reload

Goto

Attack

DrawWeapon

Elim inateT hreat

Flush OutT hreat

Chase

Cloak

Stickto Wall

Alien Soldier

Page 17: Toward Real-Time Planning in Games

Sharing Behavior between Projects

Reload

Goto

Attack

DrawWeapon

Elim inateT hreat

Flush OutT hreat

Chase

Cloak

Stickto Wall

Sci-Fi WWII

Page 18: Toward Real-Time Planning in Games

Sharing Behavior: Data Points

7 Character types in FEAR

62 Actions 41 Actions shared between projects 20 Actions shared between characters in FEAR

35 Goals 21 Goals shared between projects 21 Goals shared between characters in FEAR

Page 19: Toward Real-Time Planning in Games

Workflow

Division of Labor:

Im plem entsensors andac tuators in C ++ .

Im plem entbehaviors in C ++ .

C ons truc t w orlds .

P lace scenarios .

A ss ign behaviorsto N P C s.

E N GIN E E R :D E S IGN E R :

Page 20: Toward Real-Time Planning in Games

Workflow

Division of Labor:

Im plem entsensors andac tuators in C ++ .

Im plem entbehaviors in C ++ .

C ons truc t w orlds .

P lace scenarios .

A ss ign behaviorsto N P C s.

E N GIN E E R :D E S IGN E R :

HOWWHAT

Page 21: Toward Real-Time Planning in Games

Workflow

Division of Labor:

LOGICDATA

E N GIN E E R :D E S IGN E R :

HOWWHAT

Page 22: Toward Real-Time Planning in Games

The Best Day of

My Professional Life

Page 23: Toward Real-Time Planning in Games

Workflow

Page 24: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 25: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 26: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 27: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 28: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 29: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 30: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 31: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 32: Toward Real-Time Planning in Games

Robust Behavior

DrawWeapon

Pick UpWeapon

Goto

Attack

Elim inateT hreat

Page 33: Toward Real-Time Planning in Games

Maintenance

Idle

Patrol

Attack

Page 34: Toward Real-Time Planning in Games

Maintenance

Idle

Patrol

AttackDraw

Page 35: Toward Real-Time Planning in Games

Maintenance

Idle

Patrol

AttackDrawPickUp

Page 36: Toward Real-Time Planning in Games

Maintenance

Idle

Patrol

AttackDrawPickUp

Page 37: Toward Real-Time Planning in Games

Maintenance

Idle

Patrol

AttackDrawPickUp

Dismount

Page 38: Toward Real-Time Planning in Games

How can we use planning in practice?

Page 39: Toward Real-Time Planning in Games

How can we use planning in practice?

Symbols Plan Formulation Planning Frequency Plan Granularity

Page 40: Toward Real-Time Planning in Games

F.E.A.R. Demo

Page 41: Toward Real-Time Planning in Games

Symbols

Key-Value pairs

Enumerated keys– kKey_WeaponLoaded– kKey_AtPosition

Values – union of types– bool– int– float– enum– etc…

Page 42: Toward Real-Time Planning in Games

Symbols

Array of Key-Value pairs represents:– State of world– Goal satisfaction conditions– Action preconditions– Action effects

Page 43: Toward Real-Time Planning in Games

Symbols

Elim inateEnem y

Attack

Goal: kTargetIsDead = TRUE

Eff: kTargetIsDead = TRUEPre: kWeaponIsArmed = TRUE

DrawWeapon

Eff: kWeaponIsArmed = TRUEPre: None

Page 44: Toward Real-Time Planning in Games

Plan Formulation

A* search for sequence of actions– Action is neighbor if effect satisfies an existing

precondition.– Actions hashed by effect.– Heuristic: minimize number of unsatisfied

preconditions.

Page 45: Toward Real-Time Planning in Games

Key:

kTargetIsDead

Cur Value: Goal Value:

truefalse

Attack

Key:

kTargetIsDeadkWeaponIsArmed

Cur Value: Goal Value:

true true

true false

Key:

kTargetIsDeadkWeaponIsArmed

Cur Value: Goal Value:

true true

true true

DrawW eapon

Key: Value:

kTargetIsDeadkWeaponIsArmed

Effect:Precond:

truetrue

Key: Value:

kWeaponIsArmedNone

Effect:Precond:

true--

Page 46: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Page 47: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Agent-centric representation.

Page 48: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Agent-centric representation– Subsystem handles target selection.– Less symbols to evaluate during plan formulation.

Page 49: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Page 50: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Context preconditions.

Page 51: Toward Real-Time Planning in Games

Symbolic Representation Strategies

Context preconditions– aka Filter conditions.– Alternative to symbolic preconditions.– Test precondition(s) with arbitrary piece(s) of code.– Prune search tree.

Symbolic preconditions are only used when we want the planner to find a preceding action.

Page 52: Toward Real-Time Planning in Games

Planning Frequency

Do NOT plan every frame! Plan may last seconds or minutes. Only re-plan when:

– Goal changes.– Action invalidated.– Target changes.

Page 53: Toward Real-Time Planning in Games

Planning Frequency

Action duration:– Finite (e.g. ReloadWeapon)– Variable (e.g. Goto)– Infinite (e.g. Attack)

Page 54: Toward Real-Time Planning in Games

Planning Frequency

Action invalidation:– Out of ammo.– Target dead.– Path obstructed.

Page 55: Toward Real-Time Planning in Games

Planning Granularity

Fine grained:– Look at target– Walk in range of target– Turn toward target– Move right hand to holster– Unholster weapon– Raise right hand– Aim weapon– Fire weapon– Move left hand to weapon– Reload weapon

Page 56: Toward Real-Time Planning in Games

Planning Granularity

Course grained:– Defeat player

Page 57: Toward Real-Time Planning in Games

Planning Granularity

Happy medium:– Goto target– Draw weapon– Attack– Reload

Subsystems handle details:– Animation– NPC movement & rotation– Target selection & aiming

Page 58: Toward Real-Time Planning in Games

Take-Away

Use planning in games! Minimize number of symbols with agent-

centric representation. Prune search with context preconditions. Only re-plan when necessary. Delegate details to sub-systems.

Page 59: Toward Real-Time Planning in Games

Questions?

Jeff Orkin

Monolith Productions

http://www.jorkin.com