artificial intelligence in game design lecture 17: goal oriented action planning

14
Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Upload: edward-leon-elliott

Post on 17-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Artificial Intelligence in Game Design

Lecture 17: Goal Oriented Action Planning

Page 2: Artificial Intelligence in Game Design Lecture 17: 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 Lecture 17: 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 Lecture 17: 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 Lecture 17: Goal Oriented Action Planning

Planning and Utility

• Why choose this order?– Why take nap before concert instead of going to concert first?

• Goal: Minimize “total discontentment” over time

Σ discontentment at time t t Need Time 0 Time 1

(concert)Time 2 (concert)

Time 3 (concert)

Time 4 (nap)

Fun 8 52 22 02 12

Energy 6 72 82 92 72

Total 100 74 68 81 50

Total discontentment: 273

Total discontentment: 240

Need Time 0 Time 1(nap)

Time 2 (concert)

Time 3 (concert)

Time 4 (concert)

Fun 8 92 62 32 02

Energy 6 42 52 62 72

Total 100 85 61 45 49

Page 6: Artificial Intelligence in Game Design Lecture 17: 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 7: Artificial Intelligence in Game Design Lecture 17: 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 8: Artificial Intelligence in Game Design Lecture 17: 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 total 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 9: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Pruning and Search Trees

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

– Branches with total discontentment more than best sequence found so far

– Can possibly save search time (but no guarantee)

Total discontentment = 172

Total discontentment to this point = 180

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

Discontentment at this state= 150

Unacceptably bad, so no further search

Page 10: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Planning and Preconditions

• Actions may have preconditions before they can be taken

• Multiple actions required to meet needs

ActionPreconditions Postconditions

ActionPreconditions which character meets

Postconditions

ActionPreconditions Postconditionsmeet need

meets

Page 11: Artificial Intelligence in Game Design Lecture 17: 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 12: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Planning Methods

• Depth-limited search– Try all combinations of actions up to lookahead limit

– Can prune branches with actions whose preconditions not met

• Expensive– Design world so actions require few steps (2 or 3 at most)

Get food

Cook food in microwave

Cook food in microwave

Prerequisite not met

Page 13: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Planning Methods

• Scripted action sequences– Actually single action with what appears to be multiple steps

– Long animated sequence

• Very simple to implement (no planning needed!)• Weaknesses:

– Cannot interrupt sequence without starting over entirely• Phone rings while cooking

– Cannot start plan until all preconditions met

Get foodCook food in microwave

Eat food

Have uncooked foodHave microwave

Hungry - 5

Page 14: Artificial Intelligence in Game Design Lecture 17: Goal Oriented Action Planning

Opportunistic Planning

• What if not all preconditions for plan exist?– Can get uncooked food– No microwave to cook food (yet)– Should still buy the food if hungry!

• Opportunistic planning: Taking actions which may pay off in future– Meets one of several prerequisites for action

– Other prerequisites can then become goals for character• Tell player to buy microwave for character• Search for microwave…

Get food from fridgeCook food in microwave

Eat food

Have uncooked foodHave microwave

Hungry - 5