Planners are certainly getting more popular in game studios these days, but there’s still a very long way to go before developers reach the same level of understanding as for traditional scripted systems. One area in particular that causes problems is dealing with dynamic situations.
Tobe Mayr, a former colleague and designer at Rockstar, wrote a very interesting comment [1] about the use of planners yesterday on the post about SHOP:
“This approach seems very useful in a deterministic or stable environment, say, a slow-evolving strategy game. How about games that feature radical changes in short time spans? E.g. shooters with multiple objectives that need to be re-evaluated whenever conditions change dramatically?”
Since that last article was rather academic, it’s a good opportunity to balance it out with something more practical…
Screenshot 1: Highly dynamic situations in Grand Theft Auto 4.
Sometimes It’s Black and White
Anyway, Tobe is absolutely right on two counts in his comments about hierarchical task network (HTN) planners:
Hierarchical planners are perfectly suited to static worlds where the AI has long term goals. However, those types of problems are very rare in games; the player interaction makes everything dynamic!
On the other hand, such planners are not necessary for problems where you want the AI actors to behave in a purely reactive fashion. You might as well be using a state machine.
That covers the black and white cases… but in practice, most often you’ll end up somewhere in the middle.
What About the Other Cases?
Assuming you want your AI to solve context-sensitive problems in a purposeful way, then I’m going to make the argument that both hierarchies and planners can still be very useful to build reactive AI.
- Hierarchies
- A hierarchy helps design responsive AI because they’re a simple yet powerful way to express behaviors. You can break down the top level combat behaviors into sub-behaviors for attacking, and easily specify when each of them should be interrupted. This is why HFSM work so well. These same ideas make hierarchical planners equally useful for complex dynamic problems too.
- Planning
- Planners help because they allow you to reduce the amount of work necessary to connect states. Instead of building a large spaghetti state machine, you build modular parts and let an automated algorithm plug together the blocks to solve problems dynamically.
As a matter of fact, Jeff Orkin who created the planner for F.E.A.R. mentioned in his GDC talk that his use of the planner mainly helped generate reactive behaviors in a much simpler way. The soldier behaviors were a little more complex than games before, but they were primarily much easier to edit and build up modularly.
Screenshot 2: Worlds in GTA 4 require adaptive behaviors from player and AI.
Planners In Practice
Effectively, a hierarchical planner can be applied to situations in games where responsive behaviors are required, and it’ll generally help maintain the codebase and keep things simple.
However, there are a few things to watch out for compared to building a normal state machine: You’ll need to:
Keep running your planner very regular basis (multiple times per second, e.g. 5 Hz) to compute new plans.
Use logic to prevent unnecessary work by trying to detecting relevant changes, and using level of detail for different characters.
Detect redundant plans (or duplicates) and don’t execute them from scratch every time.
Add simple logic to prevent oscillations in the behaviors and commit to a particular course of action when appropriate.
This part of applying planners is harder than the actual theory itself. Start simple, then as you need more logic to manage the planner, start building simple state machines to deal with changes in the world and feed the data to the planner appropriately. Also be sure to see how the code in the F.E.A.R. SDK handles these problems.
Do you think planners can and should be applied to problems where responsive behaviors are required? If not, why not?













