Skip to content
עברית

Game AI

Definition

Game AI is the term the video game industry uses for anything that makes a character, an opponent or a game world look like it is "deciding" on its own: from the ghosts in Pac-Man to the zombie hordes in Left 4 Dead. In most cases there is no machine learning at all, only rules programmed in advance to create an enjoyable, well-balanced experience. That is different from the research meaning of "AI that plays games," such as Deep Blue and AlphaGo, where the goal is to win, not to entertain.

💡 Example

The red ghost in Pac-Man, Blinky, isn't "thinking" about Pac-Man. Each time it enters a new tile of the maze, it simply checks which tile Pac-Man currently occupies and picks the turn that brings it closest to that tile. That is a typical example of game AI: a simple computed rule that looks, from the outside, like intelligent behavior.

Two different meanings of "AI" in games

The term "artificial intelligence" shows up in games in two different senses, and it's worth separating them. According to Wikipedia's article "Artificial intelligence in video games," "academic AI—aimed at developing autonomous reasoning or learning—is distinct from game AI," whose aim is "engaging, believable, and efficient behavior for players," and which, according to the same article, often consists of "a half-dozen rules of thumb, or heuristics, that are just enough to give a good gameplay experience." That is the game AI most entries in this category are about: the Pac-Man ghosts, the characters in Left 4 Dead, the opponent in a racing game. The second sense is what this site calls "a computer that plays against a person or learns to play" — for example Deep Blue, which beat the world chess champion, and AlphaGo, which learned to play Go. These are systems built to win at a game, and they sometimes involve real machine learning. Both senses share the words "artificial intelligence," but not the method and not the goal.

The finite-state machine: the basic building block

One of the simplest and most common techniques for game AI is the finite-state machine (FSM). According to Wikipedia, an FSM "models an NPC as one state at a time, such as attacking or patrolling." A guard in a stealth game, for example, can be in a "patrol" state, switch to an "investigate" state when it hears a noise, and to an "attack" state once it sees the player. Every transition between states is decided in advance by the programmer: if X happens, switch to state Y. The method is easy to build and understand, but according to the same source, "these FSMs are simple to build but become difficult to extend as the number of behaviors grow": every new behavior a programmer adds adds more transitions that have to be defined between the existing states.

Behavior trees: when an FSM isn't enough

To deal with that limitation, behavior trees were developed, which also belong to robotics and are explained in their own separate entry on this site. The key difference from an FSM: the building block of a behavior tree is a task, not a state, and tasks are arranged in a hierarchical tree that decides, at every moment, what to try first. According to Wikipedia, behavior trees "have been extensively used in high-profile video games such as Halo, Bioshock, and Spore," and the article cites a 2005 conference talk on the AI of Halo 2, Bungie's 2004 game. Instead of writing out every possible transition between "patrol" and "attack" in advance, the programmer defines a list of tasks ranked by priority, and the tree checks them again and again in order of importance, running the first one it can currently perform — which makes it easier to add new behavior without rewriting everything that came before it.

Finding a way across the map: navigation and pathfinding

Another problem every moving game character has to solve is navigation: how to get from point A to point B without getting stuck on a wall. One of the most common algorithms for this, A* ("A-star"), was first published in 1968 by Peter Hart, Nils Nilsson and Bertram Raphael of Stanford Research Institute (now SRI International), as part of the Shakey project — an attempt to build a mobile robot that could plan its own actions. According to Wikipedia, "A* is often used for the common pathfinding problem in applications such as video games." Many commercial games divide the map into a grid of tiles, and A* efficiently computes the shortest path between them without checking every possible route — so a character can "know" how to walk around a table without a programmer having hand-coded that specific detour in advance.

The four personalities of the Pac-Man ghosts

Pac-Man, released by the Japanese company Namco in 1980, is an early and especially well-known example of game AI. According to Wikipedia, each of the four ghosts has its own "unique artificial intelligence (A.I.), or 'personality.'" According to a detailed analysis of the game's code (The Pac-Man Dossier, by Jamey Pittman), each ghost follows a fixed targeting rule: red Blinky aims straight for Pac-Man's current tile. Pink Pinky targets a point four tiles ahead of Pac-Man in his direction of travel, effectively ambushing him. Cyan Inky calculates a point two tiles ahead of Pac-Man, then doubles the length of the line from Blinky to that point — a rule that makes it hard to predict. And orange Clyde behaves like Blinky when more than eight tiles away from Pac-Man, but heads for his own corner once he gets closer than that. The ghosts also alternate, on a fixed schedule, between a "chase" mode, in which each one follows its own targeting rule, and a "scatter" mode, in which each retreats to its own corner of the maze. There is no learning here: four fixed arithmetic rules are what make the ghosts look like they each have a character.

AI that runs the whole game: Left 4 Dead's Director

Not all game AI controls a single character. Left 4 Dead (2008), developed by Turtle Rock Studios (by then renamed Valve South) and published by Valve, introduced a system called the "Director" that manages the entire game: according to Wikipedia, it is "a dynamic system for game dramatics, pacing and difficulty," with no fixed spawn points — instead, it decides in real time how many enemies and items to place, and where, based on each player's situation, location and skill, in order to keep tension high and make every playthrough feel different. It also uses visual effects, dynamic music and character dialogue as emotional cues. Valve's Gabe Newell, writing in Edge magazine, described it this way: "This is what makes procedural narrative more of a story-telling device than, say, a simple difficulty mechanism." This is a different level of game AI: not a character deciding for itself, but a conductor shaping the experience of the entire game.

FAQ ❓

What's the difference between "game AI" and AI that wins at games, like Deep Blue?

"Game AI" is the industry term for the rules that make characters and game worlds feel alive, usually with no learning at all, for the sake of entertainment. Deep Blue and AlphaGo, by contrast, are research systems built to win at a game, sometimes using real machine learning.

Do the Pac-Man ghosts actually learn anything?

No. Each ghost follows a fixed targeting rule programmed in advance (for example, Pinky aims for a point four tiles ahead of Pac-Man), with no updating or learning involved. Each ghost's "personality" is the result of a simple, fixed arithmetic rule.

What's the difference between a finite-state machine and a behavior tree?

In a finite-state machine, a character is in one state at a time, and every transition between states is decided separately in advance. In a behavior tree, the building block is a task ranked by priority, and the tree checks them in order of priority and runs the first one it can perform, which makes it easier to add new behaviors.

What does Left 4 Dead's Director do?

It's a system that manages the whole game, not a single character: it decides in real time how many enemies and items to place and where, and how to use music and effects, in order to keep up tension and make every playthrough feel different.

Why does a game character need an algorithm just to walk from one point to another?

Because the game map is full of obstacles, and the character needs to compute a route that avoids them. A pathfinding algorithm like A*, originally developed for a planning robot in 1968, finds the shortest route without checking every possibility.

Found a mistake, or have a source we should add? Write to us