Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
The Recipe for Good AI
In this article we look at how to put together a good AI, from a game design perspective.
You can read more of Jon's thoughts on design and project management at his website. You can also find him on Twitter. |
A solid AI is one of game development's hardest dishes to prepare.
I’ve worked on AI in a number of games over the years. Every nugget of wisdom I’ve picked up along the way points to one basic, possibly depressing lesson: creating a good AI is exceptionally difficult. Not only is it tough to make one that simply meets the incredibly low bar of not completely falling on its face - but even if you make a really, really smart AI it doesn’t mean you’ve made a good AI. After all, not everyone wants to be ruthlessly eviscerated by a merciless opponent. Some people are looking to roleplay, or just would prefer the AI keep the gloves on even when it has an advantage. Even those who want a serious challenge wouldn’t enjoy losing every game.
So what is the first step for a designer or AI programmer in this quest to prepare a five-star meal? No matter your task, the answer is always the same: identify your goals.
What Really Matters
Okay, so the lesson of “writing AI is hard!” is neither particularly useful nor surprising, but there is another so important developers must embrace it: all that matters is what players see and believe. Really. That’s it. The AI can cheat, act in or out of character, make dumb decisions, whatever – as long as the player is having fun that’s what counts. Developers are often surprised by which features players get the most enjoyment out of. “Wait, your favorite part of the game is the hats? That only took a day to implement!” Getting the most bang for your buck is important in all aspects of game development, but it’s absolutely essential with AI – the biggest meal of the year calls for the best ingredients money can buy.
AI is just like any other system in that there is zero value in it being well-engineered if the player doesn’t actually get something out of it. It’s incredibly easy to get bogged down in the details of how to solve the myriad of difficult problems that pop up, and never step back and realize you’re spending a ton of effort on a feature that doesn’t really contribute to the actual experience of playing the game. The risk of this occurring is particularly high with AI because much of the time it’s hard to tell if your code is even doing what youthink it is, let alone doing it well.
Okay, so you’ve laid down some goals and have vowed to dutifully follow through on them. The next thing our recipe calls for is to identify what can go wrong with a game’s AI. The AI has failed if a player considers it to be either 1) too random, or 2) dumb. The job of an AI developer is to sidestep these pitfalls in any way possible. Let’s first talk about how to make an AI appear rational, and not simply random.
Randomness can be cool - just not with AI behavior.
Preventing Random AI
A strategy for making an AI look less random is to actually make it less random. Sure, it sounds obvious, but how predictable or wacky an AI should behave is an important design decision. Perhaps instead of doing a random roll each time an AI unit can attack, a singleroll could be done at the beginning of the war to determine how aggressive all