Thursday, June 04, 2009

Interesting…but wrong

I recently read an article on 'Cracked' entitled "The five things the Gaming Industry will never fix and why."

The section on AI was interesting in that the writer had an interesting theory about why team-mate AI seems to be so terrible:

"…it's not a flaw, necessarily. See, Resident Evil 5 doesn't want you to play with A.I. Sheva. They want you to play with a friend, in the co-op mode. Specifically, they want you to play with a friend who you forced to buy a second copy of the game. And Microsoft wants both of you paying monthly subscription fees for XBox Live.

It won't get fixed, because there's more money in not fixing it."

It's an interesting theory. It's also completely and totally wrong.

Oh, I'm sure Microsoft would love you to talk a friend into buying a copy of RE 5, but that game isn't exactly short of fans anyway. This is just a classic case of someone commenting on something they just don't know enough about.

AI tends to be fairly crappy because programming AI is hard.

Think of it this way, humans have instinct, intuition and years and years of experience to draw on when we need to react to something. An AI only has what it's been programmed to do. This is why AI controlled characters will do flat out suicidal things for apparently 'no reason'.

For example, let's say we program an first-person shooter AI with a set of simple rules:

  1. If you're getting shot at, take the nearest cover.
  2. If you have line of sight on an enemy, shoot at them.
  3. If enemy is in cover, throw grenade to flush them out.

Simple, right? But what if you're being chased by a massive number of bad guys and the nearest cover is 50 in game yards behind you and the next nearest is 50.1 yards ahead? Your AI partner is going to turn around and run towards the chasing enemies and get cut off when it really makes more sense to keep moving forward.

What happens if you're running to some cover, hopelessly out-numbered, but your AI partner isn't getting shot at at that second and has line of sight on a bad guy? He stops and shoots, of course, despite the fact he's starting a fight he can't possibly win.

Finally, your AI partner sees a bad guy in cover and throws a grenade…but he's only programmed to throw the grenade at the bad guy in cover…none of his rules say that it's a bad idea to throw a grenade at a bad guy who's only two feet away.

Of course, the solution is simple, we just program our AI with more rules. For example, only throw a grenade when no friendlies are in the blast-radius...but even with that rule, the AI could still throw grenades directly in our path…after all, we're not in the blast radius at the instant the grenade is thrown…so we need another rule to never throw grenades in a place friendlies are heading towards…but that cuts off the whole 'bang and clear tactic, so we write another rule…

This leads us to the next problem: More rules means more reaction time, more system resources and more to go wrong. If an AI has to constantly check a few thousand rules on the fly, things slow down. In a fast paced shooter an AI has to make split second decisions…it doesn't matter if it's the most intelligent AI in the universe if you've shot it a hundred times before it figures out what to do. Secondly, it doesn't matter if you have ultra-intelligent AI if the game looks like crap because all your system's processing power is tied up by the AI.

Last but my no means least, you suddenly have an AI with contradictory rules that has to react to hundreds of other AI's with contradictory rules in a constantly changing environment with an unpredictable human player thrown in for good measure. Things are going to go wrong.

This leads us to the next problem. Even if we have a system with infinite resources and infinite processing power, you can't program every eventuality. At some point your AI is going to find itself in a situation it's not programmed for…and that's when weird things happen.

Paradoxically, even AI that behaves exactly as it's supposed to can cause problems. Once you give an AI any form of 'free will' you lose a level of control that can totally break your game.

For example, 'Oblivion' had a game world populated by AI characters that were programmed with virtual 'personalities'. Each character had certain 'needs' and personality traits. For example, when a character's hunger level got to a particular point, that character might go to an inn to buy a meal. If they couldn't afford a meal, depending on how moral they were, they could go to work to earn some money or steal from someone else. The character they stole from might catch them in the act and run screaming or turn and attack them. None of this was actually scripted, it was just very clever AI characters interacting with one another, the player and the environment.

During testing, testers discovered that a drug dealer character who was supposed to give the player a quest was usually dead by the time the player got to him. Eventually they discovered the problem. By the time the player got that deeply into the game, the drug dealer's 'customers' had run out of money, stolen and sold everything of value in the town and had eventually murdered the drug dealer for their 'fix'. No one had programmed the characters to do this and it's an amazing bit of emergent intelligence…but the simple fact is it broke the game and the AI had to be scaled back for the retail release.

This brings us to the final problem which is probably the biggest of all: We expect more from AI characters than we do from real people.

You see, if you're playing a co-operative game and lose because a human partner made a mistake, it's just part of the game. If you friend Steve makes a mistake and gets you killed during a game of co-op Halo, it's not really a big deal. However, when you're playing alone and an AI character gets you killed or you lose because they did something stupid, that's totally unacceptable.

If you lose in multiplayer, your team just wasn't good enough…if you lose in single-player because of an AI, you're just playing a game where winning or losing is taken out of your hands. It becomes a coin toss.

In closing, AI has come a long way since the term was first coined. There will probably always be programs with AI, but it's not a marketing issue…it's a 'Programming AI is really, really hard' issue.


 

2 comments:

Evan 08 said...

I'm playing Oblivion now... interesting tidbit. (BTW, thanks to my awesome brother-in-law for bringing it to me.)

Paulius said...

I played the crap out of Oblivion on the PC. It's in my top five best games ever made.

The 'Radiant AI' system was seriously scaled back, but cool stuff still happens.

I remember a quest where I had o assassinate a guy, and returning to the town about a game-week later, I discovered that the guy's bodyguard had taken up drinking. He started a fight in a tavern and ended up killing a store owner and being chased out of town by guards.

None of that was scripted (it only happened on one play through)