How intelligent should enemy AI be?

Hey gamedevs, I just finished coding most of the states and skills into my SRPG type game, and am about to go do a second runthrough of the enemy AI conditionals. While setting up the status effects, buffs/debuffs, and various counter/reaction states, something crossed my mind. That being, how prone to making obvious mistakes should the enemy be?

For context, I have a few skills that cause 1-2 attacks worth of permanent dodges vs melee or an entire turns worth of a Precounter ability (think Hamedo from FFT). What I mean here, is that a competent human player would just ignore attacking an enemy that is going to 100% dodge an attack. A non-competent player not so much, but generally speaking this is something that will be avoided.

Now for the enemy AI, I can and have been setting it to just not use certain attacks vs conditions like these, because it is seemingly an obvious mistake to avoid. However, as noted, humans are indeed prone to error, and I am wondering if perhaps there should be some degree of error making present in the AI decision making process. You know, to make it more human like. Or rather, the alternative, to lock the AI conditions within the same choices I as a player would make. Such as not attacking the enemy who will obviously punish you for doing so due to their enhanced dodge state.

I want my game to be challenging. I intend to set up the enemy factions to represent me as the dev, so it is like the player has to fight against a ghost version of myself when playing the game. So I am leaning towards the never make any obvious mistakes line of thinking. But at the same time, I wonder if this is too formulaic, too predictable in a sense, too boring, and even too difficult.

So to break the question down to its simplest form...

Should enemy AI be able to miscalculate and make bad decisions?

Or should the decision making be as concrete as I can make it? A real challenge to fight through and win against?
I think a good way to go about it might be the best of both worlds, where you have both intelligent enemies that act according to you by way of bosses, and then the more general enemies that might be a bit more scatter-brained and random/prone to error with how they attack so that they can be unpredictable, but not ruthless compared to bosses.

I believe pokémon has this approach to a degree, where wild pokemon will use moves without a thought, leading to some silly situations, but trainer AI is a bit more intelligent with how it uses moves and preying on weaknesses, etc.

Of course this sort of approach might not benefit every kind of game--but I felt it might be fun to consider all the same. Like the more general enemies don't have to be completely braindead and could still potentially have some reactions in place to certain things, but just not as calculating as some bosses. This could especially be the case if the general fights are wild animals/monsters, etc. and it makes more thematic sense, like with the wild pokémon thing.
Hmm, that is a good idea and not one I thought of originally. I think I will consider this one a bit. It also makes me think of different difficulty modes. Perhaps instead of just increasing or decreasing player/enemy stat values at a higher difficulty, the AI also changes to match the difficulty.

I may have to write a bit more of a complex formula to make this happen, but I think it is well within my reach. Thank you for the suggestion @FrigidGaze
my AI is designed to find the weakest spot of the player's formation and exploit it.
in turn, that can allow the player to make the opening on purpose, and then close it on the AI.
for example: each action (by anyone in the battle) requires 3 components, position, action and target.
additionally, each AI battler has behavior modes: aggro, fear, support and flank.
for "aggro", *target* is *whomever enemy is creating the most problems*, which is *whomever enemy that the own party is being most troubled by*... each battler keeps aggro score.
and for "aggro", *position* is *whatever square is closer to [target], out of the collection of most available skills, ordered by damage.
if *target* is an archer surrounded by tanks or ranged fighters, *action* would be *whatever skill of mine is ranged* ... because *position* can't be the same position that is occupied by the enemy defenders of said target.

it's the player's own tactic that determines the enemy tactic.
and, the player can use their own skills to affect how the AI "sees" the battle, by pulling or throwing enemies around.

if the player thinks they can pull off a smart combo and create an opening, maybe they can, and it will pay off, but also if the player formation has an opening, the AI will find it... because it already exists, even tho the player hasn't seen it.

