Tuesday, March 14, 2017

Creating an Intelligence to Outsmart

Week 4 

William's Game 


For the past couple weeks, I've been working on making the enemies for my game work.  For a stealth game, an enemy's AI could end up carrying a lot of the gameplay's weight.  Being stealth is, after all, all about outsmarting and outmaneuvering a reactive foe.

And... this.

So, between my extremely time consuming job and the commute that comes with it, I've been working on designing my enemy AI.

When you're programming something like a Goomba, you don't have a whole lot to worry about.  You can juggle all of a Goomba's abilities in your head: walks right to left, falls off of platforms, turns at obstacles, kills Mario on touch, gets killed all of the normal ways.

But, when you're programming a stealth game's enemy, there's states of an enemy's awareness and proximity to the player that will determine their behavior.  And so, allow me to unleash onto your face the most exciting programming tool in the world:

The Flow Chart

If that doesn't get you all hot and bothered, I don't think I can help you.

So, if you can get passed the sloppy handwriting, you can see what is the foundation for the inner workings for what will be the most simple enemy in the game: no guns, pure chase, has a lunge attack that adept players can learn to dodge.  Another benefit of the lunge-attack that can be dodged is that this becomes an enemy that the player might see as a waste of ammo, making players who have saved up lots of ammunition feel privileged enough by their ammo surplus to dispatch these nuisances with ease.

"I SAVED MY AMMO FOR THIS VERY MOMENT"


Modular Design

A big help in laying out the behavior like this is that now I can segment the behaviors on paper to plan out as functions and subs to organize.  Once I have each aspect of the enemy's behavior compartmentalized I can pick and choose pieces from it to integrate into different enemy types, while switching out some parts (such as close distance aggressive chasing switched out for aiming and firing a weapon).

This is a kind of modular approach that is hugely helpful in organizing code when dealing with more complicated AI.  A good example of this kind of thing is in the way that a game like Doom handles its programming:
While that's a tad more simple than this stealth game's AI will be, it illustrates one of the benefits of having enemies with many possible states: small adjustments to a single state results in a totally different and unique challenge.

Part of what makes stealth games interesting is that you often learn multiple ways of maneuvering around and besting your enemies.  Part of what makes this extremely easy for creating difficulty curves is that you can put a twist on each individual approach at a time and it will inject a fresh dynamic into the scenario every time.

The best and easiest franchise to illustrate this approach with is the Batman: Arkham Asylum franchise.  The game gives you tons of safety nets up front for approaching enemies by allowing you to escape to gargoyles that you can perch and hide atop of.  But later on in the game, the enemies wise up and this happens:
This changes the entire dynamic of a stealth hunt.  You have the ability to jump to a gargoyle for safety, but not long before it will explode.  It will get you out of a pickle, but you won't be able to use it again.

The idea of small differences forcing players to improvise is taken to its logical conclusion with a genius boss battle in Arkham City where you have to battle Mr. Freeze, who can be attacked using any one of your stealth methods.
But every time you use a method on him, he immediately upgrades his suit and approach to prevent you from using that method on him again, forcing the player to constantly improvise to make it through the fight.

The Mr. Freeze boss fight is almost like an entire game contained to a boss fight, forcing the player to employ everything in their arsenal to adapt to slightly evolving threats.  In a way, it takes a complicated setup that the player can wander around freely and makes it more challenging and interesting by simplifying it in ways that reduce the player's choices in how to handle a situation.  Things become more complicated by becoming more simple.

And just like those Doom enemies up above or Mr. Freeze's suit, I can make an entirely interesting threat every time I change something small in an enemy's structure.  It's the easy and smart way to make a fun stealth game.

I still have some work to finish with the enemy's AI before I can really show it off, so that will need to be in a follow-up post.  But for now, rest assured that a good look at enemy AI is right around the corner!



Gabe's Comment: Totally agree with the post and I'm really excited to see this in practice! I do think it's worth pointing out, though, that all of the enemies in Batman, including Mr. Freeze, are only as good as the Bat's gadgets. Intelligent AI is a chore to deal with if you don't have tools that encourage exploration of their intellect.
I'm interested to see what enemies you come up with to specifically encourage creative exploration of your primary body snatch mechanic. Most stealth games feature the classic, easily distracted, line of site enemy. Maybe a few variations of it.
That's all fine and good, but what will make your game memorable are the things that can only be done within the context of this experience. I think it's wise to consider intuitive AI functionality over base line intellect.
Now if you'll excuse me, I have some Goomba AI to program. 
Are there other methods of organizing AI that you are interested in?  Are you a flowchart enthusiast?  Do you perhaps have no idea what was being discussed in this post?  Tell us about it in the comments below!

Want more immediate posts from us?  You can follow William on Twitter here and follow Gabe on Twitter here.

No comments:

Post a Comment