Advertisement

AI in a fighting game: Reactive or proactive?

Started by December 17, 2010 08:41 AM
7 comments, last by IADaveMark 13 years, 8 months ago
Hi all GD.Net!

I'm new to AI programming (except pathfinding) but, as always, I'm doing my homework ;)
Now, I started to develop an action adventure game which I would describe it for it's mechanics as being in the middle between Kingdom Hearts and Prince of Persia 2008.
As in KH, players are teamed with 3 members.

And finally the time for the AI has come.
I'm using state machines, so far I'm really happy with it. For the two allies I have a "TeamMember" state which is working wonderfully, my partners are very believable mates and feel interactive.

For NPC enemies, I have an "Alert" state, which is a WIP as of today, but it's going in the right direction. For now they stand still with and when an enemy (i.e. the player) enter it's LOS it goes into "Battle" mode. In the future they will support patrolling. Another state (not written yet) will be called "Search" which happens when the NPC losts sight of the player's whereabout, and is looking for him to engage again (I find the idea of walking straight to the player's position as if it were a psychic or see through walls even when he's hiding horrendous) .
TeamMembers when engage their enemies, also go into the "Battle" state.

The game mechanics will allow melee attacks (with combos, already implemented), and magic attacks (close or distant, not implemented yet). There is a defend button. If the character hit the defend button with right timing, he will counter the attack (the combo is broken and both opponents are able to take a counter measure).

With this introduction to better understand how my game works, here comes the question of the topic:

Now what are your thoughts on the "Battle" state?, I want to hear your opinions.

Randomly smashing the attack button with random combo combinations until target is dead, eventually firing some magic seems stupid.
I was thinking of alternating proactive and reactive behaviors based on the following conditions:
* If the enemy is too aggressive in it's attack (many combos in a row, immediately started attacking), go to reactive mode. Most likely this means looking at what the player is doing or going to do, and play defensive, with a low random chance of countering.

