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
Planning Example ActionEffect on FunEffect on Energy Paint-2+1 Go to Concert-9+3 Nap in Chair+1-2 Sleep in Bed+5-10 NeedCurrent level After PaintAfter Go to Concert After Nap in Chair After Sleep in Bed Fun Energy Total effect Best action if single action allowed Will be very tired afterward!
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 NeedCurrent levelAfter Nap in ChairThen After Go to Concert Fun Energy Total effect Better than taking single action
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 NeedTime 0Time 1 (concert) Time 2 (concert) Time 3 (concert) Time 4 (nap) Fun Energy Total Total discontentment: 273 Total discontentment: 240 NeedTime 0Time 1 (nap) Time 2 (concert) Time 3 (concert) Time 4 (concert) Fun Energy Total
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 Go to Conc ert Paint Nap in Chair Paint Sleep in Bed Go to Conc ert Paint Go to Conc ert Nap in Chair Go to Conc ert Sleep in Bed Nap in Chair Paint Nap in Chair Go to Conc ert Nap in Chair Sleep in Bed Paint Sleep in Bed Go to Conc ert Sleep in Bed Nap in Chair Sleep in Bed
Planning and Search Trees Expanding search tree is costly –Given a possible actions –Given n possible levels a n 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
Planning and Search Trees Algorithm: depth limited search –Depth-first search to some fixed limit n a n 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
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
Planning and Preconditions Actions may have preconditions before they can be taken Multiple actions required to meet needs Action PreconditionsPostconditions Action Preconditions which character meets Postconditions Action PreconditionsPostconditions meet need meets
Planning and Preconditions Example: Microwaving food Get food Uncooked food in fridge Have uncooked food Cook food in microwave Have uncooked food Have microwave Have cooked food meets Eat food Have cooked food Hunger - 5 meets
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 Prerequisite not met
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 food Cook food in microwave Eat food Have uncooked food Have microwave Hungry - 5
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 fridge Cook food in microwave Eat food Have uncooked food Have microwave Hungry - 5