(Subheader)

Updates Tuesdays and Fridays.

Tuesday, October 9, 2012

What do we want from our AI?

We've been working on implementing our first enemies (if that's the correct word for it) in Candlelight, and one thing we have been considering is how we'll do the AI. Our problems so far haven't been behavioral so much as technical (we're still trying to find the best way to implement what we want to do in Unity), but I got to thinking about AI in games this morning and thought I'd talk a little bit about what role it can play.

It's sometimes helpful to think of characters controlled by some kind of AI - I'm just going to group them collectively as Non-Player Characters, or NPCs - as analogues to characters in books or movies. Characters in a well-crafted book behave in a way that makes some kind of sense; we might not always agree with their choices or find them to be rational, but ideally we can understand  why they might make them. We expect them to behave in some way that seems reasoned, consistent, or meaningful. The Pac-Man ghosts chase us; we're not really sure why, but there it is. If one of them went into the corner and sat there, or only ever circled around one brick, we'd wonder what it was doing.

We wouldn't want our brightly-colored ghosts to not be believable.
The thing is, in a book or movie any action of a character is something carefully sculpted by the writer in response to a particular set of circumstances, all known beforehand to the writer. When Iago tells Othello a lie about Othello's wife Desdemona, Othello's reaction is based on a few very exact, very particular circumstances, including his feelings of self-worth, his perceived friendship with Iago, and his relationship with Desdemona. To say it's easy to come up with his reaction is a ridiculous overstatement, but in part that's because the reaction Shakespeare wrote was fine and nuanced (if crazy and violent), and that's what makes the characters in the play so intriguing.

Yup.
As game developers, we don't get those exact sets of known circumstances. We can specify conditions for an event, but when the number of unknowns start to pile up, it's hard to create a believable reaction for every set of circumstances.

Take Skyrim, which is actually quite good at AI in a lot of ways. Characters eat and sleep, run and hide when they're scared or fight when they're threatened, talk among each other, comment on quests you've accomplished or pants you aren't wearing, and so forth. That said, there are so many variables that for any given interaction with AI the devs couldn't hope to have accounted for all of them. If you approach the leader of a city after saving the city from a dragon, he'll praise and reward you, as might be expected. He won't, however, change his speech based on how many years it's been since you killed that dragon, on whether "somebody" quietly killed every person in his city, on whether the emperor has been murdered, on whether you're wearing pants, on whether he's wearing pants, or on whether you're wearing his stolen pants.

On whether you're violating his personal space, etc.
What's lost by this absence of pants-related dialogue is open to interpretation, though arguably if this is how you're playing Skyrim, you may not that interested in the authenticity of the NPC's reactions. What it means, though, is that there are limits to how realistic the gameplay feels, and those limits are tested when you go outside the bounds of what the game is centrally about - that is, slaying dragons, and doing a number of other, smaller quests along the way. (The fact that Bethesda actually did include a number of dialogue lines that characters will sometimes throw out when you're mostly nude probably says that a lot of players enjoyed doing this in Oblivion and Morrowind). There's a lot you can do in Skyrim, and the AI feels pretty good because NPCs react in a reasonable way to most of what you do.

And in general, that's what we ask for in a video game. When we turn up the difficulty in StarCraft 2 and see that our computer opponent is making units in a clever way (as opposed to making one of everything before building an army), is focusing on your weak points, and is changing its army compositions to counter yours, we think that's good AI. When that same computer marches its giant army to your unprotected front, only to turn that entire army around and waltz slowly across the map back to its own base because you've threatened with a pitiful force, we (rightly) think that's bad AI. The Turing test is useful here - would a person behave that way? not a skilled one - but we don't always need an AI that sophisticated. Sometimes, we barely need anything we'd call an AI at all; we don't need the goombas in Mario to make clever decisions, we need them to walk forward. They're more an obstacle than an enemy. And sometimes, that's fine. Mario isn't about believable character interaction. We're a little disappointed in the AI when that very first goomba walks itself right off a cliff without our intervention, but we get over it when we do likewise. We usually accept the idea of enemies as obstacles rather than rational actors (otherwise we'd expect the Bob-ombs to rush us all at once instead of in single-file), provided it still feels like they're trying to impede us. If the Hammer Bros. always threw hammers away from Mario, we would probably feel like the game was showing us a challenge (we can see the hammers) but not actually confronting us with it, and that would quickly kill any sense of achievement.

If your game, and your game world, is to feel like a believable world where the point is at least partly exploration and the gameplay is at least partly about feeling like you're an influence, you'll likely want the AI of the game to reflect that - you want characters and enemies that treat your character seriously, that respond to you. If, on the other hand, your game is more focused on the "game" side, then we want enemies that act to inhibit you, that change what they're doing based on what you're doing so that our players continue to feel challenged. In all cases, if our players feel like their choices and their skills matter, or they're going to question whether they have any agency at all. Sometimes that reaction can net you a cool emotional experience (this is in line a bit with what I said about horror last week). Unless you're going for it, though, take care to avoid it. People often come to games because they want a little more control than other media afford, and it's frustrating to be denied that - especially in a way that doesn't feel artful or deliberate.

2 comments:

  1. This is my favorite post of yours so far. How to make "good" AI is a tangled, knotty question that probably has no answers. Nonetheless, it is (to state the obvious) phenomenally important.

    It reminds me of the 1979 classic on artificial intelligence -- Godel, Escher, Bach -- written by Douglas Hofstadter. In it, Hofstadter investigates the means by which simple components, collectively, accumulate "awareness" through capacities for self-reference. I don't want to oversimplify (or spoil) his very elegant writing, but I think there it contains a huge insight which is routinely overlooked in games.

    Artificial intelligence, bluntly written, makes characters "do the right thing" in certain circumstances. Zerg AI knows its early build order, any FPS baddy worth his salt will strafe and run when you're shooting at him, and maybe if we're lucky, Skyrim's residents will know to acknowledge our undress. Each of these if-then conditions is important to drawing a good AI, but each above action, also, feels dumb, and obviously scripted.

    More elegant AI, to continue the acting analogy from the blog post, is not primarily driven by a script, but by a set of motivations. "Good AI" has purpose, in addition to a toolbox of actions. This is a little abstract, but here are a couple of examples: a major problem, I am convinced, with NPCs everywhere, is that they have no self-defined reason to be. As a result, if the "shop guy" is only there to sell you new swords, nothing else you do in relation to him has particular relevance -- unless the designer has coded conditional responses. This makes the game experience get meta, and quick. On the other hand, consider those pesky ghosts from Pac-Man. They may be dumb as hell, but damned if they don't know what they want.

    Think again of "patrolling" enemies, like red troopas from SMB. Although they are also simple, their straightforward coding gives them simple motivations: stay on this ledge. They're purpose is to guard.

    This is not to slight the massive efforts and skill required to make even passingly believable humans in triple-A titles. It isn't easy to instill purpose into characters who, ultimately, exist just to be a) shot, b) observed, c) talked to, or d) milked for information. But the problem is, if they don't have something else to do, the whole facade falls away. When NPCs exist only "for" the PC, they are computers. When they have desires, they are characters.

    ReplyDelete
  2. The thing is, though, that these games do often revolve around the character. Why is the red koopa patrolling if not to keep Mario out? Sure, maybe it's the smith's job to sell equipment to people other than the Dragonborn, but if he tells you to piss off because he's got another 9,997 swords to make for Ulfric Stormcloak you're going to have to figure out something to do while you wait. The key is to make a world that feels believable while still having that world be tailored to your experience. I think an important part of that might be to keep you from thinking about it too hard sometimes...

    ReplyDelete