* If the enemy is attacking, use some randomness to i.e. 1/4 of the time to go into proactive mode. But maintaining consistency with this randomness (don't switch to proactive in the middle of a defense, that would turn the reactive behavior useless and stupid). If the enemy is blocking or doing nothing, also go into proactive. The proactive state means choose a combo/spell and start smashing, while constantly evaluating if the enemy is about to perform something that could potentially change us to reactive. Note when two attacks clash, either both get damaged and blasted away, or only one attack prevails. The latter most likely scenario due to the game's logic.

What are your thoughts? Do you spot any potential problems with this design? Do you think I'm in the wrong direction?

So far the only problem I spot is that I have to be careful when my AI teammates battle against an NPC, they don't go both into reactive mode, teasing each other who's gonna start the first attack.
(By the way, the AI teammates can be replaced by cooperative multiplayer, but single player needs the AI)

I'm open to suggestions
Thanks
You might look into string matching, and n-grams. If you can get your hands on a copy of Ian Millington's "Artificial Intelligence for Games," it has a good description of this approach. The basic idea is that you can use a (very) simple learning algorithm to examine the sequence of player's actions and predict what they will do next. This has been used on this sort of game to create AI that is very nearly unbeatable - typically, you then have to dial the AI back a bit. Don't know how it would work for you, but hopefully it would at least be fairly simple to try...
Advertisement
Thanks a lot for pointing me with some direction!

I will try to get a hand on that book.

From what I see from google it means a way of predicting player's behaviors based on repeating patterns, storing their frequency in a multidimensional array.

This works EXCELLENT for my game as it can tell which combos it will choose, and each magic spell has a weakness against another magic spell, so it fits perfectly to predict which counter spell should be casted if the player is about to cast one.

I wrote in my description both reactive & proactive should anticipate in some sort what the enemy is about to do, so I think string matching works for both behaviors.

Thanks a lot!
Not that Kevin is wrong, but one advantage of your other method (in general) is that it has "tells" for the player. It shows a meta mentality of the different states that the player can use to predict what the agent might do and use it to his advantage. Remember, you aren't trying to make Deep Blue here... you're making a fun game.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Yeah, I may have been hyped a bit.

That's I've been thinking during the night. On one side, I have a nice algorithm that predicts and adapts to the player's style.
On the other, I have a determined AI style that is easier to understand, tune, exploit, and get beaten too.

Making an unbeatable AI problem applies for both techniques.
Because the next combo is decided a few frames before it is executed (sometimes even 500ms earlier, depending on which combo and when the player hit the buttons), if the technique I propose looks what combo has been decided and act accordingly, then it would be an all-known (labeled as "cheater") unbeatable AI.

I'm liking more my approach I first described, since it's easier to code, to understand, to stage encounters; and I prefer simplicity against complex algorithms. But because the game has this "Prince of Persia 2008" concept where fights usually happen between 2 teams of up to 3 members each, occasionally having 3 teams battling at the same time or 1 team against 16 enemies (but not one against one thousand) making each enemy more boss-like fights, an AI that learns from the player's style seems like it should help making each "boss" feel unique.

Quote: InnocuousFox said:
Remember, you aren't trying to make Deep Blue here... you're making a fun game.

Thanks, I'm constantly remembering myself, not only just when doing AI.
It took me too many years to realize this. When I did, I started seeing greatly increased progress. A game has to be fun, and if I also plan to live by this, then it also has to sell. Being realistic, non-realistic, with advanced 3D graphics, without them, doesn't really matter; they're just details.
Put another ways, often the fun in fighting games comes from players detecting the AI's patterns and reacting to them rather than the other way around.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Advertisement
If the technique you started with results in an unbeatable AI, then there's not much reason to use n-grams. And if you are in the fortunate position of having unbeatable AI, toning it down (having it intentionally make mistakes) shouldn't be too hard, I'd hope. FPS AI often has to do this with their aiming AI, for instance, since it's not too hard to write a bot that will never miss. So part of the bot's specification becomes how frequently it should hit.

If your game is too easy, you might try a combination of the two. Use n-grams some of the time to create a challenge, but then deliberately throw in a long sequence or other tells that the player can recognize. Or use n-grams to predict what the player will do, and then use that to select from among stylized responses. The player could even learn to use that to lure the AI into a mistake - if I play in this way, I can draw him into this long sequence that I can then exploit.
Just to keep the interested and curious one informed, I ended up deciding for the first algorithm I propose. With a few changes, of course.

And the algorithm is doing great. It's not the best AI ever, but it works, it's fun, it's simple, clean, and easy to fix if there are bugs.

The main reasons of this choice were because of what InnocuousFox said (it's gotta be fun) and I managed to solve what was worrying me about: which was that my AI would be a soulless repetitive enemy. In the end, I ended up with an AI which has (so far) 12 parameters which let me define it's behavior (ranging from aggressive, coward, preferring cornering the enemy, getting far so that it can strike back, make a lot of combos once it attacks, make none with single blow attacks, etc) this allows me to break the absolute repetitiveness, while tunning each type of enemy.

The other reason I didn't end up choosing N-Grams or other algorithms of any sort is because they didn't seem as easy to implement as this one, I didn't have experience writing one, and the most important: that algorithm relies on data, more than code. If the AI is being stupid... it's because it's tables/database is crap or there's a bug in the code? I don't have the time to debug both each time the AI is doing something it shouldn't; or wondering why the AI did something I didn't expect (and was stupid)

So far I'm happy.

May be the N-Gram and Co. algorithms will be implemented in a sequel, next iteration of the game. But for the foreseeable future, they're out.

Thanks for all who provided me hints, tips, and opinions.
Cheers
Dark Sylinc
Quote: Original post by Matias Goldberg
The main reasons of this choice were because of what InnocuousFox said (it's gotta be fun)

... and there you have peered into the vast chasm between game industry AI and what academics keep trying to sell.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement