Artificial Intelligence in Game Design Goal-Oriented Action Planning.

27
Artificial Intelligence in Game Design Goal-Oriented Action Planning

Transcript of Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Page 1: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Artificial Intelligence in Game Design

Goal-Oriented Action Planning

Page 2: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning

• Creating series of actions to meet some goal

• Planning actions to meet multiple needs– Chosen so final state has highest utility

– Intermediate states after part of sequence should not be unacceptable– Allows fast actions to be chosen in logical circumstances

• Planning actions with multiple steps before payoff– Purchase ingredients– Cook ingredients in oven– Eat meal

– No effect on hunger until after last step

Page 3: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning ExampleAction Effect on Fun Effect on Energy

Paint -2 +1

Go to Concert -9 +3

Nap in Chair +1 -2

Sleep in Bed +5 -10

Need Current level

After Paint After Go to Concert

After Nap in Chair

After Sleep in Bed

Fun 8 62 02 92 132

Energy 6 72 92 42 02

Total effect 100 85 81 107 169

Best action if single action allowed

Will be very tired afterward!

Page 4: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning Example

• Better approach for two large needs:– Take fast action to relieve one

– Then take another action to relieve other

• Example: – Take nap before concert

Need Current level After Nap in Chair Then After Go to Concert

Fun 8 92 02

Energy 6 42 72

Total effect 100 107 49

Better than taking single action

Page 5: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Search Trees

• Must try all possible combinations of actions– Compute total discontentment for each path

– Choose path with lowest total

root

Sleep in Bed

Nap in Chair

Go to Concert

Paint

Paint

Paint

Paint

Go to Conc

ert

Paint

Nap in

Chair

Paint

Sleep in

Bed

Go to Conc

ertPaint

Go to Conc

ertGo to Conc

ert

Go to Conc

ertNap in

Chair

Go to Conc

ertSleep

in Bed

Nap in

ChairPaint

Nap in

ChairGo to Conc

ert

Nap in

ChairNap in

Chair

Nap in

ChairSleep

in Bed

Sleep in

BedPaint

Sleep in

BedGo to Conc

ert

Sleep in

BedNap in

Chair

Sleep in

BedSleep

in Bed

Page 6: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Search Trees

• Expanding search tree is costly– Given a possible actions– Given n possible levels

• an possibilities to test– Will only be able to test small number of action combinations (lookahead

limit)

– Even two actions enough to seem intelligent• Looks like character thinking ahead

Page 7: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Search Trees

• Algorithm: depth limited search– Depth-first search to some fixed limit n

• an leafs in tree

– At each leaf, compute discontentment

– Just keep track of best path found so far• Storage cost: n

Best sequence of actions found so far

Current path being tested

Page 8: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Pruning and Search Trees

• Can cut off search down obviously bad branches– Branches with intermediate state unacceptably bad

– Can possibly save search time (but no guarantee)

Discontentment = 172

Character dead

No path can be better than best found so far, so no further search

Character dead

No path can be better than best found so far, so no further search

Page 9: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Preconditions

• Actions may have preconditions before they can be taken

• Multiple actions required to meet needsActionPreconditions Postconditions

ActionPreconditions which character meets

Postconditions

ActionPreconditions Postconditionsmeet need

meets

Page 10: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Preconditions

• Example: Microwaving food

Get foodUncooked food in fridge

Have uncooked food

Cook food in microwave

Have uncooked foodHave microwave

Have cooked food

meets

Eat foodHave cooked food

Hunger - 5

meets

Page 11: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

STRIPS Planning

• Simple planning for worlds with preconditions on actions– “Stanford research intelligent planning system”– Prohibitively expensive for complex problems (thousands of

possible actions, prerequisites, etc.)

– Widely used in games where actions limited(Quake, Age of Empires, etc.)

• Plan of attack for single NPC• Series of actions to meet large-scale goal

(“increase number of citizens farming”)

ActionPreconditions Postconditions

Page 12: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

STRIPS Planning

• Regressing searching: Working backwards from goals to preconditions

goallist = {unmet needs}while (unmet goals in goallist) { choose goal G from goallist select action A with G in postconditions remove G from goallist add unmet preconditions of A to goallist }

