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 Action 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 After Nap Concert in Chair After Sleep in Bed Fun 8 62 02 92 132 Energy 6 72 92 42 02 100 85 81 107 169 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 Need Current level After Nap in Chair Then After Go to Concert Fun 8 92 02 Energy 6 42 72 100 107 49 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 Need Time 0 Fun 8 52 22 02 12 Energy 6 72 82 92 72 Total 100 74 68 81 50 Need Time 0 Total discontentment: Fun 8 92 62 32 02 240 Energy 6 42 52 62 72 100 85 61 45 49 Total discontentment: 273 Total Time 1 (concert) Time 1 (nap) Time 2 (concert) Time 2 (concert) Time 3 (concert) Time 3 (concert) Time 4 (nap) Time 4 (concert) Planning and Search Trees • Must try all possible combinations of actions – Compute total discontentment for each path – Choose path with lowest total root Go to Concert Paint Paint Paint Paint Go to Conc ert Nap in Chair Sleep in Bed Nap in Chair Paint Paint Paint Go to Conc ert Paint Nap in Chair Go to Conc ert Go to Conc ert Go to Conc ert Nap in Chair Go to Conc ert Sleep in Bed Nap in Chair Go to Conc ert Nap in Chair Nap in Chair Sleep in Bed Nap in Chair Sleep in Bed Sleep in Bed Paint Sleep in Bed Go to Conc ert Sleep in Bed Nap in Chair Sleep in Bed Sleep in Bed 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 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 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) Discontentment at this state= 150 Total discontentment to this point = 180 Total discontentment = 172 No path can be better than best found so far, so no further search Unacceptably bad, so no further search Planning and Preconditions • Actions may have preconditions before they can be taken Preconditions Action Postconditions • Multiple actions required to meet needs Preconditions which character meets Action Postconditions meets Preconditions Action Postconditions meet need Planning and Preconditions • Example: Microwaving food Uncooked food in fridge Get food Have uncooked food meets Have uncooked food Have microwave Cook food in microwave Have cooked food meets Have cooked food Eat food Hunger - 5 Planning Methods • Depth-limited search – Try all combinations of actions up to lookahead limit – Can prune branches with actions whose preconditions not met Get food Cook food in microwave Prerequisite not met Cook food in microwave • Expensive – Design world so actions require few steps (2 or 3 at most) Planning Methods • Scripted action sequences – Actually single action with what appears to be multiple steps – Long animated sequence Have uncooked food Have microwave Get food Cook food in microwave Eat food Hungry - 5 • 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 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 Have uncooked food Have microwave Get food from fridge Cook food in microwave Eat food Hungry - 5 – Other prerequisites can then become goals for character • Tell player to buy microwave for character • Search for microwave…