wild animals/monsters, etc
I have animals and beasts that are conditioned to run away if injured.
and, undead, demons and golems who will never run away, because they have no brain to be shaken by a player's mind-flaying. (except! undead who will run from a cleric's banishment. Because, CLERIC)
Definitely like the idea of variable AI behavior that adjusts depending on battle conditions. I haven't gone too in depth with this yet, but one example I thought was fitting was to have Assassin class characters actively look to kill (as in perma-death) wounded entities on the opposing team, while other classes such as a Knight or Paladin will skip these wounded/disabled entities to have more honorable encounters. Which is actually the strategically sound move in most cases. Assassin however wants to prevent a revive and earn a passive buff for actually killing a unit.

We haven't grown past permadeath for party members as a preference for strategy RPGs I hope!
In my opinion, AI should be what it stands for...... ARTIFICIAL INTELLIGENCE. And since Humans make mistakes, AI should too. It should be able to make mistakes.... but also learn from those mistakes. So, it won't just keep doing the same ineffective attacks or stupid mistakes over again.
Hmm, now that is an idea. Do you mean the enemy AI throughout the whole game, or a per unit or per battle basis? Say if enemy#13 whiffs an attack vs 100% dodge state, they will no longer use such skills against enemies with this state. Should all allied units in the same battle map now learn this behavior? Just the attacking unit? Or all enemies throughout the entire game?

Learnable behavior is not something I had thought of or considered at all.
*cracks knuckles* Alright. Let's do this.

First thing to consider: overall game difficulty. Without knowing this, any choice you make is gonna be the equivalent of throwing a dart at a globe and saying 'that's my next vacation destination'. Yeah, you can get lucky and go to Bora Bora. Or, you can end up in middle-of-nowhere.
The more challenging you want your game to be, the more AI you can consider implementing. The more choices your enemies have, the more options they consider. An easier game might have enemies try to target characters with low defense, with physical attacks. But the enemies won't consider passives, or damage-reflection, or an auto-life state currently on the player, or heck, they may not even look at HP. Another char might have 1HP, but high defense, so the enemies won't hit it.
A more challenging game might consider defense, and THEN look for the char with lowest HP, thus maximizing its chance to kill.
An even more challenging enemy might see that auto-life state and use a Dispel skill, allowing one of its allies to get the kill on the character.

I see you want your game more on the challenging side, but I've put all this ^ for anyone else asking this question, but going the opposite way.

Secondly, realize your players are most likely NOT going to play half as well as you. You are the dev. You know all the mechanics, all the skills, all the states, the effects, the numbers... There is a very good reason for the tip "if it's easy for you, it's normal for players. If it's normal for you, it's challenging for players. If it's challenging for you, it's impossible for players"
Your 'margin of error' or 'bad decisions' are going to be noticeably less than players'.
If I can finish a boss fight in 2 rounds, I expect the best of my players to take 4-5 rounds.

Third, how would you add in that 'error' to AI? It's not thinking. AI in this sense is just...a bunch of conditional checks. Are you going to add variance to its calcs? Like, if player hp > 10% +- 2%, then use Soul Stealer? Will you base it on chance? For example, if char has Dodge state, enemy has a 20% chance to ignore this and attack anyways?

Fourth, how far are you willing to take this? What can enemies check for? What can't they check for? Are they limited to looking at current states and stats, or will enemies be able to base their actions on possible player strategies - a future situation? Which takes priority? Do they have self-preservation, or will they fight until dead? Do they care about their allies? Will enemies in groups work together to focus-fire characters?

If you make AI too airtight, players will lose. Many times. They will get frustrated. Battles will be long, painful sloughs. If you puts 'mistakes' in the AI, it can become unpredictable in bad ways. Players might learn some of the AI tendencies, but the 'mistake' will cause the enemy to act in an unpredictable way - while the player was prepped and had planned for another reaction. Takes a lot of the strategy out of it on the player's side and comes down more to luck.

On top of all this, you have to...ya know...implement it.
'Wow, Cythera, really? I have to make something I want to make? Ah-DUH!'
It's not always that simple haha. You can plan out a complex AI on paper, but when it comes time to actual implement it, there's a lot more. How do you do variance? How do you have mistakes? How do you have enemy groups work together? Enemy AI act differently depending on difficulty, or environment, or choices made in the game? And if you do implement all this...will it even matter to the player? Or will they just try to brute-force it all anyways?

