18
3/28/15 1 AI Architectures Gustavo Patow IMAE UdG Par7ally based on AI Architectures: A Culinary Guide h>p://intrinsicalgorithm.com/IAonAI/tag/hfsm/ Mexican Food Analogy The outside is a content delivery mechanism

AI Architectures

  • Upload
    dagush

  • View
    23

  • Download
    4

Embed Size (px)

DESCRIPTION

AI architectures for game programming

Citation preview

  • 3/28/15

    1

    AI Architectures

    Gustavo Patow IMAE - UdG

    Par7ally based on AI Architectures: A Culinary Guide h>p://intrinsicalgorithm.com/IAonAI/tag/hfsm/

    Mexican Food Analogy

    The outside is a content delivery mechanism

  • 3/28/15

    2

    Bunch of rules Simply adding rules here or there around our code

    that change the direcBon of things in a fairly haphazard manner

    Obviously, the problem with that is you can only get so much content before things become unstable

    Its a bit unwieldy as well Most importantly, every Bme you take a bite of your

    content, you never know when the enBre plaKorm is going to simply fall apart

    The most basic architecture

    Adding a liLle bit of structure to a bunch of otherwise disjointed rules

    maps over somewhat to the most basic of AI architectures

  • 3/28/15

    3

    The nite state machine (FSM) The most basic part of a FSM is a state:

    an AI agent is doing or being something at a given point in Bme

    It is said to be in a state TheoreBcally, an agent can only be in one state at a Bme (although other implementaBons exist)

    UnawareInvestigate

    CombatSearch

    The nite state machine (FSM) This organizes the agent behavior beLer Because everything the agent needs to know about what it is doing is contained in the code for the state that it is in The animaBons it needs to play to act out a certain state, for example, are listed in the body of that state.

  • 3/28/15

    4

    An example The transiBon logic in any given state may be as simple or as

    complex as needed For example, it may simply involve a countdown Bmer that

    says to switch to a new state aVer a designated amount of Bme It may be a simple random chance that a new state should be

    entered For example, State A might say that, every Bme we check, there

    is a 10% chance of transiBoning to State B We could even elect to make the new state that we will

    transiBon to a result of a random selecBon as wellsay a 1/3 chance of State B and a 2/3 chance of State C.

    Another one More commonly, state machines employ elaborate trigger

    mechanisms that involve the game logic and situaBon For instance our guard state may have the logic, if [the player

    enters the room] and [is holding the Taco of Power] and [I have the Salsa of SmiBng], then aLack the player at which point my state changes from guard to a>ack. Note the three individual criteria in the statement

    We could certainly have a dierent statement that says, if [the player enters the room] and [is holding the Taco of Power] and [I DO NOT have the Salsa of SmiBng], then ee Obviously, the result of this is that I would transiBon from guard to

    ee instead

  • 3/28/15

    5

    Problems First, as the number of states increases, the number of potenBal transiBons increases as well

    at an alarming rate!

    Workload for each new state To have that state accessible, go and

    touch every single other state that could potenBally transiBon to it

    To add a State E, we would have to edit A-D to add the transiBons to E

    EdiBng a states logic invokes the same problem

    You have to remember what other states may be involved and revisit each one

  • 3/28/15

    6

    Workload AddiBonally, any logic that

    would be involved in that transiBon must also be interworked into the other state-specic logic that may already be there

    Suers from some of the same fragility of the ad hoc bunch of rules we menBoned earlier

    The Behavior Tree It is useful to point out the dierences

    between an ac7on and a decision In the FSM, our agents were in one state at a Bme they were doing something at any given moment

    even if that something was doing nothing Inside each state was decision logic that told them if they should change

    to something else and, in fact, what they should change to That logic oVen has very li>le to do with the state contained in and more

    to do with what is going on outside the state or even the agent itself If I hear a gunshot, it really doesnt maLer what Im doing at the BmeIm going to

    inch, duck for cover, wet myself, or any number of other appropriate responses. Therefore, why would I need to have the decision logic for React to Gunshot in each

    and every other state I could have been in at the Bme?

  • 3/28/15

    7

    The Behavior Tree Separates the states from the decision logic

    The Behavior Tree States and decision logic sBll exist in the

    AI code but they are not arranged so that the

    decision logic is in the actual state code Instead, the decision logic is removed to a

    stand-alone architecture This allows it to run by itselfeither

    conBnuously or as neededwhere it selects what state the agent should be in

    All the state code is responsible for is doing things that are specic to that state such as animaBng, changing values in the world, etc.

  • 3/28/15

    8

    The Behavior Tree

    All the decision logic is in a single place!!!

    Hierarchical Finite State Machine

    some states contain other related states making the organizaBon more manageable

  • 3/28/15

    9

    Hierarchical Finite State Machine There are mulBple levels of states Higher-level states will only be concerned

    with transiBoning to other states on the same level

    On the other hand, lower-level states inside the parent state can only transiBon to each other

    This Bered separaBon of responsibility helps to provide a li>le structural organiza7on to a at FSM and helps to keep some of the complexity under control

    Planner Like a behavior tree, the reasoning architecture behind a

    planner is separate from the code that does stu While the end result of a planner is a state (just like the FSM

    and behavior tree), how it gets to that state is signicantly dierent

    A planner compares its situaBonthe state of the world at the momentand compares it to a collecBon of individual atomic acBons that it could do

    It then assembles one or more of these tasks into a sequence (the plan) so that its current goal is met

  • 3/28/15

    10

    Planner

    A planner actually works backwards from its goal

    Planner For example, if the goal is kill player, a planner might

    discover that one method of saBsfying that goal is to shoot player. Of course, this requires having a gun. If the agent doesnt have a gun, it would have to pick one up. If one is not nearby, it would have to move to one it knows exists. If it doesnt know where one is, it may have to search for one. The result of searching backwards is a plan that can be executed

    forwards. Of course, if another method of saBsfying the kill player

    goal is to throw a Taco of Power at it, and the agent already has one in hand, it would likely elect to take the shorter plan and just hurl said taco.

  • 3/28/15

    11

    Dierences The planner diverges from the FSM and BT in that

    it isnt specically hand-authored Therein lies the dierence in plannersthey actually solve situaBons based on what is available to do and how those available acBons can be chained together

    One of the benets of this sort of structure is that it can oVen come up with soluBons to novel situaBons that the designer or programmer didnt necessarily account for and handle directly in code

    Advantages and Disadvantages From an implementaBon standpoint, a major plus of the planner is that a

    new acBon can be dropped into the game and the planner architecture will know how to use it This speeds up development Bme markedly All the author says is, here are the potenBal things you could do go forth and do

    things

    Of course, a drawback of this is that authorial control is diminished. In a FSM or BT, creaBve, outside the box soluBons were the excepBon from the

    predictable, hand-authored systems In a planner, the scripted, predictable moments are the excepBon; you must

    specically override or trick the planning system to say, no I really want you to do this exact thing at this moment

  • 3/28/15

    12

    Example A more recent avor of planner is the hierarchical task network (or HTN) planner such as was used to great eect in Guerillas Killzone 2

    hLp://aigamedev.com/open/coverage/htn-planning-discussion/

    uBlity-based method Instead of assembling a plan like

    the planner, however, the uBlity-based system simply selects the single next acBon

    All the ingredients are in the mix and available at all Bmes.

    However, you simply select what it is that would like to poke at and execute.

    You can select it based on what you have a taste for or what is most accessible at the moment.

  • 3/28/15

    13

    uBlity-based method The progression of AI architectures

    throughout The Sims franchise is well documented

    Each potenBal acBon in the game is scored based on a combinaBon of an agents current needs and the ability of that acBon or item to saBsfy that need

    The agent then uses an approach common in uBlity-based methods and constructs a weighted sum of the consideraBons to determine which acBon is the best at that moment

    The acBon with the highest score wins

    uBlity-based method While uBlity-based systems can be used in many types of

    games, they are more appropriate in situaBons where there are a large number of potenBally compeBng acBons the AI can takeoVen with no obvious right answer

    In those Bmes, the mathemaBcal approach that uBlity-based systems employ is necessary to ferret out what the most reasonable acBon to take is

    Aside from The Sims, other common areas where uBlity-based systems are appropriate are in RPGs, RTS, and simulaBons.

  • 3/28/15

    14

    ImplementaBon Like behavior trees and planners, the uBlity-based AI code is a reasoner Once an acBon is decided up, the agent sBll must transiBon to a state The uBlity system simply is selecBng what state to go to next In the same way, then, just like those other systems, the reasoning code is

    all in a single place This makes building, ediBng, tuning and tweaking the system much more

    compartmentalized Also, like a planner, adding acBons to the system is fairly straight forward By simply adding the acBon with the appropriate weights, the AI will

    automaBcally take it into account and being using it in relevant situaBons This is one of the reasons that games such as The Sims were as expandable

    as they werethe agents simply included any new object into their decision system without any changes to the underlying code.

    Drawback There isnt always a good way to intuit what will happen in a given situaBon

    In a behavior tree, for example, it is a relaBvely simple exercise to traverse the tree and nd the branches and nodes that would be acBve in a parBcular situaBon

    Because a uBlity system is inherently more fuzzy than binary, determining how the acBons stack up is oVen more opaque

    Thats not to say that a uBlity-based AI is not controllable or congurable In fact, uBlity systems oer a deep level of control The dierence is that rather than telling the system exactly what to do in a

    situaBon, the system is providing suggesBons as to what might be a good idea

    In that respect, a uBlity system shares some of the adaptable aspects of plannersthe AI simply looks at its available opBons and then decides what is most appropriate.

  • 3/28/15

    15

    Neural Network (NN) This is the caveat emptor of the NN-based AI soluBon As a type of learning AI, neural nets need to be trained with

    test or live performance data At some point you have to wrap up the training and say, This

    is what I have If a designer wanders in, looks over your shoulder and says,

    It looks preLy cool, but in [this situaBon] I would like it to do [this acBon] a liLle a liLle more oVen, theres really nothing you can do to change it

    About all you can do is try to retrain the NN and hope for the best

    Neural Network (NN) Lack of designer control aVer the

    fact Unfortunately, this tends to

    disqualify NNs and other machine-learning soluBons from consideraBon in the game AI environment where that level of control is not only valuable but oVen a requirement

  • 3/28/15

    16

    Wrap up This has by no means been an exhausBve treatment of AI architectures

    The purpose was simply to expose you to the opBons that are out there and why you may or may not want to select each for the parBcular tastes and needs of your project

    To sum up, though, lets go through the opBons once again

    Wrap up

  • 3/28/15

    17

    Conclusions there is no one size ts all solu7on to AI

    architectures You also dont have to limit yourself to a single

    architecture in a game Depending on your needs, your team, and your prior

    experience, any of the techniques may be The Right Way for you to organize your AI

    As with any technical decision, the secret is to research what you can, even try a few things out, and decide what you like

    Homework (HFSM) Michael Booth. 2009. "The AI Systems of LeV 4 Dead." ArBcial Intelligence and InteracBve Digital Entertainment Conference (Stanford University).

    (On Moodle)

  • 3/28/15

    18

    Thanks!