Basics of Game AI
By Geoff Howland
Game AI (artificial intelligence) is the subject of a lot of discussion recently, with good cause. As games forge ahead in the areas of graphics and sounds it becomes increasingly obvious when the actions of the game controlled players are not functioning in an “intelligent” manner.
More important than the game controlled player’s “intelligence”, is really the game controlled player’s stupidity. Most game players are not expecting to load up the newest first person shooter and face off against Professor Moriarty with a nail gun. They do expect that they will not be playing against an inbred lobotomy patient that is confounded by the complexity of a corner.
Unit Behavioral AI
Game AI is not necessarily AI in the standard meaning of the word. Game AI for units is really an attempt to program life-like attributes to provide a challenge or an appearance of reality.
A guard in a game that stands in one place never moving can seem very unrealistic. However, if you create a routine to make that guard look around in different directions from time to time, or change his posture, he can start to look more alive. By creating a situation where another guard who walks in a pre-made path occasionally stops in front of the standing guard and appears to speak to him, the appearance of reality can be increased greatly.
There are two categories of actions in unit AI: reactionary and spontaneous.
Units act in a reactionary manner whenever they are responding to a change in their environment. If an enemy spots you and starts to run towards you and shoot, then they have acted as a reaction to seeing you.
Units act in a spontaneous manner when they perform an action that is not based on any change in their environment. A unit that decides to move from his standing guard post to a walking sentry around the base has made a spontaneous action.
By using both types of unit behaviors in your game, you can create the illusion that you have “intelligent” units who are autonomous, and not necessarily simple machines.
Reactionary inputs should always be based on the senses of the units. When modeling AI after human characters you need to take into consideration their range and distance of sight, their sense of hearing and if applicable, smell.
Creating levels of alertness is a good way to handle the input of different senses. If a unit sees an enemy directly in its sights, then it should switch to an alert mode that corresponds to how it would react to confronting an enemy. If the unit does not see the enemy but hears footsteps or a gunshot, then the unit should go to a corresponding level of alert that would apply to non-direct knowledge of the situation.
In the case of a unit that was a guard, hearing a gunshot would make the guard act to investigate in the area the shot was fired in. Hearing footsteps may make the guard stand in waiting to ambush the walking unit. All of these different kinds of actions and alerts can be set up in a rule-based or fuzzy logic system so that you can interpret each sound or sighting by every unit and have them react in an appropriate manner.
A general alert is also an important factor in the appearance of reality and intelligence in a game. If you have been running around shooting up a base full of people and keep encountering new enemies who are completely clueless to the fact there has been non-stop gun fire for the past ten minutes, it is going to really seem out of place. By creating an alert system for all the units, and perhaps an alert plan, you can strengthen the appearance of reality in your game world.
An alert plan would consist of rules that units would follow if there were an alert, as opposed to rules for non-alert situations. For instance, if there was an alert you could have all units that are in non-critical areas run to the entrances of the base to assist in the defense.
Spontaneous AI is extremely important in creating a sense of life in your game worlds. If everyone you meet is just standing there waiting for you to talk to them or kill them, or almost worse, wandering around aimlessly, it is not going to be very convincing for the player.
Some methods of breaking up the standing around problem are to give each of the units a set of non-alert goals. These could include walking pre-set paths, walking to pre-set areas randomly, stopping next to other units occasionally when passing them and walking with other units to pre-set destinations. I have said pre-set in all of these situations because unless you come up with a very good algorithm for setting destinations or paths your units are going to look like they are wandering aimlessly.
What really makes a game unit look intelligent is their actions. If they move in a way that the player might, or do an action, such as ducking, in a situation that the player might, then the unit can look intelligent. You do not necessarily need a lot of actions to create an illusion of intelligent actions, you just need enough to cover whatever basic situations your units will be involved in.
The more areas you cover, if you cover them well, the greater the chance that your players will believe your units are acting “intelligently”. Put yourself in the place of your units. What would you do in their situation? How would you respond to various forms of attack or enemy encounters? What would you be doing if nothing was going on at all?
If you answer these, and correctly implement them for each situation your units will encounter you will maximize your chances of having intelligent looking units, and that is the first step to creating a good, solid game AI.
This article was written by Geoff Howland, an independent contributor to GameSlice’s Game Design. His home page is located at www.lupinegames.com.