I say all this as someone with a penchant for pain, a love for insane boss fights, and making a final boss who currently has over 200 checks for her AI. Yes, it's fun to make a super-smart enemy that crushes players! Heck, I've joked about this so many times in my status posts haha.
But is it fun for the player? Is it possible for the player? Can the player reasonably learn the general gist of the enemy AI, and come up with strats to counter it? If the answer to any of those is no, then...I've made a mistake. A game isn't a dev vs players thing. It's not PvP. I'm not trying to break my players - despite my jokes about it... - I'm trying to give them a challenging, but winnable and rewarding, boss fight.

What's the point of adding AI to your enemies? To make them more challenging? Then add enough checks and options that keep players on their toes, and keep enemies robust. Not every enemy needs to consider every single mechanic possible in the game.
Sometimes, a simple strategy is the most effective one. Not all enemies need to be super smart to still present a challenge.

This is a topic I care a lot about, so I hope something in my long-winded ramble makes sense, and helps devs out.
Well, that really depends what kind of an enemy were talking about here, I think in most cases no tho. Because... each enemy would have its own "database" in it's "head" telling it what skills to or to not use, and what the attacking player's strategy is.
Really incredible post @Cythera ! I read every word and will take to heart everything you have said. While I don't think I plan to or even have the ability to make cooperative behavior for the enemy considering both my skills and the SRPG system I am using, I think I definitely can make basic plans of attacks, when to use a skill, when to not use a skill, when to use a support skill before or after an attack, when to retreat, when to advance, when to put up a defensive tile blocking decision, all of that I think I can do, and even more, but something you said towards the end rings the most true. KISS. Keep it simple, stupid! So in that regard, I think outside of obvious whiffs which can easily be checked with conditionals, or outside of obvious pairing of support and attack abilities, the rest should be somewhat set to a degree of randomness.

Let us say that out of 20 available skills, conditions prevent 12 of these from being executed. Of these 8, instead of hand selecting a specific action, let random chance be what determines what the enemy uses, following a check to see which target should be selected first. The skills in my game are the same for both enemy and player, and none of them I would consider duds. Most can be used interchangeably, and even a player who wants to bruteforce through using a single skill will probably find some success in this approach. In this same manner, an enemy who is avoiding making obvious mistakes, yet has a degree of randomness to select which skill to actually use, will also find some level of success as well. But the determining factor for both sides, and one I feel like I won't give too much focus on for the AI, is when are the ideal times to use the skills that pass the conditional check, outside of a few specific cases. This then gives the power to the player, in an evenly matched fight, to use their knowledge of the game, and general strategy as well, to turn the tides in their favor. For optional bosses and endgame content, this is then where the odds can be stacked against the player, where their knowledge and skill will be what determines a win or a loss.

You and others have given me much to think on, and I highly appreciate the advice and input.
one example I thought was fitting was to have Assassin class characters actively look to kill (as in perma-death) wounded entities on the opposing team, while other classes such as a Knight or Paladin will skip these wounded/disabled entities to have more honorable encounters.
that's my support and flank behavior, yes.
flankers will target whomever is targetting friendly mages, and will try and find the most vulnerable spot in the player's formation that isn't on range of anyone.
in addition to looking for opposing positions that are in range of own skills, they will look for the lot of tiles that are covered by opposing ranges and avoid it.
the support behavior will help whomever is being engaged by the enemy, based on available skills: if the heal skill is available, it will go to whomever ally is most wounded; if the debuff skill is available it will go to whomever enemy is causing trouble.
it will not directly engage a player character unless to defend themselves (which, triggers other support characters to defend IT, as per rules, so whomever had engaged IT can find themselves overpowered the next turn.)

