Original article was published by Etienne Brunelle-Leclerc on Artificial Intelligence on Medium
Looking to Get Into Game AI?
I am currently teaching a college class where the students are asked to specialize in a particular aspect of game development. As part of the course, the students are asked to research their chosen area of expertise extensively in order to better understand the tasks and responsibilities that lie within this particular career as well as to identify the key skills which they will need to acquire. This can be a daunting process for the students and as the questions kept coming in, I began to think about my own specialization─game AI. What is game AI? What is it not? How should you approach it? The following are my current thoughts on game AI as a craft and as an integral part of game development and design. I hope that this can help my students better understand the kind of work which they are expected to produce and perhaps give some insight to those that might be looking to get into game AI.
What is game AI?
AI is a monstrously large topic which no single developer can hope to master in a lifetime. It is also a thriving area of research and development with AI techniques constantly finding new applications in every aspect of modern life. For someone looking to get into game AI, it is important to first distinguish game AI from the general field of AI, or to position the former as a narrow, highly specialized subset of the latter. In most cases, game AI leverages a handful of tried and true AI concepts and techniques, most of which were pioneered decades ago, in order to provide interesting solutions to game-specific problems that range from the mundane to the esoteric. Notice the ambiguous verbiage there: “in most cases?”, “interesting solutions?”, “esoteric problems?” I am aware that this bears explanation and fear not, I will do my best to address this below. That being said, the upshot of the above is that you do not need to be an AI buff to design and implement game AI. You can get quite far with a solid understanding of algorithmic thinking and design and a familiarity with the core AI techniques that tend to crop up in games.
Just to be clear, you should not stop there. There is no such thing as knowing too much and the fact that games tend to converge on the same techniques does not mean that more advanced algorithms cannot or will not be used in games. Video games are a fast-evolving, highly competitive industry and developers are always experimenting with new technology. For example, there are things looming on the horizon that promise to challenge our very conceptions of games and design. AI is already being used to generate assets and assist in player control, often without them realizing it, much like how modern cars use computers to interpret the driver’s input. Before long, we may be playing games that design themselves. But that is a topic for another time.
At present AI has a broad range of applications in video games. It is used to automate certain aspects of moment-to-moment gameplay, like the movement of individual units in a real-time strategy game. It is also used to generate content like levels, items, characters and even entire fictional worlds on the fly. The extent to which procedural content generation falls under the purview of AI is a matter of debate. I tend to lump them together because the skills that are needed to design and implement these systems are quite similar. Another interesting use case for AI in games is what I like to call gameplay personalization. These systems track the player’s progress and adjust the game’s pacing or difficulty to ensure that it provides the intended experience for the player. Although dynamic difficulty adjustment has been much-maligned in the gaming press, gameplay personalization has been leveraged successfully in the past. Turtle Rock Studios’ Left for Dead series deployed an AI director that controlled the game’s pacing and difficulty curve to ensure that it built up to a satisfying climax.
That being said, the mention of game AI most often refers to systems that attempt to simulate the behavior of autonomous agents within the game world; systems that allow the game to play a part in the player’s experience, providing assistance, resistance or a bit of both. These systems are all but ubiquitous in games and as such they will be my focus for the remainder of this discussion. There are hundreds of ways of implementing agent behavior. Seeing as most games require us to pick one, I will offer a guiding principle in the face of what can seem like an impossible choice: game AI should provide interesting solutions to game-specific problems.
Interesting solutions to game-specific problems
Evaluating the output of an algorithm requires some kind of formal definition for success. We need to distill the problem at hand down to a set of parameters that the algorithm can manipulate in order to achieve an optimal result. Game AI differs from other kinds of AI in that the criteria for success are often arbitrary. While defining the optimum of a pathfinding algorithm is a relatively trivial task, the same cannot be said for a procedural content generator or a system that attempts to simulate the decision-making of autonomous agents. In those cases, controlling the output requires an aesthetic judgement on the designer’s part. Experienced designers will have developed heuristics that make it easier for them to approach these problems, but the truth is that there are no one-size-fits-all solutions.
The design of a game AI system will be tightly coupled to the design of the game, and games are not defined only by their technical construction. Games are also aesthetic objects: they are meant to entertain, to captivate an audience, to provide a compelling fantasy for the player to slot into. In the same way that games blur the line between technology and art, optimizing the output of game AI systems is as much a technical issue as it is an aesthetic one. Game AI should behave in ways that are interesting in the context of a particular game. This means that to design the AI for a game requires a deep understanding of the game’s design and its intended experience.
Video games are not simulations
Video games and computer simulations sometimes overlap. Many games present the player with a system that attempts to model a given situation which they are then free to poke, prod and tinker with to their heart’s content. However, we should not let that confuse us: video games are in fact not simulations. Simulations are mathematical models that allow us to make predictions about the outcomes of certain situations. Video games on the other hand are, as I said above, aesthetic objects. Some games leverage simulations as part of their core gameplay which then revolves around making predictions about outcomes in the game world. To achieve this, games like Sim City and Roller Coaster Tycoon feature an elaborate model of the game world and attempt to efficiently communicate the working of the model to the player. Most games however do not do this. In most cases, the player does not need to know the ins and outs of what is going on behind the screen, as it were, so long as every individual element plays its part in making the gameplay work. For that reason, I encourage game developers to keep a user-side perspective when designing AI, especially in the early stages of the design process.
Say we are making a game or a section of a game where the player is being chased through some kind of maze by AI-controlled agents. We could adopt what I like to refer to as the “feature set” approach to design where we start by listing the features that the AI system should have. In this case, we would need the agents to be able to find their way through the maze and to react based on their perception of their surroundings. Then, we could dust off a reference manual, look up fancy pathfinding and decision-making algorithms that fit within our performance budget, hook everything together and hope that it all works. Or, we could first stop and reflect on the particular game we are working on. What should the chasing sequence look like from the player’s perspective? What should it feel like? What kind of interactions do we picture them having with their chasers? Once we have a clearer idea of what the intended experience is, we can get to work designing a system that supports exactly that experience─nothing more, and nothing less. This approach tends to produce simpler results that are easier to work and that do exactly what the game needs them to do.
As tempting as it is to get carried away designing systems that accurately simulate the behavior of autonomous agents in a virtual world, we should not lose sight of the original goal: our job is not to make a fancy AI; our job is to ship a great game. The two are not necessarily mutually exclusive, but the former can definitely make the latter much harder to achieve. That is because complexity, especially extraneous or ‘hidden’ complexity that the player never sees or interacts with in any meaningful way, is the kiss of death when it comes to game AI.
Why simpler is better
Simply put, game AI should be as simple as it can get away with. For a new developer starting out, I would advise adopting an iterative approach. Start with the simplest implementation for the target behavior and test it. See how it interacts with other game systems and whether or not it supports the intended experience. From there, slowly and deliberately introduce complexity when and where it is appropriate to do so, but always in measured amounts. And check your assumptions about what needs to be generalized, optimized or abstracted: these things will become obvious in due time. This approach could be generalized to most programming practices, but I feel the need to outline it here because game AI is especially vulnerable to the detrimental effects of runaway complexity. Part of the blame falls on us designers: we just love to build up bigger and crazier systems, much like some people procrastinate by sorting their bookshelves or cleaning their apartment. Making the AI more sophisticated is not necessarily a productive use of our time: there is no guarantee that the game will be better for it. Worse, if the AI becomes unwieldy or its behavior becomes erratic, we have effectively created more work for ourselves (and everybody else). That being said, there are other more prosaic reasons why simpler is better.
Like other aspects of game development, game AI have strict performance constraints. These constraints have been somewhat relaxed over the last few decades, but they remain a part of every developer’s daily grind, especially on mobile platforms. Game AI typically ranks low on the pecking order for system resources, far behind rendering, audio, physics, etc. The AI is often the thing that gets axed when a game fails to hit its framerate, which means that in order for it to be included in the final game, an AI has to be fast. That is already a good reason to aim for simplicity: simpler is often faster.
But there is more. The design of a game’s AI is coupled to that of other core gameplay systems like combat, economy, etc. This means that changes within these systems will have repercussions for the AI. In an ideal world, gameplay would be feature locked before the AI developers are brought in. However as anyone who has ever made a game knows, that is simply not how things are done. Core gameplay systems are changed frequently and extensively throughout development which means that a game AI is likely to undergo several redesigns over the course of a project. Keeping complexity to a minimum will help alleviate the costs incurred when switching from one design to the next.
Last but not least, game AI abides by the fundamental rules of game development: much like we optimize for performance to ensure that the game runs adequately, we ensure that the game is as good as it can be by optimizing for iteration speed. When a problem arises, we need to be able to go in and debug it in a timely manner. Level designers need to be able to make adjustments quickly and often which means that we need to build powerful tools that allow them to get the most out of the AI. All of these things are easier to achieve when the complexity of the AI is kept in check. Simpler is simply better.
Note that simpler does not necessarily mean simple. The design of an AI depends first and foremost on the game that is built for: the AI for a racing game and a turn-based strategy game will share little commonality. The lower bound for the complexity of an AI is thus set by the complexity of the gameplay or the particular part that the AI plays in it. It is up to the designer to ensure that it does not stray too far above that threshold.
The game AI designer
As a game AI designer, you will be expected to be familiar with the AI techniques that are often deployed in games and to be able to use them to author interesting behaviors. This knowledge will allow you to make more informed decisions when building the AI system for a game. This does not mean that you should code everything in-house or from scratch. While some may argue that doing so would be ideal, it is seldom realistic or practical. You should be aware of what is available in terms of frameworks and libraries. As ever with it comes to programming, reading documentation is a valuable skill in and of itself. Most game engines come with a suite of AI tools and getting familiar with those is a good way to get started. If this is starting to sound a lot like a programmer’s job, that is because it is. Game AI is one of the more programming intensive aspects of game design. It requires domain-specific knowledge and skills that most other developers will not have. Be ready to educate your colleagues about the dos and don’ts of the particular techniques that your team is using. You may also have to develop custom tools that allow less tech-savvy designers to use the AI system when creating content for the game.
That being said, there is more to game AI than mere programming. Up to this point, I have stressed the technical aspects of game AI design because they can act as a barrier to entry. Much like a musician playing an instrument, you need to attain a certain level of technical proficiency in order to unlock the creative aspect. As I said above, designing game AI requires a blend of technical skill and design intuition. This is not something that can be learned from reading documentation. You should also become a student of game design and think critically about the role that AI plays in games. If you see yourself as more of a designer than as a pure programmer and you are interested in using game AI to drive your creative process, I have some thoughts on that matter which I will be happy to share in a future post.