Thursday, July 10, 2008

AI Design

I decided that Artificial Intelligence in the gaming world is something that is often glossed over when talking about game design in the sense that there are tons of pages detailing various dynamics of games a designer should consider, and even a couple discussing what exactly AI is. However, I am disappointed that there is a lack of publications describing the aspects of AI a game designer should know about when they decide to add some bots to their programs. While this post focuses on the impications, aspects, points of interest, etcetera specifically in AI for games, the concept can also be applied to Artificial Intelligence as a whole.

Lets start by defining what constitutes as Artificial Intelligence. AI is the ability of an object to make decisions that ultimately complete a set goal. This encompasses many things in a game, from bad guys shooting at you, to rival racers trying to beat you in a race. I like to split this definition into two types: Dumb AI and Smart AI. It might seem a little ironic that we call any amount of intelligence "dumb" or "smart", but it actually makes sense to classify AI as such. Imagine the classic game of Pong, where you play one paddle, and the bot (run by AI) plays the other. Each player tries to bounce the ball away from their side of the screen and past the other player. We classify this bot as having Dumb AI since it has a simple job of checking where the ball has moved to, and moving to match its position on the appropriate axis. There are no extra factors involved -- The bot doesnt check for where the player is, what kind of angle the ball should be bounced off at, or some other possibly critical decision-making datum. On the opposite side of the spectrum, imagine a game like Need For Speed, where the player is chased by police cars controlled by AI. This sort of AI is much more exciting in that the AI has to not only follow the player, but anticipate his next turn, dodge obstacles, and work together with other police cars to stop the player. This is a prime example of Smart AI. Dumb AI, while being effective in some situations, makes for very stale gameplay, or sometimes even frustration due to the bot being unbeatable.

Smart AI is what everyone wants to see more of. However, it comes with its own cons as well. A bot that is hardset on fulfilling a specific goal without factoring anything else in can lead to an unbeatable bot, which makes this type of AI just as terrible as the previous one. Since your average developer doesnt have a supercomputer residing in their moms basement, they arent capable of creating life-like intelligence that factors in human miscalculations and other realistic errors. This brings us to the next talking point; "Flawed" AI. To make sure a bots AI isnt infalible, many developers purposefully flaw their AI by adding a random chance that the AI will do the opposite of its goal, freeze up for a given amount of time, or something else that gives the player a chance to actually beat the bot. This sort of approach is completely in the wrong direction. The developer should not dumb down the AI for playability's sake. Now we get to the real meat behind this article. Lets examine two of the alternatives to purposefully dumbing down Smart AI, and figure out what Flawed AI really is.

First of all, consider what makes actual intelligence so manageable. Nature didnt create random counters that decide when an animal should eat and when it shouldnt. So what is stopping it from eating all of the food it can? The answer is a technique called prioritization. By prioritizing objectives, the animal can do what is most important at the time first, then doing the next most important thing. We can incorporate this into our AI in many different ways. Given that our game is a real-time strategy game like Age of Empires or Empire Earth, we can see how our gatherer-builders no longer gather until their "source of resources" is empty. Instead, they gather only when they need the resources and use the rest of the time to build vital structures.

Our second alternative is a business school classic called risk-benefit analysis. In this technique, the risk of a situation is compared to the possible benefits or perceived value. Risk-benefit analysis can be used in the previous example with similar effects. The further away a gold mine is from a guard tower, the more likely it is that the gatherer will be killed. In short, the further from defense, the higher the risk, and the less likely the gatherer will venture out to get that gold. To give another example, recall the Need For Speed police AI. The more police cars the player has damaged or totaled, the further back the other police cars will follow, and the less likely they will be to try to fish-tail the players car.

Flawed AI is an intelligent, objective-based approach to making AI more realistic and the gaming experience more enjoyable. Weve looked at just two alternatives to throwing our perfectly good Smart AI out the window. There are many more ways of achieving the same effect, but for now, Ill leave it at just these two. I might post about some more in a future article. Until then, enjoy building your worlds. If you have any games youre proud of, dont hesitate to post a link in the comments (Yes, comments are back up ;p ) or send them my way. blake.oxx@gmail.com (remove the dot)

2 comments:

Anonymous said...

COMMENTS ARE BACK UP?
SWEET.

BLAKE SUCKS!

Blake said...

rofl, Mat. I take it that means you liked the post :p