all of this is set theory, and there's no analysis.
"from [battlers], pick [friendlies], order by [value], take the first one, get [position]", simple as that.
same for finding matching ranges and skills: "take [my range], overlay on [target], if [my position] is within it, *I* am in range".
previous versions of the system (by Gubid) would go entry by entry of the whole construct performing checks, which ground the game to a halt with lag.
that's my support and flank behavior, yes.
flankers will target whomever is targetting friendly mages, and will try and find the most vulnerable spot in the player's formation that isn't on range of anyone.
in addition to looking for opposing positions that are in range of own skills, they will look for the lot of tiles that are covered by opposing ranges and avoid it.
the support behavior will help whomever is being engaged by the enemy, based on available skills: if the heal skill is available, it will go to whomever ally is most wounded; if the debuff skill is available it will go to whomever enemy is causing trouble.
it will not directly engage a player character unless to defend themselves (which, triggers other support characters to defend IT, as per rules, so whomever had engaged IT can find themselves overpowered the next turn.)

all of this is set theory, and there's no analysis.
"from [battlers], pick [friendlies], order by [value], take the first one, get [position]", simple as that.
same for finding matching ranges and skills: "take [my range], overlay on [target], if [my position] is within it, *I* am in range".
previous versions of the system (by Gubid) would go entry by entry of the whole construct performing checks, which ground the game to a halt with lag.
What battle system are you using? It sounds like an SRPG. I assume SRPG engine if so? The AI options you present are quite something else, and it seems much more advanced than the system I am using (LeTBS). Lag has presented itself several times, mostly with AI behavior (pathfinding more than anything really).
The one thing I would add for possible consideration is that I don’t think the enemy AI should be at an advantage over what the player can know about the enemy. Meaning, if you don’t allow the player to know all the states, stats, etc. of the enemy, then the enemy shouldn’t know it about the player either.

If the player has to learn through observation and experience, then so should the enemy. If the player doesn’t know that a particular enemy is resistant to fire until they use a fire attack and it isn’t that effective, then why should the enemy know that the player has a high defense in any particular area.

And I definitely agree with the idea that different enemies should have different levels of intelligence and AI smartness based on what is reasonable for that enemy.

I generally agree with the other very good points that have been raised.
Thank you Zombie, that is a good point as well. I think I am going to try to make every stat visible for the player, but this would also be a good system to use to differentiate between the more intelligent varieties vs the plain garden weed types.

Something else I just thought of, as I have an 'Intoxication' state in my game. Perhaps instead of having this simply influence debuff/block resistance, it could work to lower the intelligence tier of afflicted entities. Thinking more about this, utilizing a hidden 'INT' parameter would be a great way to not only divide up, but organize AI behavior as well.
Thinking more about this, utilizing a hidden 'INT' parameter would be a great way to not only divide up, but organize AI behavior as well.
now you have to be careful. if youre saying that the ai's "intelligence" can be numerically quantified and you make it act based on their INT stat, you run the risk of overscripting your enemies and making them too predictable.
If a highly intelligent AI strictly follows a given priority, then once a player knows what that priority is, they can play around it with 100% accuracy. meanwhile lowering their INT actually makes it more dangerous as you can less reliably predict what it will do.
Actually, another point to consider would be that a particular state could influence the AI. For instance, if you have a Confused state or anything similar. That could cause a variety of things like:
  • No action on turn
  • Less than optimal action
  • Retreat
  • Charge blindly forward
  • Attack own party
  • Miscast spell
  • Hurt self
  • Etc.
Many of those could be considered “mistakes” but they are caused by the Confused state.
Very good point Robro. I don't think I will overscript the AI for that purpose, but rather help point out what not to do instead for enemies that fall into the higher INT category or otherwise.

I do like your suggestions as well Zombie. I actually just finished polishing the confusion state, but it is a rudimentary approach at best, simply flipping a coin and attacking allies if tails, enemies if heads. I don't want to make the enemy too dumb, even when confused, but this basic formula can definitely be modified a bit to mix it up.
Some of the questions I've asked myself when improving enemy AI:

Is it biological?
Is it fearful?
What if it was poisoned, would that make it too sick to sometimes move?
Does it get tired if the battle goes on for too long?
Would it have trouble moving if it became too injured?
Does it look like it has anger issues?
Does it look like it's excessively calm?
Does it use eyes? If so, can it see in the dark?
Can it see through the light?
Does it require excessive heat?
Does it require excessive cold?
What if the humidity of the area is too high, would that affect it?
What if the humidity is too low? Does it require water?
What if it's covered in water? Would it gain new skills?
Does it bleed?
Would bleeding cause it to panic?
Is it a large monster that requires a large ceiling?
Is it a flying monster that requires an open ceiling?
Does it have legs? And if so, would it be easy to knock down?
Is it smart enough to likely stand back up if it was knocked down?
How large is this thing? Would its height be naturally intimidating to the characters?

