Understanding Game AI and Design Part 1: Intro and State Machines

Intro and State Machines

Planning Systems and Terrain

Examples and Conclusions

Artificial intelligence, for the present moment, isn’t a reality. The human race has not yet developed the technology to create an entirely digital, artificial form of life, much as we have tried. Will we in the future? it will be interesting to see!

One wonder, though, what the developer of “AI” in relationship to video games MEANS. Does it mean realistic enemy movements and patterns? Does it mean wandering pedestrians who act in a way fitting for common people in a large city? What exactly do we want when it comes to the intelligence of artitifical creatures in a video game? And is this something that we SHOULD WANT? Or, are we looking at the issue in an entirely wrong way?

I’m sparked to these questions by Cracked, of all places; if there’s a place where you can see the common Intenet consensus about many things, Cracked will usually provide you that answer if you look for it. In many ways, some form of complaint about “realistic” AI emerged ever since video games became more “realistic”, at least from an aesthetic standpoint. I want to take this deeper than a mere refutation article, however; what, exactly, IS AI in video games?


An Impression of Intelligence

So here’s my first question: how do you think AI works? Just thinking about it for a second, we did not create artificial life yet; it’s quite a few years away. So what, exactly, do you see in your video games? In effect, what you see in video games sits more on the side of “illusion” than “reality”. Good video game AI gives you the impression of intelligence; it doesn’t need to replicate it in a 1:1 ratio. In the exact same way a 3D film intending for lifelike graphics could never exactly nail the look of reality without descending into the uncanny valley, a video game doesn’t strive for a complete replication of real things in a digital environment,

And yes, this might seem obvious, but the constant demands for “better AI” means that we don’t quite understand how it works. Creative Assembly, the creators of the Total War series, know this well. Richard Turnbull, their battle system AI programmer, explains:

…the AI academics are your wizards and we’re your stage magicians – it’s all smoke and mirrors with game AI.  We’re trying to give you the perception of reality, and often we therefore look like we’ve got systems that are much more impressive than anything the academics can create, and we’re not doing anything more intelligent. In fact, in most cases, we’re not – what we’re doing is giving the perception of the AI being much cleverer than it actually is.

If you want to think in terms of metaphor, video game AI fits more into the category of marionettes and puppetry than creating life. Imagine, if you will, wandering through a haunted house; it’s designed for one purpose, to frighten you. The various elements in it, from jump scares to mechanical devices to actors, all emerge at preset (or relatively random) intervals for each guest. At the same time, the people who go into these things know the purpose, and know that much of the environment looks completely staged, yet they don’t care. The purpose of the haunted house supersedes the scripted nature of the whole experience.

Video game AI, in the same way, exists to make your experience more interesting and exciting. You do not encounter real things or real people; they form obstacles that you must overcome via some means, violent or not. That’s the whole reason why they function the way they do. If you want to face actual, real-life people, multiplayer exists to supplement that purpose. I guess people desire that in their single-player games as well, and that’s the crux of the problem for many people. So can you go for realism in this, or is that just impossible? Well, there may be a way to do it without so much “realism” as “appearance”, and that can look just as good!


State Machines and Complexity

Most game AI runs off what they call “state machines”, basically a list of different states that model/thing/whatever will take when a particular circumstance happens. Imagine a common enemy like a soldier, who has a walking patrol pattern (state 1), an enemy detection pattern (state 2), and a shooting at enemy pattern (state 3). All of these states will have different actions, or sounds, movements, and game changes associated with them, and those make up the bulk of what you see on screen: the game reacts to you, more often than not.

However, because they function via code and scripting, a video game programmer cannot account for every variable a player might encounter; games need to ship at some point, and the developer cannot squash every bug before release. Yes, these little points can and will break immersion, even in the highest budget game, but they inevitably arrive due to the complexity of the events occurring. Most times, I find these to be quite hilarious and dumb; video game glitches never fail to make me laugh, especially when they “break” the game in more ways than one.

Furthermore, you can imagine that state machines, even when placing states into a hierarchy of states, become predictable. I find that as the basis of any good video game – the ability to detect patterns – and that’s all well and good. What if you want to move beyond that, though? The work in states would quickly become insanely complex to an unmaneagable degree. To return to our Creative Assembly example, their communications director Kieran Brigden said thus:

When you start talking about an ever-expanding number of states then you start to run into problems. For example, if you have a huge number of states for a man in Empire: Total War, you then put 160 men in a unit, and 20 units in an army, think how many decision trees you’re having to do for every single man on the screen. We’re talking about several thousands of guys on the screen at one time; each of those has a massive state-based logic tree, so never mind your two percent processor overhead.

Obviously, state machines won’t account for the vast complexity of humanoid behaviors, especially when up close and personal. In a bird’s eye view strategy game like Total War, you might get away with it, but what about a first person shooter? Who hasn’t had the experience of dumb AI doing dumb things – that’s fun, but it certainly could suck the air out of the room if the game wants to immerse you. Are there alternatives?

About Zachery Oliver

Zachery Oliver, MTS, is the lead writer for Theology Gaming, a blog focused on the integration of games and theological issues. He can be reached at viewtifulzfo at gmail dot com or on Theology Gaming’s Facebook Page.