AI: Artifical Stupidity

First of all, this is going to be an extremely short and completely theory based tutorial. The reason I will not provide code on implementing the techniques discussed below is that they are (in my opinion) implemented differently for whatever situation they are coded for. There are many source examples on the Internet should you care to look hard enough.

Artificial intelligence is one area where many games fail to make a big impression on gamers. Many people complain about the dull and (ironically) robotic AI, that is so predictable and monotonous that it hinders the overall impact of the game.

There are many ways to make the artificial intelligence of a game more interesting and ways to make it part of the core gameplay - enemies that seek the player out, attempt to defend territory, heal when injured, or flee when dying. You might think this is complex and difficult to achieve, but through two quite standard and simple techniques - Finite State Machines (FSM) and Probability Distributions (PD), you can make your game a much more enjoyable experience.

Finite State Machines - A behaviour model that simulates intelligence wherein the "machine" (object) can act in only a finite number of ways.

Let's use a simple example - a shooter. Your basic enemy will be a fighter, that might have 3 states. Find, Flee, Attack. Using the principle of FSM, you would take information from the environment of the machine and from that information, invoke one of the states. In psuedo-code, using our shooter example:

The problem with this is that you suffer from the same problem that was the cause of writing the tutorial, predictability. The player would immediately see the states and every single enemy would become part of a "flock" an do the exact same thing in the same scenario.

The way to overcome this is to use Probability Distributions:

Probability Distributions - A list of probabilities assigned to various states of an object.

To implement it to our shooter example, instead of invoking the Attack subroutine when PlayerIsNear is true, you would raise the probability of attacking the player and reduce the probability of finding the player. Then, you could choose a random number from a range (one that is suitable for your game's difficulty), and depending on the number, invoke one of the states.

This leads on to many interesting things. If you introduce more states, then you could have very complex NPC's. Imagine in a shooter, where if you injure the enemy, and then the enemy runs off, but might alarm others if it is brave enough? Using the probabilities, it opens up a whole range of possibilites. You might have the problem that in a state where fleeing is the dominant probability, attacking, which is the least probable state, is chosen. No worries, this enemy might be a rogue brave fighter. Similarly, you could have fighters that flee at sight of you, making them seem cowardly.

The words "brave" and "cowardly" I have used there are personifying a few lines of computer code. With time and practice, you could come up with perfect probabilites to have a range of possibilites that your "AI" might take as a course of action.

This is just a short bit of theory that shows a little about a very underused (in the amateur game community) technique for implementing clever NPC's. It is also such a generic technique, it can be applied to every style of game where a certain level of intelligence is needed. An NPC in an RPG town who might react differently to different situations - if the evil king is defeated, he might be scared. Or maybe in your FPS you might have a group of zombies who when they are together have the guts to face you, but when they are alone they might just run away, alert others and call them to your location. If you look at it from other perspectives, it may seem that your game is "intelligent," but from the fairly simple code you wrote to implement them, you'll see that AI is actually pretty stupid.

Avinash "aetherFox" Vora
avinashvora [at] gmail [dot] com.
http://avinash.apeshell.net