Artificial intelligence in games (Dan's series of articles)

Back in 2011 Dan Vávra wrote a series of five articles about game AI that was published at Games.cz. It focuses mostly on FPS games. The English translation of the first article is brought to you thanks to @bebuce (translation) and @PhanTom_CZ (proofreading).


#Artificial intelligence in games #1: Forget about intelligence

Right at the beginning I have a disclaimer to make; even though I have experience with AI implementation and design, I am not a programmer myself. Moreover, this topic is highly involved and the series of these four articles is therefore no more than a very brief and very general introduction and I am bound to commit many inaccuracies. I want to ask those, who are AI professionals (there is not many of those in Czech Republic and I probably know most of them) to be patient, because the goal is just to familiarize our readers with what AI is and what is it used for in games.

Gaming AI is not an actual intelligence per se. A true intelligence should be able to learn, to react to external input and make autonomous decisions or at least try to. The artificial “intelligence” in games cannot do this and will not be able to for a long time yet. The goal of AI in games is to be an opponent or a partner to the player and to appear as a living being that behaves appropriately in the given situation as much as possible. The number of situations in games is, fortunately for the programmers and designers, very limited and usually consists primarily of fights with the player in a way that seems the most authentic.

Computer-controlled character must therefore be able to navigate around the game environment, attack the player, defend from his attacks, exploit the game environment to its advantage and eventually to cooperate with other computer controlled characters. If we wanted this from a robot moving in the real world, this would be a task worthy of a supercomputer, because just the orientation in such an environment is nothing funny.

Luckily, in the game the designers can give hints and guide the AI in various ways. As a result the AI doesn’t work as an “inteligence”, but technically as a primitive automaton which makes decisions based on simple rules: You see the player? Shoot; Got hit? Say “Auch” and take cover; Run out of ammo? It’s over there, go and get it.

Bulletstorm (2010)

Navigation

The most basic thing we expect from an AI is that it can move. To simply throw it into a 3D level mesh and let it figure it out on its own would require that supercomputer I mentioned and an actual intelligence which can analyze, remember and learn, which is not really possible. Therefore essentially every game contains some form of navigation data which the AI relies on if it needs to move from A to B. Usually it is some form of a navigation mesh or linked checkpoints that tell the ingame character where it can walk.

In the past designers were drawing checkpoints by hand, nowadays they usually get computed automatically. This mesh replaces the need for a memory and ability to recognize the surroundings. The only concern of the NPC is to calculate the shortest path to its destination using these points. The advances of physics inside games brought another problem: what to do when the player blocks the NPC’s path with a movable object? The AI needs to reroute, which is not difficult by itself. The problem appears when the player blocks all the paths and the goal becomes unreachable.

Take an example of a hypothetical situation in an open world game like Fallout. The player is to follow an NPC into a building where a plot twist is about to happen. What happens if the player parked a truck right in front of the building door? Shit happens. Asking the AI to get in and move it somewhere else is a task worthy of an actual intelligence. The designers have to start cheating. They can place some indestructible barriers so that the vehicle cannot get there, but that breaks the impression of an amazing physics, if the rest of the game allows bringing down full grown oaks. They can make the car disappear—but that might make the player mad when he comes back for it later—or teleport it to another place. All these situations demand a large amount of foresight from the designers and considering the number of possible places like this, it’s essentially impossible to prevent all such situations. The bigger the world is and the more possibilities are there, the more complicated it gets.

Fallout 3 (2008)

Another variant is when the AI is following the player. A telling example is the Elder Scrolls series. Veterans may remember the utter desperation in Morrowind, where it often happened that the character which should accompany you simply got lost and the quest where the character was included was then impossible to finish. This could happen for a variety of reasons: in a difficult terrain the player would climb to a place with no navigation mesh and the NPC could not follow, getting stuck somewhere. If the player did not notice, that was the end. Sometimes the player was attacked and decided to flee, but the NPC started fighting and lost the player.

In Fallout 3 the designers decided to simply cheat. If the NPC and the player get separated for whatever reason, the NPC is teleported somewhere out of sight in his vicinity like if nothing happened. It sometimes feels funny when for example you leave a building through the only single exit and the NPC who was 100 meters behind is suddenly waiting for you outside, though it prevents much worse situations form happening.

Both these cases show why Game designers are not eager to make complex missions with too much physics infolved or where the player has to cooperate with a large amount of story driving NPCs. If they really want to have that in the game, they usually solve it by scripting.

Killzone 2 (2009

Smoke and mirrors

With the exception of games based purely on AI (strategy games like Sims and Spore), scripting is a larger part of game design than the AI. The developers have to keep telling the NPCs what they are supposed to be doing in every moment of gameplay. Some essential activities can be coded directly into the AI (NPCs walking around the town in Assassin’s Creed), the more difficult ones and the single-time ones have to be scripted by the designer.

The player is to walk somewhere, the NPC talks to him and then leads him elsewhere? The designer solves this by hardcoding step by step what it should do: when player presses the button, play sentence and animation XY, walk to point A, open the door, walk to point B and play animation YZ. If the player is more than 10 m away, wait for him. If he does not get closer in X seconds, shout on him to move his butt.

To ensure this will not get screwed, the designer must clear the path for the AI, remove obstacles and enemies and stop the player from messing something, or at least make sure the NPC will not die, say by making it immortal. These are the situations in Crysis 2 or Bulletstorm when you are allowed to walk, but only slow and you cannot shoot, so you cannot get in a way or take out somebody important.

The most pronounced example in Crysis 2 is when you walk with Gould to the Cell laboratory to sit in the diagnostic chair and at the moment when Gould gets through the glass door, it smashes close right in front of your face so you cannot get in and shoot the staff inside before Gould talks to them.

Crysis 2 (2011)

The puppet show style design goes to the extreme in current FPS games where the script plays the main part and the AI plays the second fiddle. The player moves through a corridor and the behaviour of everything around is strictly predetermined. The puppet show only stops for a moment when the player falls behind. Whenever the player gets to a predetermined spot, it triggers a new series of animations. The only interactive element driven by an AI is that the player needs to shoot a few of the puppets before they shoot him or succeed in acting out a game over script (like setting off a bomb)

The AI is restricted to the bare minimum in these cases, the enemies are simply waiting for the trigger and the moment when it goes off they jump out and start shooting. In the better case they can move around in some restricted space and take cover. The situation is usually set up so that the player can’t do anything to spoil the show: to retreat or to run through the enemy lines without killing them. The show requires that player must kill everyone before the next act begins.

An honorable exception is the Modern Warfare 2, where Infinity Ward dared to occasionally allow players to venture into more open nonlinear areas and then let the artificial intelligence to move around rather freely and naturally during the firefight. Only when the player cleared the arena, the puppet show script went running again.

Modern Warfare 2 (2009)

You got a lot of material to think about AI in current games for today. Next week in the second part we will explore the senses our AIs have and how are they used in combat and spatial navigation, and the idiocies that NPCs sometimes commit.

17 Likes
1 Like

Wow, that’s pretty awesome guys. Thank you very much @bebuce and @PhanTom_CZ for giving your own time to do this. I certainly would not have read this otherwise. If you decide to do the other articles, just know that it is very appreciated. Thanks again guys. :slight_smile:

3 Likes

Do I understand correctly that a script is a database of programmed instructions (do this if this happens)?
Could this database be extended by a player through playful activities, ie, the “database” be able to infer and evaluate?

Verstehe ich das richtig, dass ein Skript eine Datenbank mit programmierten Befehlen ist (tue das wenn dies eintritt)?
Könnte diese Datenbank von einem Spieler durch spielerische Handlungen erweitert werden, also, kann die “Datenbank” in die Lage versetzt werden zu schlußfolgern und bewerten?

that’s not how scripts work. it cannot change once it is compiled. what happens is internal instructions will change and become “modified” based on player action. but all instructions have to already exist in order for them to interact with eachother, so there is no need for the script itself to change, if you simply take into account all possible meaningful player action and create instruction sets based upon that.

Scripts in a computer game are more like scripts for a movie. If the script describes a cut scene, it is EXACTLY like a movie script. It says where each actor should stand, what should be said and when precisely, how the camera moves and so on.

There are three parts to every script. Sequence, selection and iteration [1].

Sequence means a series of actions, one after another. If you are scripting a cut-scene, this is all you need.

Selection means that you can say a part of a script will happen only if a condition is fulfilled. For example: IF the player parked a truck in front of the gate THEN teleport truck away ELSE just carry on.

Iteration means that a part of the script can be executed multiple times.

This, together with a list of actions that the game developers allow you to call is essentially ALL there is to scripting.

Example of a script. From ArmA:

;=== 22:11:02
_camera camPrepareTarget [684.73,98559.95,-27662.98]
_camera camPreparePos [2545.07,2486.85,9.91]
_camera camPrepareFOV 0.700
_camera camCommitPrepared 0
@camCommitted _camera

The line starting with a semicolon is a comment so the scripter remembers what the current timecode is. The next four lines set the position of the camera, the direction it is facing and so on. The last line tell the camera it should move to that position. The at sign means that the command on the next line should execute only after the current one “completely” ended, that is, the camera has moved into the position.

removeAllWeapons player;
player addWeapon "Binocular";
player addWeapon "NVGoggles";
player addWeapon "ItemGPS";
player addWeapon "ItemMap";
player addWeapon "ItemCompass";

player addMagazine ["DemoCharge_Remote_Mag", 10];

The code that preceded it had to store a reference to the player character into the variable named player. Then this code would set the players equipment.

for "_i" from 1 to 12 do {this addmagazine "smokeshell"};

This would run the command in braces 12 times, resulting in adding 12 smoke shells into the inventory of whatever is referenced by the variable this.

You can see a lot of examples of real world scripts for example at http://www.kylania.com/ex/?page_id=72

[1] https://en.wikipedia.org/wiki/Structured_programming#Control_structures or possibly http://condor.depaul.edu/sjost/it236/documents/structured.htm

1 Like

Sorry for the second part disappearing and reappearing now… some scheduling trouble and miscommunication happened. :slight_smile:
I also apologize for it taking so long. I have a lot on my hands currently, but I will try to have the following parts ready ASAP. There are still two more to go.
In the meantime, enjoy the read!

Translation: @bebuce
Proofreading: @PhanTom_CZ
with special thanks to @masozravapalma for more corrections

Artificial intelligence in games # 2: With AI it’s hell, but so it’s without it

The quality of AI usually only shows in its full glory during combat. It’s the “senses” of
the artificial intelligence, i.e. its sight and hearing, that plays a pivotal role in making the fight seem the most natural. The computer, of course, always knows where the player is. The goal is to make the fighters behave like real beings, so it has to be computed whether the enemy can see, or hear the player. This is done by casting an invisible ray from his head in the direction of the player many times per second. If this line strikes an obstacle, the enemy does not see the player, if it doesn’t, the enemy can see the him.

Naturally, it’s a bit more complicated than that. What if only a part of the player’s arm is sticking out from behind the corner? The ray is cast towards the torso first and if it fails, another try goes for the head and limbs. Still, it might happen that a part of the player is visible but because the “vision” isn’t testing that specific part, the enemy won’t see the player. Computing these rays is essentially a collision detection, which is, together with graphics rendering, one of the most performance demanding tasks. This of course means that the more enemies are present, the more vision calculations there are and the slower the game runs.

Then some further parameters get in effect, for example the lighting. Even if the enemy sees the player, the player may be hidden in the dark, so he’s not really visible. This is not that difficult, because the computer knows how much light is hitting the player character. One crazy situation is the player standing in shadows with a light source behind him, so his silhouette is actually clearly visible. The majority of games still cannot deal with this situation.

Vegetation and other fancy stuff is a chapter in itself. You might have experienced this in Flashpoint / Arma while lying in complete darkness in a three-feet tall grass a mile away from the enemy. You couldn’t see shit through the grass yourselves even with the NV goggles and suddenly you took a headshot. On another occasion you are lying in a bush with an enemy standing half a meter from you without noticing you. Deciding whether the AI should be able to see you in thick foliage or not is probably the hardest problem. The developers resort to various simplifications, which lead to the situations I described.


Well, this ArmA soldier won’t be crawling anywhere and the grass won’t help him

The same thing with sound. If the player is in the same area as the enemy, it’s rather easy. No need to compute the collisions, it’s enough to limit the distance at which the sound can be heard. It becomes way more difficult if the player is in a building with lots of rooms and, say fires a shot. The computation of sound spreading in such a space is nothing trivial. One needs to take collisions into account, but because the sound ricochets it’s important to simulate how it spreads through holes into other rooms and finally decide whether the AI should be able to determine the location of its source.

The developers usually conclude that the resulting behaviour is hard to notice for the players and put in only a simple detection. That means that the enemy can hear you through walls and ceilings, but because the games nowadays are often designed so that the enemies in different parts of the building don’t move and “patiently” wait for the player, it does not cause problems. It’s still a far cry from reality, though.

In most games, after the player enters a building and fires a shot, NPCs from one room will throw themselves at the player and as the player progresses through the building, more and more waves of enemies that “did not know” about the player until then do jump out. In reality, if somebody starts shooting in a building full of enemies, the whole garrison would quickly surround and neutralize him.


Thief: Deadly Shadows is a prime example of a game that builds upon the AI’s ability to follow and evaluate player’s noises and movement in the area

Combat!

Our AI is now able to move and sense the enemy on the battlefield. Now we must teach it to use all this in combat. We will start with the most frequent kind - a firefight. The tactics of a firefight is simple in essence: you must get to the most advantageous position relative to the enemy, preferably unnoticed, and then shoot him.

The last action is the simplest. If the developers want it so, the AI can hit you every time it fires. What we need is to randomize it. The probability of a hit decreases with the increasing distance, depending on whether it’s you or the shooter who’s moving, whether you’re in shadows or in light, what part of you is visible, if you’re standing or lying and so on. Stealthy approach and maneuvering is not a large problem either. Nowadays, most commercially available AIs can determine its own cover and move where the player can’t hit them.

A hard thing to decide is when to engage. What is the ideal distance to reveal yourself and attack the player? In reality, a soldier would base that decision on an incredible amount of details, many of which would be subjective. In a game, the designer has to solve this process in cooperation with the programmer and tell the AI straight what to do.


Ghost Recon: Advanced Warfighter also had some minor issues with NPC teammates

The ideal distance for shooting with each weapon must be specified; then how many shots should be fired before performing another action; as well as what should be done if the player gets too close. The goal is to make sure the firefight won’t look like a battle in Napoleonic wars: units standing against each other and firing a volley after volley until one side falls. There is a huge number of parameters to take into account and fine-tuning them is a real hell.

If you’ve played a game that has NPCs on the player’s side as well, you might’ve encountered a situation when the opposing NPCs got very close to each other, each firing like crazy, but unable to hit anything. That stems from the setting that gives the AI the same low probability of hitting at the close range as at the long range.

The whole thing looks funny, but sadly it has its reasons. If the developers increased the AI accuracy at close range, it would not affect just the NPC-vs-NPC fights, but the player-vs-NPC too. And most players wouldn’t appreciate it if closing to the enemy at less than 15 meters would mean an instant death.


The first F.E.A.R. does not have to remain only in our memories, go ahead and play
it to see one of the most crafty AIs in a shooter game

Exploiting the environment

Taking cover is a natural part of a fight and it’s reasonable to want this ability from our NPCs. The commercial AIs you can buy nowadays can tell the NPC if it’s visible from the player’s position, but that works best when there is a solid wall between them. What we want is to have the AI duck behind obstacles inside a room, peek from behind corners, take blind shots from its cover and look awesome while doing all that. No AI can manage that without the help of designers and programmers.

AI must be told where the cover is and what taking cover there looks like. As a result, levels are flooded with thousands of AI marks that define what can be done where. You can see it in one of the demonstration videos that Crytek made to showcase the AI in Crysis 2. New York Central Station, which is one of the levels, was literally flooded with various marks, not just for cover, but also for places where enemy monsters can jump from one floor to another. To summarize, if you want your NPCs to jump through windows, you must place a marker on every window that will tell them that it can be done there.

Game mechanics

You probably noticed already that if you kill an enemy and want to take some of its possessions, in the vast majority of games what you can pick up is very different from the equipment the enemy was using. All the same it might be hard for you to remember a moment when an NPC has ran out of ammo. When you want to loot a corpse of a soldier which had unlimited ammo when he was alive, you will see he has only a few rounds left or even nothing at all.

Players got used to that, even though it’s actually an irrational and illogical nonsense. Kill a giant with an ultimate axe wearing a terrifying armor and the corpse will have a torn shirt and a pocket knife. Why? Enemies have limitless ammo, because what should we do if they ran out of it? It’s fascinating that we work in an industry where developers successfully solve heaps and heaps of incredibly hard problems, yet only a few managed to solve the problem of what to do when NPCs run out of ammo.

And it’s not just the ammo. There are loads of situations in games when the AI is acting in a terrible and senseless way and not because of technical limitations, but because the designer was sloppy. Take a very common situation when the player opens fire at a place full of civilians. In very most games, they will all hit the ground, cover their face with their hands and hysterically scream “noo pleease!”, or at best run in circles and scream the same thing. We’ve gotten used to this, the civilians in games simply run in circles with hands up, screaming “noo pleease!” Would you do the same? It is really that hard to make them shout something else and not make them all look like hysteric old ladies?


State of Emergency is a piece of trash, but in its day it attracted attention thanks to its crowd scenes… in which the NPCs were behaving in a really stupid way

It may sound strange, but the inspiration for game designs is usually not the reality, but other, previous games. Of course, there are some things we want to avoid in order to make the game fun and some hard stuff must be simplified, but still, games often simplify too much.

It leads to absurdities that, strangely, everybody is OK with, even though people know very well that in reality things work in a completely different way. The developers and players of these games both accepted a set of absurd rules, which will seem ridiculous to our children, just like the acting performances in films from the early history of cinema now do to us.

In the third part of the Game AI series we’ll take a look at AI-driven character cooperation, discuss why AI cannot be fully utilized in games and how can an AI that is obviously faulty be actually the most realistic one.

4 Likes

ahhja … think I understand a little. A (pardon, amateur) question, Scripts various NPCs can - if there are overlaps, not affected NPCs trigger a command in the script (?) Quasi the selection of the script (part of) a NPC involved in an action with the player is recognized by an impartial NPC and dissolves in the script an action …?
I’m thinking of a kind of collective communication. Simple example: If I have a general question about his village imagine a farmer and he gives me a general answer, the next farmer would not give me the same general answer, but his personal information, or even a counter question (what you want to know exactly ?)

In the background, farmer (A) with farmer (B) would talk about the questioner and A would have given B his answer, B is informed.

1 Like

why would that happen? that would be like telepathy. the next farmer may or may not know what the other farmer has told you. if they were to communicate, there would be a limited amount they would relate about the player, so it would be only pertinent information significant to gameplay, story, etc. they wouldn’t “care” whether you asked a question already or not, and it wouldn’t be realistic either.

unless you mean farmer a physically traveled to farmer b’s location and told him about the player’s question about the town. again, not a realistic expectation, memory and script writing wise, but in relation to more important things, i think it’s possible. like if you helped farmer a with something, he will tell farmer b your good need and improve your standing within the community. farmer b’s dialog choices will then reflect your good deed. his dialog choices may change

2 Likes

On something went my thought, yes. However’m not sure if that has anything to do with a script or rather a “game mechanics / Database” in the background.
On the other hand, it should be a scripted action trigger this process - no?

The AI handles the more general, automated, robotic actions that are supposed to be done on some regular basis with no respect to whether the player is present, or watching. The scripted parts are created specifically for certain actions that are supposed to happen when the player is around, they are there to be watched and to enhance the “immersion”.

For the scenario that you described… I guess the AI would be covering the core part about the villagers gradually sharing a piece of information on “the traveler was asking…”, if the dialogue option gets triggered by you while talking to one of them. Depending on the AI it would either get distributed to all (or selected few) of them automatically (with a delay to simulate the time necessary for the gossip to spread), or it could possibly work the way you suggested - with each NPC having to physically meet the other to distribute the information further.
Dan Vávra mentioned that this is the way he wants to deal with the player’s reputation in KCD. News spreading through some AI-driven “gossip” mechanics. Sounds pretty neat…

But during such an NPC encounter, the information could still just transfer inside the game’s system without much real action in-game. That would be when the scripts come in.
If it was supposed for the gossip to actually happen in the game (to be possibly encountered and overheard by the player), that would mean including it in a scripted scene with some pre-set dialogue for the NPCs to happen in parallel.

2 Likes

ah, o.k., I see. Thank you! So it was mainly a matter for the AI. Had ever thought about it years ago, as it would be if the nature (weather, season, soil conditions and events (in) the game world) would act as a “drive” for actions / intentions of the NPC (depending on the job description in modified form) and then - would respond to player actions - filtered through a priority system. Then you could then here’s a “no time, come by later” or “Help me to do this or that” come. Probably in this case stands for each encounter with an NPC open a variety of options, but would also work very credible. Later, when diplomacy should play a greater role, it probably will not otherwise go without it seems static. Could also think that in a true sandbox the laws of nature must play an essential role, no matter, what age is playing in game. Unfortunately, the “forces of nature” from Raindrop to the bacterium must install the programmer … :neutral_face: :stuck_out_tongue_winking_eye:
Think before all developers so far (understandably) were afraid. On the other hand, it is a question to extent to which the simulation of the elements is necessary to achieve a credible result. Was there ever approaches in this direction?

Eventuell zur Erklärung - unter einer “Sandbox” verstehe ich einen großen Haufen (Form)-Sand in einem abgegrenzten Terrain. Einige Terrain-Editoren und minecraft kommen immerhin in die Nähe des Begriffes, die Spiele dann bewegen sich aber “auf” dem Sand, sind Projektionen auf eine Oberfläche. Ein wesentlicher Schritt war minecraft, wo immerhin “mit” Teilen des Sandes gespielt wird, wenn auch in sehr groben Raster. “Open-World” bedeutet nicht zwingend “Sandbox”, allerdings könnte eine wirklich durchdachte Sandbox diesen Open-World-Games ordnende Elemente zuweisen. Da würden dann nachts keine Vogelschwärme fliegen, es stände im Hochsommer nicht tagelang Wasser in Pfützen, ohne dass es regnet, Bauern würden nicht leere Felder bestellen, wenn gleichzeitig Früchte an Bäumen hängen und, und, und…

Perhaps explanation - under a “sandbox”, I mean a big pile (form) -sand within a defined territory. Some terrain editors and minecraft come at least in the vicinity of the term, but the games then move “on” the sand, are projected onto a surface. An important step was minecraft, where at least is played “with” parts of the sand, but in very rough grid. “Open-world” does not necessarily mean “sandbox”, but could assign this open-world games ordering elements a really well thought sandbox. Since no flocks of birds would then fly at night, it stands in the height of summer days in water puddles, without it rains, farmers would order nonempty fields when simultaneously hanging fruit on trees and, and, and …

varva actually talks quite lot about how such expanded artificial scripting cna be applied to shooter games. i once remember maybe over a decade back, a project from his former company featured a very good looking fps focused on east european soldiers, i think.

there was a cutscene, some small gameplay, all looking like very high production value.

but it never came to fruition. i wonder if that was one of his projects that the company didn’t go with.

This is why I see great potential in game streaming.

There has been much said about why cloud based gaming is a bad idea. I guess I need not link to that arguments here. I want to talk about why cloud might actually do a lot of good too.

Running the game in the cloud often changes the “this is impossible because it is too performance intensive” into “this is impractical, because it (significantly) increases costs of development and operations”. One cannot fight the impossible, but engineering is all about making the impractical be practical.

Imagine that instead of casting “four or five invisible rays” on the CPU we will be able to actually render the scene from the point of view of every (relevant) NPC on the GPU. We will of course have to change the textures first: the enemy objects will be drawn in red, the friendly ones in blue and everything else in green. Now the problem of detecting the enemy is a simple one: look at the rendering and count the number of red pixels. The great thing is that if we can afford to render things like reflection in the environment, the NPCs will be able to see the players reflection in a mirror and evaluate it as “hostiles spotted”. Amazing!

Now onto evaluating if the detected enemy should be actually noticed. I have few ideas there but nothing solid. (which is why I am still writing this instead of running my own Kickstarter :wink:

The bad thing is that we might need more than one GPU and more than one computer to do all this. That is the reason why I said at the beginning that the development costs and operations costs would be high. If this ever comes to be, I expect it will happen first in MMOs or other multiplayer games which would allow amortizing the financial cost of vision computations over a larger pool of players than single player does.

Now, running a game in the cloud on a cluster and taking advantage of everything this environment brings is hard, so if ever it comes to this, it certainly won’t be soon.

Hello again, just finished the third part and here it goes!

Once more, I’m sorry for it taking so long. My last few weeks before Christmas are also pretty busy. I probably wouldn’t be able to finish the last part during the next week, but I will make sure to have it ready by the last weekend before Christmas (in two weeks).

Have a nice reading until then!

Translation: @bebuce
Proofreading: @PhanTom_CZ

Artificial intelligence in games #3: Nobody wants a smart AI

How is the third Arma going to deal with teammate’s AI?

Cooperation

Mutual cooperation of its entities is a difficult task for an AI. Most players would probably think of a special forces squad advancing by-the-book in a perfect formation. In reality it all actually starts with the NPCs not walking into each other’s line of fire, in everyone not trying to take cover behind the same crate, or in sharing the player’s location.

Of course, the commercial AIs can do even the advanced show-offs, just like a squad moving in a perfect formation, or a crowd scene simulation with a thousand of figures pushing each other. If you take a look at a presentation demo of Kynapse AI, you will see how nicely it works.

What’s the problem then? Why do the NPCs in most games just limit themselves to popping up, spraying you with an unlimited amount of ammo and then going down after a single hit, while your mates are keeping their respectful distance somewhere behind and are capable only of getting stuck somewhere, or running straight into your line of fire to get accidentally killed? The veterans will now shed a tear in the memory of meeting the special forces in Half-Life for the first time and those crazy maneuvers of your enemies in F.E.A.R. Why don’t games make use of all that today’s AI can do?

Game versus reality

The thing is that the game is not reality and the goal is usually not to create a perfect simulation of some complicated activity, but to simplify it so that even a normal, untrained person can try and “live” through it. The creator has to find a balance between the game being a challenge, while also being entertaining rather than frustrating at the same time, so that the player has a good feeling from his accomplishments.

Everyone who ever tried multiplayer, airsoft, paintball or an actual war knows that to kill a living enemy is much, much harder than in any FPS game and we are not even talking about the moral difficulty of such an act, but about the very struggle to win. If you happen to face several well coordinated enemies just on your own, you’re practically helpless and good feeling is the last thing you will get.

I recently tried that out by myself in a paintball pistol tournament of three-person squads. The moment when you’re alone against three cooperating opponents is when you’re screwed, as you can’t cover three directions at once and any intelligent opponent of course surrounds its pray. The victorious team managed to get through nine matches without losing once and even with a single casualty, (which, as it happens, was my only kill in the tournament worthy of a record :).

Yet the basic premise of most games is the player standing alone against a huge swarm that he has to overcome, which puts the designers to an almost hopeless situation. The players are calling for awesome artificial intelligence, but if they got it, the game would be unplayable and vast majority of players wouldn’t like it at all.

The simplest thing the designers can do for the player to make his fights with the NPCs easier is to give him an advantage. Usually by giving his avatar some more endurance. This, however, leads to another undesirable outcome - the AI, set to expect its enemy to die after getting hit, would be somewhat “taken by surprise” that the player didn’t die and keeps on returning the fire with joy.

What now? If we leave the NPC standing in place and shooting until the player drops, that eliminates the original advantage we gave to the player. If the AI runs from the player, it would look stupid and we are back where we started.

If you count in the teammates on the player’s side, which are usually important for story progression, so they shouldn’t die, we are already quite far from achieving some believable simulation. Most designers don’t want the teammates to be able to achieve victories for a passive player and on the other hand they are also trying to avoid getting them killed, so that the player would not have to restart the level angry, for the failure was not his fault.

Probably everyone can recall the absurd situations in lots of games where you have a crowd of mutually antagonistic characters running around in a small space, everybody shooting like crazy, yet nobody dies. This is a result of exactly those problems. Another natural advantage the player has is to be able to repeat the part where he had a problem. The player knows what to expect and can use it to his advantage, while the AI starts fresh with each restart.

Do you remember HECU? Some people have the enemies from Hazardous Environment Combat Unit in Half-Life games chasing them in their sleep to this day

Imperfect reality

This raises a question of what should be called “realistic” and what is an “error”. If you go watching real people in a multiplayer game, you will probably see a lot of funny situations - friendly fire, throwing grenades under their own feet, pointless running around… If an AI does that, we would consider it a bug. Yet similar mistakes happen even in the real fights.

Friendly fire is a very serious issue in every war and who thinks that soldiers can’t get lost probably never tried walking in the woods with a map. Does it bother you that your teammates in Flashpoint react differently to your commands than you expected? You should try commanding some real people in a similar situation, you would quickly realize that they often behave in even more unpredictable and stupid ways than their computer variants.

It’s no wonder then that game designers started to focus on scripted coordinated puppet plays. We could use most introductory missions in Call of Duty as a good example. The designer gets a task to create a scene were the player’s unit storms a building and neutralizes the terrorists inside. If he decides to script that, it means he has to painstakingly develop every second of the action. He needs to set up all the animations for each soldier and time it carefully.

There was a lot of hype about F.E.A.R before its release and it has been quite justified afterwards

Everything in-game has to be set up so that the player couldn’t break it. A great thing is that if you can motion-capture it all, the final scene will look absolutely fantastic and only a few things could go wrong. The downside is that it will remain the same every time and the player will soon realize that he’s not really a player, but just a viewer.

Only few choose to go the other way, taking an AI, giving it a task and letting the things unfold on its own. To stand up in scrutiny against the scripts, the AI must be able to perform some visually impressive macho actions - to kick out doors, to take cover behind obstacles, to tilt while running in an arc… in short, to have perfect animations.

The drawback is that the animation sequences synthesized in real time from prepared universal moves can’t compete with a script which often uses animations that were captured for that scene specifically. The clear advantage is that every playthrough can be completely different and the player has a huge freedom of action.

Everybody makes mistakes. Who knows if that Korean that keeps crashing into the fence isn’t just under the influence of North Korean ideology and does it on purpose

Every script has its purpose

The main issue and I dare say the main reason why most developers prefer scripting over creating a solid AI is that the result is largely unpredictable and it can turn against its creators. Even if you put all that you can into testing and QA, you can never be sure what would happen and the more freedom the AI has, the more likely it is that something won’t happen the way you wanted.

Crysis 2 can serve as a proof. The creators were boasting about their most advanced AI ever to be found in a game, yet they got ridiculed. Every NPC that got stuck, threw a grenade under its feet, or couldn’t react properly to the player, was used against them as if they were lying. With a bit more exaggeration you could say that this kind of mockery is similar to someone ridiculing the God for having created people who suck at playing Counter Strike.

The environment in current games is usually huge and the AI, like the one in Crysis 2, simply does what it wants. A certain amount of errors, embarrassments and troubles is almost inevitable. Just like the players do make mistakes, so does the AI. Although, of course, this should be happening as rarely as possible.

Dan will close this four-part series about the fundamentals of gaming AI with a treatise on why AI in games is (still) not capable of sensible communication and natural behavior and why we probably wouldn’t even ever want that.

8 Likes

That’s because you rewrote nearly everything I translated :wink: Sometimes it feels to me like an enactment of slightly changed version of Adam Savage’s (of Discovery channel fame) motto: “I refuse your translations and replace them with my own”.

That’s the best part, IMO.

Sorry, I’m really trying not to be too intrusive and resort mostly to the stylistic stuff. But I also sometimes tend to be nit-picky, especially with the thought that there might be lots of people reading it after me. :slight_smile:
That translator you use always marks everything and makes it look like there’s nothing left of the original, that looks exaggerated! :smiley:

If you select a sentence, click “Show all x versions” and hover over the text with your mouse, it highlights the changes character by character.

I’m not a programmer (unfortunately - or fortunately?) But maybe it helps to orient themselves to the construction of fortresses. At all times, was trying to take over the number of attackers funnel shape to the minimal number of defenders to reduce / focus. For this purpose, we used sophisticated kennel facilities, restricted access to (low) gates, stairs, at the end ladders and planks that were pulled away in the dungeon during the retreat. The aim was always to eliminate only the first row of the attacker, without allowing them the opportunity of the attack on all defenders. Similarly, it worked in the (ideal) orders of battle. Friendly-Fire is acceptable if defenders are in the majority, the risk was factored in battles often and was part of the strategy. Often was fighting, orderly retreat by taking advantage of the (previously investigated for suitability) terrain the only viable strategy for victory - or at least to a stalemate. Ultimately, it came to undermine the enemy’s morale and increase the price of a (still more uncertain) victory. And - as in reality - it usually remains the escape as a last resort, when a fight can not be won. This decision, however, is the heaviest fighting, as Blücher wrote all right … As long as an escape route is available, the player also has a choice, he just needs to make the right decision. Oh yes, there was in the Middle Ages also the possibility to ask for mercy? Neither is glorious, but survivable.