Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Techniques for Avoiding Artificial Stupidity!

Discussion in 'Game Design' started by DanSuperGP, Jan 13, 2015.

  1. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I'm starting this thread in the hopes to get some discussion brewing about how to design AI NPC characters to avoid what is often called "artificial stupidity".

    A good example of what is meant by artificial stupidity is summed up in this quote by @Tomnnn from another thread.

     
    Tomnnn likes this.
  2. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    That's just tracking things. Instead of the NPCs, meals and utensils being simple props the NPCs would be active in the scene. Meaning they are entities in the game world not just presentation only. As active entities they'd have a state. It would have been IndoorMeal perhaps. This state would require them to be seated at a table with food and such in front of them.

    It could have been dealt with different ways of course. Any spell or other force capable of disrupting their meal may have transitioned their state to ProtectingMeal (or more generically ProtectingSmallObjectInFrontOfMe which combined with knowing they are currently sitting in front of a table) would cause them to lean over and cover their meals and perhaps yell out "Hey do you mind?", "Trying to eat here!".

    Or just make it so the meals and utensils themselves were also "nonexisting" props in this case. This would be the cheap way out. This stuff can be as detailed as a person bothers to make it. It is all in the tracking of details: current state, state transition events/factors, non-state-transition output. When the spell was cast any object (including the NPC) could be notified the player caused a disruptive force. The NPCs receive the notice and perhaps 2 out of 5 randomly choose to shield their meal. The meals themselves receive the notice and 3 of them being unshielded slide across the table crashing to the floor. And so forth.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Yeah, that's the way it always is with these questions — for any particular example, it's easy enough to see how the standard state-machine approaches could be extended to cover them. After all, FSMs are Turing-complete; they can do anything that's computable, in theory.

    In practice, though, the problem is the gross proliferation of states required to deal with every possible eventuality (and all the developer time needed to create and maintain all those states). It's really hard to think of everything, and even harder to code up responses for everything you can think of.

    To deal with that, you need some level of more general sensors and behaviors. Sensors should include high-level concepts like "unexpected event" and "aggression", and some serious time would have to be put into these. But, for example, any animation could be tagged with objects that are expected to be there, and if those objects are suddenly not there, it could fire the unexpected-event sensor. Similarly, any attack (including fus-ro-dah) aimed in a character's direction could trigger the aggression sensor.

    Then, your state machine can respond to these very general sensors. While in the eating state, there should be a bail-out for unexpected event that makes them stop eating and look up with expressions of surprise. An aggression event should jump to the "hey, what's the big idea?!?" type response. Either of these would stop the eating, which is a big step up.

    Hierarchical state machines (HFSMs) can help prune the work of this sort of thing.

    It still only gets you so far, though, IMHO. At some point the industry is going to move away from those entirely, and switch to something like goal-oriented planners. These provide some actual intelligence, rather than mere scripted behaviors, and is really the only way to deal with unexpected events in a rich environment.
     
    theANMATOR2b likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    For the sake of discussion, let me be heretical and suggest a different design approach: make a less rich environment. If the player can't put buckets on vendors' heads, the vendors won't look stupid (at least in this way). In contrast to open world games, more-rigid designs such as most platformers focus the player on the actions they're intended to take, rather than encouraging them to experiment with how much they can deviate from those actions.

    Getting back to open world games, contextual sensors are where the advances need to focus. For action decision, you could get fine behavior out of a simple FSM for Tomnnn's example. If the player does something "unacceptable," just change to a simple state that reacts to unacceptable behavior. The hard part, it seems to me, is sensing when something is unacceptable, not planning how to handle it after you've sensed it.
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Sensing something that is not acceptable is difficult. Sensing something that is acceptable is much easier.

    So the NPC goes out with a bunch of sensors that are polled on a regular basis. Something like "Do I still have the items I need for my current state". Eating state requires food. Shop keeping state requires range of sight. And so forth. This approach does require some computational overhead, but may be simpler then an event based system. Combine this with the normal interrupt events. "Noise above certain level", "Take damage" and you should have something viable.
     
  6. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Yes, I think that's exactly the problem. For humans, sensing the things that are not acceptable is natural because we understand context.

    "What is the deer doing inside the tavern?"

    While Goal Oriented Action Planners are going to give us more dynamic action selection, they're not going to teach our characters about context.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Nueral nets? Surprisingly light on computational power for pattern recognition. But no one has built an efficient way to hand craft a net. They tend to be black boxes, which makes many programmers avoid them.
     
  8. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I can't think of a single commercial game that actually uses them. Even if the programmer likes the idea, the designers are going to hate you because they can't twiddle the knobs.

    I think it's a good observation that it's easier to enumerate what's acceptable in a context than to try to enumerate everything that's unacceptable.

    Then you can markup things with contexts like a list of tags... for instance, if a deer has a "wilderness" context and it's inside a "tavern" context... you can have a response like "what they hell is that thing doing in here"
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I played with nets for a while. The lack of ability to tune, or even understand, what is happening inside them is a pain. Current training techniques are cumbersome too. Building a neural net is relatively simple. Building the superstructure to train them is a big job. The training is also highly related to the context and becomes invalid as soon as you change anything. No one is going to let you sit on a fully developed game for six months while you train an AI.

    I like the idea of context tags.
     
    DanSuperGP likes this.
  10. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Ah, I remember that post. I also more clearly remember that day now. It was the companions! I was just getting back from removing a wolf from someone's house (for a third time) and accidentally hit the button bound to the shout. So the character let out a little 'Fus!' which honestly sounds more like "fulsche!", and it was down the center of the table so the characters weren't affected but the silverware & food was.

    Because of @hippocoder 's response to that, I didn't have the nerve at the time to admit to testing this at the stormcloak's estate after installing this mod. Was I really so immature only 2-3 years ago? :p
     
  11. This_Game_Lags

    This_Game_Lags

    Joined:
    Jun 7, 2014
    Posts:
    25
    Unexpected Events to be handled can be simple. As long as you just have a "cover all" technique.

    If I was an NPC and you just threw my food all over the place with your voice. I would instantly go to being defensive because of the aggressive move taken. Then my disposition would change depending on my personality. (Maybe I thought it was hilarious.) Then I would immediately move to any state that was effectively after that.

    You don't need to handle every situation. You just need to pretend you have control over all situations with quick reactions that are relevant to the NPC and not just the situation.

    A user just needs to feel that the NPC has awareness.

    In the case of the bucket covering the NPC's eyes. Well, that has to do with a lack of awareness of your AI/NPC.

    You NPC is completely unaware that you have placed a bucket on his head. Well, maybe he is disciplined and has entranced himself or maybe your NPC thinks it's a hilarious joke.

    This could have been easily dealt with from programming forethought about NPC field of vision blocking. As long as the NPC can communicate that his vision is blocked then it becomes a toy. Now you can have NPC's react differently to having their vision blocked. Vision Blocked could just be the state.

    All acts can be summed up into a few categories. It's making a player believe that you are aware of his every action that brings about the immersion.

    For Skyrim: How they coded the sight allows you to figure out how to handle each situation.

    Now, for any game. The more control you give to the User the more awareness you have to give to the AI. The less strict your AI is to situations, the more situations it can handle with the same code.


    Immersion breaks when a player feels like the invisible hand of the game master is no longer in control. Even a simple "Hey, don't do that!" can save immersion.. Unless you keep doing it and that's the only response you get.
     
    DanSuperGP likes this.
  12. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    This has totally taken me down a side jag about wanting a shout to cause clothes to disintegrate in comedic anime fashion.
    Couldn't be any worse than a fart joke.



    Skyrim could probably work around a lot of these issues with a more robust understanding of ownership and placement. In theory, NPC's could actually move items around, to the effect of setting tables and otherwise being organized, but it would require far most simulation than the ES games have ever had. It's an ideal solution that comes at far too much cost.

    It would be totally doable for dwarf fortress, but not so much for Skyrim.


    At the end of the day, it's neither practical nor even possible to account for all cases of human stupidity, lest we forget why mcdonald's coffee has to have a warning that it might be hot. People can get pretty retarded, and in the process of thinking you can outwit a retarded person, chances are you'll end up becoming one.
     
  13. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    I agree with you completely. But ultimately you need certain states / behaviors the NPCs can engage in. You could define eating, traveling and so forth. That is fine. I wouldn't set out to explicitly rig up an FSM covering every possible thing although I don't think it would be that difficult to do it and handle more scenarios than many RPGs handle. But since I have not done that yet that is up in the air.

    Anyway, what I am getting at (and probably did a poor job of) is when is first the NPCs need to be fully "there" in the game. In the example it seems to me they are basically just props. So the first step is to get them actually into the world as active entities.

    Then when I say managing states, transitions, and so forth something like ProtectingMeal or ProtectingSmallObjectInFrontMe is an abstract term. Basically I was trying to show to generalize this as much as possible. But the bottom line is the entity should "know" they "own" something even if it is not actually on their person. And this could be tracked through descriptors.

    What can they do? Let's say they can walk, run, duck, jump, melee combat, talk, take things, give things, receive visual, audio and kinesthetic events. By simply classifying the "things" with descriptors such as size, weight, edible and so forth we have moved a long way toward the end goal.

    The casting of the spell would create a visual and audio event and the impact of the spell hitting the table (as well as the NPCs) would create a kinesthetic event. Meaning the NPC would "feel" the force. They received an audio event from you, followed by a visual event (say a flash or light or whatever) and shortly after they received a kinesthetic event. This chain of information flowing to them can be processed to determine sound from this way, perhaps they look up from their meal. Flash from position coinciding with the player's position. They know you just did something. They feel "something". They see something they own (this can be specific "their meal") knocked away. They hear something they own ("their meal") crash to the floor.

    What I am getting at is this stuff can be broken down and classified. But yes ultimately we need to handle the information and states of the NPC. So they have all of this information what do they do with it? That stuff we need to program in. I would make it as generic as possible. Not literally try to explicitly program in each and every interaction possible in the game world. That would be insane. lol
     
    JoeStrout and This_Game_Lags like this.
  14. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    What about a general "One of these things is not like the other, one of these things does not belong" protocol for handling things like a deer wandering around inside a guild. I also recall having a dragon attack me while wandering around the courtyard type area at the wizard college, and for some reason after I killed it, the corpse persisted throughout the rest of that save file. It'd be great if Skyrim had implemented a check for dragons to not come after you in "outside" areas that they would get stuck in forever.

    UE4's native ai isn't that great either. Finally had a chance to play with it, and it sends a failure flag when it rounds a corner because it steps off the navmesh for a split second!
     
  15. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I had that same thing happen. I was pissed off to have it attack me there in the first place.