Hope these give you some ideas.
What battle system are you using?
Gubid's system, with a lot of custom patchwork and tweaks.
originally with Layy's isometric system, but I scrapped it because of some errors.

Lag has presented itself several times, mostly with AI behavior (pathfinding more than anything really).
probably because of that sequential scan I mention.
try using direct set theory.
pathfinding on my end is very clunky and the battlers will take a huge detour to avoid "cost per movement" tiles according to the logic, but it doesn't lag because it's not pre-analyzed.
that's on the to-do list, somewhere :$

if you don’t allow the player to know all the states, stats, etc. of the enemy, then the enemy shouldn’t know it about the player either.
toyed with that as well.
initially I wouldn't show the enemy stats because of an error in the GUI that I couldn't fix, but the enemy was always aware of everything about the player.
now I'm showing stats for everyone, but making the AI "dumb" on purpose is tricky. I have to keep track of skills the player has and hasn't used, their effects, and who has seen it. That's a lot of extra patching. (The framework exists, tho: the aggro system by Dasher42, it just needs to be worked on)
if someone can design a system with that included from the start, that should be the standard going forward, but patching existing systems to add that is not really worth it.
To add on to what @Cythera said about "choosing what difficulty you want":

It is also important to establish WHAT your difficulty is.

I'll use Warframe as the example:

If you are killing enemies in 1 hit, you're "where you're supposed to be" in terms of difficulty. The game trains you to do this, introduces systems that allow you to do it, and enforces it. So, then the "difficulty" of the game is in the "prep" of your character, not in the gameplay itself. Well, most of the time.

My own game is like that. Difficulty is "prep" and "intelligent decisions made".

A monster in my game isn't difficult because "it will exploit your weaknesses". It is "difficult" because you don't yet know how to beat it, or have limited your options for beating it, or haven't learned efficient ways to play.

Let me give an example:

A wolf. Standard enemy. It has enough attack power to kill the player outright in one hit if the player is wearing "Heavy Armor". They attack with the "Agility" stat against your "Reflex" stat (which Heavy Armor actually lowers). However, if the player equips "Leather Armor" or "Light Armor", that Reflex stat jacks up about 15-20 points, which means the Wolf will do... 1 damage. 2 damage. Maybe even... THREE damage a hit. But, that's it. 3 damage, maximum.

Okay, so how is the player meant to know this when they first encounter the Wolf?

The NPC's tell them about it.

So, to beat this "Wolf", the player is expected to:
1. Talk to the NPC's to get the hint on how to beat them.
2. Equip the correct armor for the situation.

This is just the basic understanding of this enemy. It doesn't even get into granularity. Wolves are "Beast" type enemies. Means they're weak to Fire and Blades. So, on the attack front, if you hit them with swords and Fire Skills, you wipe THEM OUT in one hit too!

And, they have a special feature. If one of your Fire Skills manages to inflict "Burn" on Wolves... they immediately run from combat. Which means you might lose out on that XP or drops if that enemy runs away. So... is it wise to hit Wolves with Fire Skills, then? It does kill them faster... but the risk involved is that you might lose their XP and drops if Burn hits. Or, you may want them to run away because of Burn.

It isn't just "The enemies are difficult". It is "what qualifies as difficulty in the game".

My players will find my game to be very difficult if they don't stock up on supplies constantly and play cautiously. They won't find it to be very difficult because the enemies have Super AI.

But, it's also a game about giving intelligent players a power fantasy. Players that prep, learn skill combos, memorize enemy archetypes, and find ways to cheese the system.

So, what is your difficulty in the game? What determines whether your game is "hard" or not? Is it just how the AI responds to you in combat? Or, is it something else?

Original thread: https://forums.rpgmakerweb.com/threads/how-intelligent-should-enemy-ai-be.168311/