Page 13: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

STRIPS Planning Example

• Initial goal

• Choose “attack” action which meets initial goal

• Precondition added to list

• Choose “load weapon” to meet precondition

• Its precondition added

• That precondition already true, so plan complete

Page 15: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning as Search

• Can take form of search tree– Depth-limited search

• Must backtrack if current plan has unmeetable preconditions– Adds appearance of intelligence– Can be expensive if happens too often

Open DoorDoor unlocked

Get KeyKey in current room

Door unlockedNo available action has this as postcondition

Pick Lock Door unlockedBacktrack and try this action

Page 16: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning as A* Search

• Can use A* to choose next action to add to tree • Cost of path found so far

– Actions assigned costs – Cost of rest of plan from current state =

sum of actions from current state to goal

• Heuristic estimate of rest of path– Number of unmet preconditions– Possibly weighted by some “expected cost” measure

ActionPrecondition Goal

Precondition

Precondition

Action

Page 17: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning as A* Search

• Example:– “Open Door” action has cost 1– “Get Key” action has cost 2– “Pick Lock” action has cost 5– “Key in current room” precondition estimated cost = 1

Open DoorDoor unlocked

Get KeyKey in current room

Door unlockedTry first since estimated path cost = 4

Pick Lock Door unlockedTry next since estimated path cost = 6

Page 18: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning as Tree Building

• Actions with multiple preconditions represented as trees – Actions with preconditions Nodes with preconditions as branches– Actions with no preconditions Leafs

Build Cannons

Build Cannon Factory

Produce Cannons in Factory

Order troops to collect 1000 wood

Mine iron

Have 1000 wood

Have 1000 iron

Build Iron Mine

Order troops to mine 1000 iron

Order troops to collect 100

wood

Page 19: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning and Scheduling

• Key question: How to schedule the actions that result from plan– Some branches may have to be accomplished before others– Some branches can be done in parallel

Build Cannons

Build Cannon Factory

Produce Cannons in Factory

Order troops to collect 1000 wood

Mine ironBuild Iron Mine

Order troops to mine 1000 iron

Order troops to collect 100

wood

preceeds

preceeds

Can be done in parallel

Page 20: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Hierarchical Planning

• Overall plan created at different levels of abstraction• Low-level subplans created to do higher level tasks

– High-level tasks have preconditions and postconditions– High-level tasks have methods for expanding into subplans– Steps of subplan accomplishes postconditions given preconditions

Task TaskTaskPreconditions Postconditions

Main plan

ActionPreconditions PostconditionsTask Action

SubplanAction Action

Page 23: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning for Hierarchical Teams

• Goals of team should direct goals of individuals• Individuals take actions to support overall actions of team

Page 24: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning for Hierarchical Teams

• Individual units meet goal based on individual abilities– No micromanaging from overall system

Search all rooms

Open DoorPick LockLook in Room

Look in Room with X-ray Vision

Smash Door

Look in Room

Overall team goal

Page 25: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning for Hierarchical Teams

• Individual units can balance team goals with individual goals to give appearance of independent thought

• Each individual/subteam has relevance measure for different goals

• Meets goal with highest current relevance

Goal Charge TakeCover Retreat Patrol

Relevance 0.6 0.8 0.3 0.0

Current action

Page 26: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning for Hierarchical Teams

• Individual goal modified by goals of team– Example: Leader orders squad to charge, and not retreat

Current action

Goal Charge TakeCover Retreat Patrol

Relevance 0.6 0.8 0.3 0.0

Modifier 0.5 0.0 -0.5 0.0

Total 1.1 0.8 -0.2 0.0

Page 27: Artificial Intelligence in Game Design Goal-Oriented Action Planning.

Planning for Hierarchical Teams

• If individual goals strong, team goals may be overridden!– Example: Leader orders squad to patrol– This unit currently under ambush

Current action

Goal Charge TakeCover Retreat Patrol

Relevance 0.4 0.8 0.6 0.0

Modifier 0.0 0.0 0.0 0.5

Total 0.4 0.8 0.6 0.5