Thursday, June 28, 2012

Enemy AI or: How I Learned to Stop Worrying and Love the Flowchart

Most games you play have some form of AI inside of it in order to control Enemy behaviors.

Some are incredibly simple; take the Goomba, for instance.
His only behavior is to move continuously to the left, regardless of pits. If he hits an obstacle, he reverses direction. Codewise, the Goomba behavior is pretty simple to explain and implement, and barely warrants documentation. Even Bowser, the main boss in each world of Super Mario Bros. consists of a continued pattern of jumping up and down while shooting fireballs.

But what happens when you need more complex behavior? What about enemies who actually change what they're doing depending on what the player is doing? Well, that's a bit harder.

I'm not a programmer at all, and have little skill with code; but as a designer, it is still my responsibility to document my ideas in a fashion that is easy to translate to code. The easiest way I've found to do this is using a Flowchart.

What is a flowchart? Well, if you've spent time on the internet, I'm sure you've seen a few humorous ones. But the actual definition is this:

A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. This diagrammatic representation can give a step-by-step solution to a given problem.
 Basically, flowcharts are invaluable charts for documenting, analyzing, designing, or managing a process or program. It allows a person to easily see the flow of the processes, and also design a chart that is more-or-less translatable to code. While it doesn't solve the problem of actually having to code the process, it allows people to create a well-designed algorithm, and most programmers and electrical engineers take advantage of them. For instance, here is a flowchart depicting the entire game of Tetris. Neat, eh?

But what does this have to do with Enemy AI?

Most enemies in older games rely on repeated, recognizable patterns. This is beneficial in a number of ways. For one, it's easier to program. But design-wise, it forces a player to recognize the movements and attacks of an enemy, and counter them to defeat it. Players typically get a nice rush when they recognize and overcome the patterns of an enemy. If you've ever played the Megaman games, you'll know that each Robot Master boss follows a very strict set of patterns explicitly made for you to recognize.

Bastards, each and every single one

As games have evolved, so has AI. Nowadays, developers try to create enemies that are the exact opposite: unpredictable. Normally, the reason for doing this is an attempt to emulate the ultimate antagonist: another human being playing against you. So many FPS, RPG and Stealth games in particular try to create an enemy AI that can anticipate what the player will do and act intelligently; but without being cheap or feeling artificial.
Not a good example of self-preservation

This last point is particularly important, because nobody wants to play against an all-knowing player who can see through walls and has perfect aim. But at the same time, nobody wants to play against a mindless robot that never changes up their patterns, defying any attempt of self-preservation. It's a delicate balancing act, between being bound to a pattern that players can recognize and overcome, and being just unpredictable enough to still be a challenge.

In Dead Gear, I'll be taking the more classic way to AI. Not only because it tickles my love of retro games, but because it's simply the best method with limited time and resources.

Here's an example of the first real boss monster in the game:


The Spore Crab that lives down in the Flooded Cavern, directly below the mushroom-filled Greenlight Mine. He's the first boss, so we need him to be pretty simple and forgiving. Every boss in Dead Gear will have a weak spot; the Spore Crab's weak spot is the green mushroom cap growing on top of its head. The player must bounce off the Green mushrooms on the side of the room and HIT THE WEAK SPOT FOR MASSIVE DAMAGE jump onto his head (which also functions as a bouncing mushroom!), and aim their attacks downward onto the weak spot.


For those interested, you can view a flowchart of the Spore Crab's AI patterns right here. Try to see if you can understand how it flows and moves.

Before this post gets way too long and out of control, I'll stop right here. I hope you liked this little talk on AI and flowcharts.

-Alex

No comments:

Post a Comment