
L'intelligence artificielle dans les jeux vidéo
AI Summary
The speaker, having worked in the video game industry for seven years, was initially surprised by the use of the term "AI" within this field. While typically associated with neural networks, deep learning, and language models, in video games, "AI" generally refers to the systems managing the behaviors of non-player characters (NPCs) such as enemies, allies, and passersby. Developers primarily use techniques for these NPCs that differ significantly from modern artificial intelligence, which is the focus of this discussion.
Before delving into video game AI, it's helpful to understand the historical context of artificial intelligence. AI, almost as old as computer science itself, aims to enable machines to perform cognitive tasks typically done by humans. As early as the 1950s, with the advent of conditional programming (if-then statements), rudimentary programs could simulate decision-making behaviors. This involved mapping human decision processes and replicating them in code, leading to what is known as symbolic AI. In symbolic AI, everything the machine is meant to do is explicitly programmed or can be linked to precise instructions, often with the help of domain experts. A famous example is the Eliza chatbot from 1966, which could simulate conversations by analyzing human input and reformulating questions based on precise rules.
In parallel, researchers began developing machine learning, where a program learns to perform a cognitive task by being shown many examples rather than explicit instructions. Neural networks, popular today, operate this way. Their history is marked by initial invention in the 1960s and 70s, followed by a period of near abandonment, and then a dramatic comeback around 2012 with deep learning. This resurgence was due to algorithmic advancements, the availability of vast datasets (thanks to the internet), and crucially, the use of graphics cards. These processors, originally designed to optimize video game graphics, proved highly effective for the mathematical operations required by deep neural network training. In a way, modern AI owes its existence to video games.
It's important to distinguish between machine learning, which largely defines modern AI, and symbolic approaches, which dominated initially but are less used today, sometimes referred to as "Good Old Fashioned AI." Surprisingly, video game NPCs predominantly still rely on this "good old fashioned AI," a field where symbolic AI remains prevalent for good reasons.
The most common form of AI in video games is for managing adversaries. In single-player games, opposition is necessary, requiring enemies to behave with some level of intelligence. The simplest method is a decision tree, where a series of if/then conditions determine an NPC's behavior based on its position, state, knowledge of the player, and other circumstances. This approach is easy to implement and offers total control over outcomes. While suitable for turn-based games, it's less ideal for real-time games.
Modern video games run at 30 or 60 frames per second (FPS), meaning game logic, including enemy behavior decisions, is re-evaluated every 16ms. If a decision tree is used, it must be re-traversed entirely 60 times per second. This can be computationally expensive for large trees or many entities, and it lacks continuity. An NPC might make a different decision every 16ms without memory of prior actions, appearing to "reboot" its reasoning constantly, which is suboptimal for real-time gameplay.
A more efficient solution for real-time games is finite-state machines (FSMs), a computational model used in theoretical computer science and industrial automation. For an NPC, an FSM defines a set of possible states (e.g., passive, alert, pursuing, attacking for an enemy) and rules for transitioning between them. The NPC's current state dictates its behavior, and transitions occur only when significant events or situations trigger them. This provides continuity, as the NPC remains in its current state unless a change is warranted. Pac-Man's ghosts are a famous example, with states like "chasing," "frightened" (fleeing), and "neutralized" (returning to base), each with specific transition rules. While Pac-Man's implementation is simple, many games have extensively developed this technique, even adding probabilistic transitions for variety. Doom (1993) used sophisticated FSMs with 8 base states and sub-conditions for diverse enemies, and Half-Life 2 (1998) pushed FSMs further by introducing sub-structures within each state for enhanced realism.
However, FSMs struggle with an increasing number of states. Incorporating factors like health, available weapons, player relation, and visibility leads to a combinatorial explosion of states and transitions. With N states, there are potentially N^2 transitions, making it difficult for designers and developers to read, debug, and evolve the system. Hierarchical state machines, where main states are themselves FSMs, offer partial solutions.
The widely adopted solution today, inspired by industrial algorithms, is behavior trees. Proposed in 2003 by Geoff Dromey for formalizing product specifications and behaviors (e.g., a microwave oven), this technique was quickly adapted by roboticists and video game AI programmers, notably for Halo 2 (2005). A behavior tree consists of elemental behaviors as leaves (e.g., run to enemy, shoot, open door), which can return success, failure, or "running." Intermediate nodes are control nodes: selectors and sequences. A selector executes its branches until one succeeds, offering alternative options. A sequence executes its branches in order, as long as each succeeds, breaking down complex behaviors into chained sub-behaviors.
For example, a character wanting to enter a building might follow a sequence: "go to door," then a selector to "open door" (if successful, continue sequence), "unlock then open door" (if first fails), or "force open door" (if second fails). If all options fail, the selector fails, stopping the sequence. A major advantage of behavior trees is their ability to handle behaviors that take time, with the "running" status preventing constant re-evaluation and erratic behavior. Their modularity is another key benefit. Unlike FSMs, which face combinatorial explosion, behavior trees allow easy isolation and reuse of sub-trees, which can be grafted onto larger trees. This improves maintainability, debugging, and code recycling across different situations, characters, or even games. Behavior trees have become the go-to technique for most real-time 3D games, including AAA titles, for managing all types of NPCs.
Despite the dominance of behavior trees, some games have explored different approaches. The Sims, for instance, models characters based on needs, loosely inspired by Maslow's hierarchy. However, unlike Maslow's rigid hierarchy, Sims' needs can all contribute simultaneously to their "utility," a micro-economic concept representing a character's overall satisfaction or happiness. Sims constantly calculate their utility and choose actions that maximize it, prioritizing, for example, eating when very hungry over socializing, even if a social need is also present. This system is simple and effective.
A limitation shared by both behavior trees and utility-based systems is their reactive nature, lacking memory, planning, or long-term objectives. The shooter FEAR (2005) attempted to overcome this with Goal-Oriented Action Planning (GOAP). In GOAP, each entity has an objective (e.g., eliminate the player), with preconditions that, when met, unlock actions. Each precondition can become a sub-objective, forming a graph that resembles a road network. Classic graph-traversal algorithms (like those used in Google Maps) can then be applied to devise a plan to reach the final objective. This allows for emergent action sequences (e.g., picking up a weapon, climbing a ladder, taking position) without explicit pre-programming by designers, as the character determines the best plan to achieve its goal.
It might seem surprising that the techniques discussed are mostly over 20 years old and still widely used. This is because they fall under symbolic AI, where rules are explicitly programmed. Modern machine learning, while often more effective, acts as a "black box," making it difficult to explain why it works. This is problematic for game development, where designers and programmers need to understand, debug, and adjust character behaviors to ensure the game is fun and challenging, not just populated by ultra-optimized, frustrating adversaries.
Nevertheless, machine learning is increasingly finding its place in video games, though often for purposes other than NPC AI, such as graphics rendering, animations, matchmaking, or cheat detection in online competitive games. Recent research explores using machine learning for vehicle or enemy AI, trained either on real player behaviors or through reinforcement learning (self-play). More recently, studios are investigating how large language models (LLMs) can enhance NPC interaction, moving beyond simple chatbots to enable allied characters to receive orders, discuss strategies, and function as a true team.
The speaker concludes by promoting his new book, "Le labo du jeu vidéo," which explores how physics, mechanics, optics, mathematics, and social sciences are applied in video game design and development across 30 illustrated chapters. The book covers topics from graphics rendering and character physics to procedural generation, animal management, and network play. It's a 432-page book with many illustrations, available for pre-order, which helps booksellers and online platforms gauge demand and promote the title.