[Applause] hi I'm Tommy Thompson and welcome to AI 101 the series that explores the tools and techniques used in video game development the opening episodes of this series have taken a look at some of the long-established AI methodologies used in video games with navigation meshes and finite state machines being two of the earliest techniques to become commonplace then the second episode I looked at behavior trees a technique popularized by the Halo franchise in the mid 2000s that has since arguably become the most commonly used method for controlling non player characters in the triple-a games industry
in this episode we take a look at the other technique that achieved popularity at the same time and in keeping with the channel recently reaching 100,000 subscribers thank you all so much by the way you're friggin awesome what there time to return to the technology and the game where AI n games began let's take a look at goal-oriented action planning and the game that popularized it first encounter assault recon to understand goal-oriented action planning and in ton how it's used in fear and many other games we need to take a look at the theory from
which it derives from an existing AI technology known as automated planning automated planning or AI planning is a process whereby a system attempts to figure out a sequence of actions that will achieve a distant goal set upon it by a designer the set of actions is then called a plan to do this we model the problem in some sort of language or encoding that tells us all the information that can be true about the world at any given time these are known as facts or predicates where a simple fact tells us something we might need
to know a later point in time we store all of the predicates we have about how the world looks like at any point in time within what's known as a state for example here's a door we'll call it door one because it's important to give the door a name and this door is closed but I might want a non-player character to open door 1 at some point in the future so I need to know in a predicate whether it's open or closed because opening a door that's already open is kind of stupid so the current
state of our world is one closed door now given I have this information I can build an action that allows me to open it each planning action is usually broken up into three parts the items that are involved in the action in this case a door because we want to open it the actions preconditions meaning what facts of the world must be true before I can apply the action and the effects which represent how the world changes as a result of completing the action the effects of an action adds new information to the world State
as well as possibly deleting existing facts that are no longer true so say I want my non-player character to open door 1 some valid preconditions for an open door action would be that the door is closed and that the non player character is standing in the same room as the door once the action is completed the effect would be that the door is now open now say we wanted to walk our character from room a to room B but the door between them is closed we would need to make sure in our planning model that
we explained that door one connects room a to room B and that you cannot walk between rooms if there is a closed door at which point the system will create a plan which to open the door and then walk from room a to be changing the state of the world to where the NPC is Neven room B in a nutshell this is what planning is all about figuring out what to do and in what order to do it this process of encoding problems and allowing for planning systems to solve them is why it has been
an active in developing research field for decades while fear helped bring planning to games in 2005 planning has previously been used in a variety of real-world logistics problems as far back as the 1970s this includes problems such as robotics ranging from smaller home-based devices to the lakes of the lunar and Mars rovers control of large-scale mechanical systems such as when turbines power stations and manufacturing and in complex spatial problems such as search-and-rescue operations military planning and disaster relief but my explanation hides some of the nastier details underneath these planning encodings rely on humans being able
to abstract the problem or solving into something simple for a planner to solve returning to that door-opening problem I said that the NPC needs to be in room a and that door one connects the two rooms this works fine in a planning model but there's a bunch of discrepancies between the model and how that would work in real life or even in a video game for example we're in room a is the door to room B what direction does the NPC need to move towards the door in fact in the planning model the NPC can
open the door if they're in a room that the door connects to meaning this wee fella is now apparently telekinetic and can open doors with their mind from very far away this is in contrast to a more realistic interpretation which is that not only does the NPC need to be in room a but it also needs to be standing right next to door one in order to open it hence while planning is great for solving the larger problem of what to do in a given situation executing the plan of action in the world B in
the real world or in a video game is a lot harder so know that we know what planning is and how it works let's take a look at goal oriented action planning and how it brings AI planning to video games goal-oriented action planning or go for short adapts what is known as strips planning the Stanford Research Institute problem solver a planning system from 1971 for use in video games leading development on this project was dr. Jeff Orkin the AI lead from monolith productions on both 2002 s no one lives forever two and 2005 sphere where
Gope was first implemented as detailed in organs 2006 publication at the Game Developers Conference while studying his PhD at the MIT Media Lab the gulp system is driven by a finite state machine as detailed back in episode 3 of AI 101 a finite state machine is a system whereby an AI exists within one state of behavior and then based on an event occurring will transition into another one as we explored how FSM Tzar adopted in half-life we found that there was over 80 unique states that existed in the game's codebase although whether that state was
available was determined by the type of character that the state machine was controlling however here in gulp the finite state machine has only three states moving into a position in the world playing an animation or interacting with what is known as a smart object an item in the world AI characters can communicate with now you might be a little confused how this works but it's all based on a really clever observation of how non-player character AI works if you consider an AI in a game be it the headcrabs in half-life the elites in Halo or
even the xenomorph an alien isolation all they do is play animations in very specific circumstances it's when that animation is played in the right place at the right time appears clever and when several clever animations are played the sequence appears intelligent hence each of these three states within the gulp FSM is ultimately playing an animation goto is playing a movement animation be it walking running jumping diving or climbing but it's also heading to a specific location anime is simply playing an animation this could be acknowledging the player's presence to shooting their weapon or any simple
idle animation which would give this NPC a bit more character and lastly use smart object which is a situation such as having an NPC head switch up door set in a chair or knock a table over and each case the animation is tied directly to the object and quite often in games such as that found in my episode on the AI of BioShock Infinite the object will tell the characters animation system what it needs to do so instead of a more grounded state machine where each possible behavior is enumerated as a separate state the whole
thing is executed in a much smaller and highly data-driven implementation that will execute specific movement actions and animations are passed into the system and if several movement animation and smart object states are executed in the correct sequence we'll get some smart looking behavior but how does it know what States to be in and what order should it go through them and what information is to be passed into each state well that's where the planning power of gulp kicks in using a planning encoding like we talked about before the system creates plans that solve specific problems
in the planning encoding and uses a-star search to find the best actions to take in solving the problem the actions within the resulting plan are then translated into specific FSM States with data being passed such as locations to move towards animations to play and smart objects to interact with to better understand how this works in practice let's crack open the hood of fear and explore how gulp is adopted within the game so let's take a deeper look at how gulp is applied in fear portions of the game C++ code base have been publicly available for
some years now first with the original fear SDK being released by monolith followed by the fear public tools as models of continued support for it and with very little effort you can crack it open in Visual Studio and read through the AI source code so let's walk through how gulp is applied within the code base and for those wanting to try their hand themselves I've left links in the description for you to check out each AI character and fear that has any sort of a I need stir of goals assigned to it these goals are
ones that the planner will run a search through the action space in order to find a plan of action for that character to execute thus applies to all active non-player characters in the game from the soldiers and assassins to the nightmare specters at the end of the game and even the rats that are running around on the ground we is a super important point I'll come back to in a minute this means that the other characters such as jinsoon Quan and Jankowski and even Alma herself are all scripted by designers whether a goal the AI
characters will do literally nothing they need to be given goals to accomplish which the planning system will aim to resolve there are just shy of 70 goals encoded within the game's files and each case these goals can be initialized updated and terminated and more critically have functions that allow for them to calculate their overall priority at that point of time in the game so for example if a soldier has been assigned to patrol and kill enemy goals but has no knowledge of the player being nearby then kill enemy will have a priority of zero while
patrol has a much higher priority given there's a patrol node that's been assigned to that character however in the event that it has knowledge of the player being nearby the patrol goal will have a much lower priority given it recognizes that the player is never threat to it now in order for the planner to solve that goal the character will have a collection of actions available to it that it can search through there are a hundred and twenty actions in the game ranging from simple animations to different attack variants moving to locations using smart object
nodes reloading weapons or just standing idle all of which have their own corresponding C++ classes the actions are set up in code but not all NPCs have access to all actions the game's designers use a separate database editor to assign specific actions to each enemy type allowing them to customize just how versatile that character will be in solving their goals with a goal assigned to a given character it will await a chance to access the planner and find a solution to its current situation this is where the larger issues I hinted at earlier in the
video come too late the system needs to find actions that this particular character can execute search through the possible actions within the state space find a plan that reaches the goal but all of this needs to be revalidated against the game during execution this is because something can happen either during planning time or when executing the plan that can break it returning to my door example from earlier if you're generating a plan to open the door and move between rooms but during the planning process or as you're executing it the door is opened by someone
or something else it will then invalidate that plan this is an issue that the vast majority of planning systems face in that they're rather existential in nature and assumed only the planner can change the world so it can accommodate for other characters doing stuff in the world as part of the plan in fact as mentioned in the original fear video none of the enemy AI in fear know that each other exists and cooperative behaviors are simply two AI characters being given goals that line up nicely to create what looks like coordinated behaviors were executed not
only are they unable to walk towards navigation points in the world where other characters are standing but have zero knowledge of that kindness existence hence if another character does something that would break the proposed plan then each character needs to be able to recognize that so it stops what it's doing and asks for another plan or even change the goal if necessary this is handled in three different ways firstly once a plan is devised the system will then run a quick validation check it takes a copy of the current game State execute the plan on
that copy and ensures it will satisfy the goals as intended with each actions preconditions and effects working is Haupt secondly each goal can override the replan required function which continually checks whether the current plan should be abandoned and a replacement one be retrieved from the planner a good example of this is when an enemy character is shot while executing a plan to satisfy the kill enemy goal however this is only allowed in the event the character is not executing an animation that cannot be interrupted lastly each action in the plan needs to be validated again
during execution with preconditions and effects being checked and the event they are not satisfied as intended the system will bail out the plan and force a replan to a car however if that action is going to work as intended the action is activated in the codebase when that happens it tells the finite state machine which of the three states to transition into and passes over all of the data needs to complete the finite state machines execution so say for example a soldier needs to reload their weapon then it transitions into the anime state and passes
and the specific animation parameters that are needed so that the character will reload their gun once an AI character completes their device plans successfully it will then be assigned a new goal and can plan again by managing both when plans succeed as well as when they fail this helps maintain the pace of the game and shooting the AI always knows what to do and don't stand around idle waiting to be slow-mo shot in the face in truth the length of plans and fear are often rather short typically one to two actions long with only a
handful ever reaching three or four actions in length this largely makes sense given the overall pacing of the game that said the school management and planning process does create a problem one the even the developers at monolith didn't know about for many years as detailed in a 2014 research paper by Professor le Jia coupon in which he analyzes the performance of the goal planner and fear it's discovered that this process of continually replanting creates a small performance overhead in some levels of the game thanks to the wrath the wrath and fear are as I mentioned
using the same system as the soldiers and other combat AI typically their plans are really simple move to another location in the world and preferably away from the player if they're nearby the need for the rats to replan doesn't take into consideration whether the player is nearby hence you can meet a couple of rats in the opening seconds of the level and they'll still be running around planning for new actions 20 minutes later while you're on the other side of the map this is far from an exhaustive overview the codebase and I do encourage anyone
who can walk the way our own C++ to have a read through the code it's really insightful and rewarding for game developers to get their hands on fears use of goal-oriented action planning is still held to this day as some of the most exciting and fun enemy opponents to come across in modern video games and while it's now been almost 15 years since the game's release Gorp has continued to have a lasting impact within the video games industry well far from an exhaustive list there are many highly popular games and even cult classics that vyd
opted the methodology or something similar to it this includes the lakes of condemned criminal origins stalker shadow of Chernobyl Just Cause 2 Deus Ex Human Revolution the 2013 reboot of Tomb Raider and more recent titles by monoliths such as Middle Earth shadow of Mordor and shadow of war there are other episodes of AI in games that have explored its applications such as transformers war for Cybertron in episode 14 as well as a heavily modified hybrid approach an empire and Napoleon total war back in episode 22 planning is still a popular technique in video games though
arguably not as common as say behaviour trees but over time gulp and it's strip style approach is now being adopted less frequently with more contemporary titles adopting another planning technology known as hierarchical task network or HTN planning HTM planning has been used in titles such as Killzone 2 Max Payne 3 and dying late I'll be dedicating a future episode of AI 101 to this topic but I've already covered the implementation of this planning method in detail for transformers fall of Cybertron and also in episode 14 and horizon zero dawn over an episode 37 but for
now I hope this helps everyone better understand not only why people continue to laud the AI of fear but also the underlying technology being adopted I've listed some other useful resources on goal oriented action planning in the video description for you to check out thanks for watching this episode of AI 101 and a special thank you to each and every one of you who has subscribed to and support of the channel breaking 100,000 subscribers is still relatively small by YouTube's standards but still much larger than I ever envisaged for AI in games AI 101 alongside
all my other series here on the channel as crowdfunded over on patreon if you'd want to join our community and have a say in future episodes on the show join the AI in games patreon using the links on screen and in the description stay safe have fun and I'll be back [Music]