A Generic Approach to NPC A.I.

by Maniac on August 5, 2010

Ok, welcome back!

Today ill go into a bit more detail on how generic approaches help create reasonable NPCs, how this can be achieved and what other merits it bears.

Like i stated in the introduction post, most actions are generic. Actually, how intelligent or dumb someone in real life seems if most of the time determined how much knowledge someone got about the environment and conditions and needs of whatever hes tasked to do or whatever situation he might have to face. This might not look like a big topic, but… Imagine you’re in the movies and someone in the movie does something you could have done better or would just have done in another way. Its a quite common situation and there are folks out there that still scream “Don’t open THAT door!” or “Don’t trust him! He ate your dog!”. This shows us two things: First, some behavior doesn’t have to be the best possible (re)action to be recognized as reasonable and believable and second, its easy to comment on something someone else does. Its a bit like looking at a cathedral. You don’t have to be very smart to recognize one and tell it from a chapel. So, we are all experts in telling if something is a cathedral or not. But how many of us could build a cathedral? Do You know what it takes to make a building even look like a cathedral? If we take this literally and move it into a game, say, we want a model of a cathedral in the game. Easiest thing to do is get enough pictures from different angles of a cathedral and just copy it. Even then, though, you need some basic sense of proportion and stuff… but still, its quite easy. Building a model that just looks like a cathedral but has no RL-Counterpart is more difficult, because you got to get a sense of what makes a cathedral look like a cathedral. The worst thing of all is of course building a real cathedral, because you got to think about a hell lot of things. Statics, material, form, geometry, aesthetics, etc… much more than most of us will ever be able to. Whats that got to with A.I.?

A.I. for the most part means making agents behave in a certain way. In our case, it should resemble human and animal behavior the best it can. So, we can take a look at the behavior of humans and animals and… oh my gosh… there the trouble starts. Of course we understand most human behaviors, otherwise wed be at war with each and everyone all the time because we got no freakin’ idea what they were up to. Still, whats going on inside them, what is leading them to do this or that, decide in this or that way… hell.. that’s why psychology still is science, and a science with more guessing than knowing for sure (i was a psychology student, so this is insider ;-). So, we could just copy. That’s in fact was most game AIs do nowadays, they copy behaviors. And it works quite well in small scope. A Soldier in a RTS game e.g. doesn’t have to have any feelings, preferences or sleeping habits. He doesn’t have to chose his weapons or whether he really wants to shoot someone or not. Hes guarding, not caring or attacking. he knows when he is attacked, but the way he acts and reacts is very poor. that’s ok, soldiers aren’t payed to think. a bit more thinking is one in FPS, when enemies at least have to apply some tactics and the like. but still… if you don’t see them, they are either not even spawned, are just standing there or are doing some cheap guarding. and that’s all ok for that kind of games. there’s no need for the trooper to smoke a cigarette now and then to keep him busy or calm him down (he might be paranoid). There is no change of shifts, he doesn’t have to eat, drink or go to the toilette. Also, if he gets in a fight, the communication (if any) with his team/squad mates is either only show or doesn’t really include negotiating and misinterpretation. 
All these behaviors are strict and they have a narrow set of events they can react to, and they’ll wait forever for you to reach the end of the level. they never wonder why you take so long and even if you killed hundreds of them in the first half of the game, they wont try to overwhelm you with all they got in the second half. And if they did and you still kicked their ass, the last levels would be quite boring. so, AI is still bound to the environment it acts in. now what if you designed an environment that’s open to nearly everything? you really want to design a incredibly big load of different agents that take care of each and every possible task? No, you don’t want to. believe me. just believe me. Let me rant about one more thing, then ill get to the point. Promise.



What I mean is the PoB (Pile of Bodies), which is something you encounter in nearly every game. It’s a situation you create to have more than one enemy come along a certain path to face their death, like an impregnable defense line in a canyon (RTS) or a decent corner/room (FPS, RPG) and all the following enemies just step in the same way, get crushed and the ones behind them don’t seem to draw ANY conclusions from the growing pile of bodies. If any human would behave like that, I’d say we should be glad he got removed from the gene pool.

Ok, now, how to make the agents flexible, believable, reasonable and avoid PoBs? 
Make them make their own decisions!

The agents behavior will not strictly be defined to do this and that, but have a certain list of static goals for storytelling or other purpose like traders and of course staying alive, a list of possible goals that get triggered by events that don’t have to be thought of at all times, like firefights if the agent is a simple peasant working on the fields, and a set of things he can do, like opening doors, throwing stuff, using certain objects. All things to do, called Commands, have preconditions and some encoded consequences. these consequences are used by the behavior assembler to build and expand the behavior tree (a tree structure that has different types of nodes that determine which “path” to an actual execution command to take [see here if you want to know more]) of the agent. so, agents are just given these goals and the commands and then have to find a way to achieve this goals. Doesn’t sound all that new, innovative or mind blowing? Then I didn’t explain it complicated enough. Bugger. Anyway, the great thing about this is, that the situation and the surroundings, the environment, the perception of the agent, the available items and all that melt together to some big random factor. Of course there will be a mess of random factors in the agents themselves. But the outside factors will be just as critical as the inside factors. This means, two different agents with the same equipment in the same situation may act only slightly different or may even act completely different, but not just because we told them how to react. Also, they most likely will do things you didn’t expect, so it will be a lot more work to break this A.I. (if you succeed at all). Strong emphasis will be put in the avoidance of PoBs. A dead body will be perceived and tell the A.I. that there’s a high chance of dying like a fool if he takes the same way. Of course, not all agents will be set to be very intelligent, so the one or other will still step into the obvious setup and die like he deserves it. But you wont be able to kill the whole bunch like that. Possible agent reactions to a PoB could also be a retreat, throwing grenades, finding an alternate route or, if you are in a dead end, blocking the exit and leaving you there to starve to death. Did any A.I. ever do this to you? I don’t think so, because most A.I.s are build to support the game in keeping the player busy. That’s why critters are always aggressive (at least to some degree), although in real life, most of the fauna is in fact quite peacefully if you don’t threaten them (ok, some feel threatened very easily) or, if its hungry, look like prey and there is not one species out there that’s just out for blood for the sake of killing (except humans – should make you think, heh?). So, behavior in Apokalypsos in general will be more towards every day life than combat. Especially when it comes to animals. They will thrive, roam, hunt, mate, sleep, find cover, find food, flock and enjoy themselves or struggle… whatever is possible in the corresponding situation. Needs of humans and animals alike will be also part of the static goals and they’ll include all sorts of activities that fit the type of NPC/critter. Herds of animals e.g. will roam from one source of food to another, predators will keep up with the herds and attacking them from time to time when they are hungry (as long as they are not defeated by the herding animals (STAAAAAMPEEEEDEE!!!)). Humans will serve their duties, smoke cigarettes if available, take breaks and in their spare time sleep, play cards with others, visit a bar, get some drink or even get drunk and pass out in the streets. These activities will not strictly be bound to certain times of the day, but to the conditions of certain actions and goals. A hobo might want to get drunk all the time, a hard working soldier might just want to this when his shift is over. Another soldier might just take a drink when doing his guard round, either because he luckily found a bottle of booze (though i wonder who would drop those… cant be the players.. can they?) or he’s a useless alcoholic anyway. 

So you see, the generic approach may just be what fills the world with some life that isn’t deterministic but evolving and interfering with itself, altering each other and all of that… 
buuut… that was hell of a lot of text and you might need a week to chew and not choke on it.

See you next week!

{ 0 comments… add one now }

Leave a Comment