Enemy AI Design

So I figured this topic hasn't touched on as much as the others, due to its complexity and/or difficulty of implementation. For the sake of this thread, let's just throw the "how-to" and other technical aspects of implementation aside. I'd like to discuss possible enemy AI patterns and behaviors. I was looking at the LeTBSconfig.js file and found several already made examples, which I will be listing to get us started. Hopefully, we can think of some cool ideas! (Which I can then use hehe.)

Note: Some of this will only apply to grid-based combat, while other parts can apply to all combat systems. However, I'm not trying to limit discussion to specifically 1 type or the other. Feel free to ignore any parts that don't benefit your project.

So without further adieu, here are some of the basics...

For positioning, we have 2 possibilities (that I'm aware of, would love to know if there's more)...

  • melee: prioritizes closing the distance to the target
  • ranged: prioritizes keeping a distance from the target
For skill/action selection, we have a couple more choices...
  • healing: skills that heal damage
    • usually, the AI will check for certain conditions such as...
    • is itself below a certain HP threshold? else...
    • who is the lowest HP ally and is it in range? else...
    • is the closest ally in range below a certain HP threshold?
  • support: skills that apply states
    • basically follows the same logic as healing, except it's a boolean logic (I think)
    • here I think the AI can be improved upon by dividing this category into offensive & defensive
    • otherwise, simply categorize skills that apply negative states as "offense" instead
  • offense: skills that deal damage
    • mostly straight forward, hurt the target
    • typically searches for closest target
  • the default AI seems to execute skills in the order listed above unless told otherwise
Also, for AoE, the AI can take into account the following...
  • maximize the number of targets
  • avoid friendly fire (or unfriendly for healing)
Let's not forget, we also take into account the conditional requirements in RPG Maker's enemies tab, under "Action Patterns". Here we can fine-tune the enemy's behaviors with various prerequisites. By default, the included condition options are:
  • Turn
  • HP
  • MP
  • State
  • Party Level
  • Switch
With these basic categories, we can create a combination of various behaviors. Different archetypes would prioritize different things. Now, my question is: Are there any categories I haven't mentioned that could be used to create more interesting/unique AI behaviors? Or if you prefer, simply give some examples of various enemy archetypes/behaviors. Lastly, what are some behaviors that would be exclusive to a grid-based system vs a traditional (default) battle format?

Example Enemies:

Vampire Lord
AI pattern: melee

  • Attack (melee) - Always, offense
  • Suck Blood (melee) - HP 0%~70%, offense, CD: 3
  • Lifesteal Aura (aura: 5, costs MP to maintain) - MP 50%~100%, support
Vampress
AI pattern: ranged

  • Attack (ranged: 3) - Always, offense
  • Seduce (ranged: 3) - Always, offense, CD: 7
  • Blood Rain (ranged: 5, aoe: 3) - HP 0%~50% (checks allies), healing, maximize targets, avoid (un)friendly fire, CD: 5
If you've got any interesting use of conditionals, let's hear em! 😂
I like to use conditions based on states. So if the enemy is hit with poison, for example, they would respond by using a more powerful dmg skill, or a skill that cures the poison and buffs their atk and def. Also conditions based on HP threshold are nice for changing attack patterns, but I like to stay away from enemies that restore HP. Also conditions that depend on the dmg element are useful.
I give each skill the player controlled actors can do temporary states that let the enemy track what type of skill was last used on them (not for every skill, just for skill groups) then have the enemy react intellegently based on what type of skill it was.
Though there are some situations were the A.I. might react to something more pressing like low hp. Or do a smarter action.

Essintally, i give the reactions different priorities for different enemies based on if what the player does would be very effective on them or not
I like to use conditions based on states. So if the enemy is hit with poison, for example, they would respond by using a more powerful dmg skill, or a skill that cures the poison and buffs their atk and def. Also conditions based on HP threshold are nice for changing attack patterns, but I like to stay away from enemies that restore HP. Also conditions that depend on the dmg element are useful.
Yea, state-based conditions are probably one of the most versatile ones. I wanted to use that in my examples but didn't feel like explaining the states at the same time so opted for simple examples lol.

I didn't know conditionals based on dmg element was a thing, where is that? I totally want to use it.

Btw, any particular reason you're not fond of enemies healing? I like the increased difficulty it provides.

I give each skill the player controlled actors can do temporary states that let the enemy track what type of skill was last used on them (not for every skill, just for skill groups) then have the enemy react intellegently based on what type of skill it was.
That's a neat idea!
add the concept of aggro and your system will be complete.
without a way for each character to determine which enemy to prioritize, everything is just random guesstimation.

if you have an aggro system (that is, a way for each character to keep tabs on which enemy is causing the most damage, or attracting attention in any way), suddenly you can predict what an enemy is going to do next, and with that, design an actual strategy.
I didn't know conditionals based on dmg element was a thing, where is that? I totally want to use it.
Technically it's not. But using some yanfly plugins and lunatic code it is possible to create passive abilities that react to damage and whether that damage is a specific element type. So while it's not technically a condition for an enemy to use a skill, they can react to element damage types being used against them. Since your OP said to not bother with application I didn't mention it before.

Also, when I say I stay away from enemies that can heal, it's more of a general rule as opposed to forever and always. There are always specific situations or encounters that make good use of enemies that heal, but I prefer those encounters to be limited rather than having, let's say, a healer class of enemies. I don't like enemies that heal to show up often because it can work toward dragging battles out.
That's a neat idea!
Yep. It goes something like this
example.png
Example_.png
add the concept of aggro and your system will be complete.
without a way for each character to determine which enemy to prioritize, everything is just random guesstimation.

if you have an aggro system (that is, a way for each character to keep tabs on which enemy is causing the most damage, or attracting attention in any way), suddenly you can predict what an enemy is going to do next, and with that, design an actual strategy.
Definitely! An aggro system would go a long way in regards to AI behavior. It would also simplify and reduce the need to create complex AI patterns. You just let the aggro system do its thing. If I remember correctly, you also use a tactical battle system for your project right? Do you have an aggro system implemented as well?

Yep. It goes something like this
Ah, so is that what you were referring to in your other thread?

Technically it's not. But using some yanfly plugins and lunatic code it is possible to create passive abilities that react to damage and whether that damage is a specific element type. So while it's not technically a condition for an enemy to use a skill, they can react to element damage types being used against them. Since your OP said to not bother with application I didn't mention it before.
Oh I see, in that case, it that doesn't seem that hard to implement. Very nice.

Also, when I say I stay away from enemies that can heal, it's more of a general rule as opposed to forever and always. There are always specific situations or encounters that make good use of enemies that heal, but I prefer those encounters to be limited rather than having, let's say, a healer class of enemies. I don't like enemies that heal to show up often because it can work toward dragging battles out.
Gotcha, I usually just go by the "theme" of the unit. Like it makes sense for a vampire to have some form of healing/lifesteal, but we definitely shouldn't give it to the majority of enemies lol. Although I'm a bit more liberal in its use for my game, but that's mostly because spells are quite mana intensive in general so they would only be able to get 2-3 heals off at most.
See a vampire with lifesteal makes sense. But fighting like 3 different types of vamps who all have some kind of self heal would be a huge pain.

Also, a tactical games more sense to have enemies who can heal show up more frequently because the battles are designed and play out much differently than your average turn based game.
See a vampire with lifesteal makes sense. But fighting like 3 different types of vamps who all have some kind of self heal would be a huge pain.

Also, a tactical games more sense to have enemies who can heal show up more frequently because the battles are designed and play out much differently than your average turn based game.
What battle system are you using for your project btw? I was gonna ask in that skills thread, but oh wells lol.
Using Olivia otb for the delay/speed up turn effect. Basically the same as yanfly ctb but I like it a bit better.
Do you have an aggro system implemented as well?
............bruh. >_>

it was probably the first or second feature I added.
it was made by Dasher42, for the default battle system. I had to tweak a few things.
............bruh. >_>

it was probably the first or second feature I added.
it was made by Dasher42, for the default battle system. I had to tweak a few things.
Ah, dang it. I just realized you're using VXAce lol.
Ah, so is that what you were referring to in your other thread?
No. cause the melee and magica states will do nothing to the player. What i was refering to in that thread was the state i didn't square in red

Edit: In response to the reply right above this one. You can implement a crude aggro system if you get a stacking states script and a script that lets you apply states to the user of the skill.
Basicly, make a state or two or three that increases a charecters target rate, that lasts maybe a turn or two. Then have the skills the actors use apply those states to themselves. And boom! you can make actors more threatening to enemies based on the types of skills they use
No. cause the melee and magica states will do nothing to the player. What i was refering to in that thread was the state i didn't square in red

Edit: In response to the reply right above this one. You can implement a crude aggro system if you get a stacking states script and a script that lets you apply states to the user of the skill.
Basicly, make a state or two or three that increases a charecters target rate, that lasts maybe a turn or two. Then have the skills the actors use apply those states to themselves. And boom! you can make actors more threatening to enemies based on the types of skills they use
Yea, I had totally wanted to do that...unfortunately LTBS flat out ignores Target Rate. So I've been looking for an alternative aggro system ever since. I'll just have to make do in the mean time...

LTBS does have a basic Taunt feature though, that forces all enemies to focus the unit with that state, but that's the extent of it as far as I'm aware.

Edit: ACTUALLY! Your post gave me an idea for a potential loophole/workaround! I could create the states you mentioned and have some kind of way (maybe an event?) of comparing which unit has the most stacks/variable/"aggro" and give that unit the Taunt tag. Gonna go try it out hehe...

Edit2: Now when it comes to aggro, have any of you guys seen a target-specific aggro system in RPG Maker? Or are they all troop based? As in all enemies will attack whichever party member has the highest threat vs each enemy having their own "threat meter".

Like if the enemy troop has monster A, B, & C then actor A attacking monster A would mean monster A would want to attack actor A, but monster B and C wouldn't, all things being equal.
Battle A.I. Core (YEP) which I like because you can do conditional skills like @HumanNinjaToo said if the enemy's hp is going lower like @Oddball said, the enemy gets increased attack like the aggressive state.

Since you create a tactical game, I think it would depend a lot on the range of attack of the enemies and how far from the party members.

AI pattern: melee
  • Attack (melee) - Always, offense
  • Suck Blood (melee) - HP 0%~70%, offense, CD: 3
  • Lifesteal Aura (aura: 5, costs MP to maintain) - MP 50%~100%, support
Vampress
AI pattern: ranged
  • Attack (ranged: 3) - Always, offense
  • Seduce (ranged: 3) - Always, offense, CD: 7
  • Blood Rain (ranged: 5, aoe: 3) - HP 0%~50% (checks allies), healing, maximize targets, avoid (un)friendly fire, CD: 5
Wow, cool ideas. You are surprised me all the time now.🤣

Do you play War of the Visions: Final Fantasy Brave Exvius?
I mentioned the placement of both enemies or heroes. Think about it, when you place both parties closed it becomes the skirmish. The rangers will have to be careful because the melee will cut the weak rangers up.

However, if you place them far apart, the ranger which includes the mages and the archers has advantages of the first hit.

I hope the characters like the vampire lord and the vampiress have the ability to teleport like turn to a bat, but again I do not know what you are planning.😤
Except for bosses, I don't generally make standard enemies too complicated.
I give them one or two quirks and done.

And the quirk usually tied to the action rather than the AI.
The AI will simply select skills with simple conditions. I don't want to make it complicated as it's a waste of development time and it does nothing but for the sake of being complicated.

The action quirk can be something like
- Do action --> chance to buff themselves at the end of the turn
- When buffed --> next attack will do 3 attacks
- Buff has a chance to be removed when gets damaged
- Done... that's all they need to have

Or something like
- The normal attack has a chance to cause bleed
- The enemy deals even more damage when you're bleeding.

--------
For the grid battle system, however, my planned AI will be complicated to implement. But simple to understand.

The behavior of the AI will be determined by the listed action as the default RPG Maker. Each skill will have a targeting grid. The action will be filtered if any of the valid actions (conditionally true like state, hp, etc) has target available. If there is no available target at the targeting grid, they move at random during that turn.

If two or more action has target available, pick the action randomly based on the rating like default engine. Then began to calculate the aggro. Each grid has 0 aggro value except when it is occupied by the target. Say, the default aggro value is 100, the AI will roll the targetable grid based on the aggro value. The higher the aggro value, the higher chance to get selected. That said, if the skill is AoE, say it has a 3x3 range, the aggro value will be accumulated based on the affected area. If two targets are in the AoE range, the aggro value of the center explosion will be 200 and the AI will more likely to target that spot.

"What about a friendly fire"
I can simply make the aggro value backward/negative when that happens so they will less likely to target the area.
Personally I have implemented several AI-related stuff for my game, some of them are already tested and true but there's still room for expansion as well as improvisation.
The thing is, in order to make enemies make much sense in combat, I think there's no such thing as generalized AI for all enemies. Enemies with tailored AI make the combat more sensible and promotes strategy in each encounter.

Spoiler: Anyway, something I need to say about AI
While making basic rules for enemies' action is all good and dandy, there's a complication when it comes to conditions like turn, position, allies, etc. Also, you need to put the player themselves into factor.
And speaking of behaviors, considering the example is in the grid system:
  • Position-wise, there's always a moment where enemies will just reposition themselves or simply standstill for the rest of their turn. If there's an enemy that is immobile for some reason, make it so its turn won't be wasted on being a sitting duck for player's characters to spectacularly pwn it;
  • Healing/support-wise, it might be negligible if the enemies are mere meatshield or too dumb to use any skills/spells. Otherwise, arrange their behavior accordingly, also make sure the skills/spells are valid before use (range, cost, function, effectiveness, you name it) and they know who they need to prioritize the most (least HP, most amounts of debuffs inflicted, most effective effect when applied on allies based on stats/positions, etc.); on another hand,
  • Offensive-wise, both melee and ranged enemies will usually attack their targets by default, so the only thing that really comes into factor is their attack range and which target they prioritize the most. While ranged units can kite their target, they're usually not coming with great effect (those who can do splash damage/AoE is another case btw). Also, accuracy is a thing unless the game states otherwise; and
  • Special conditions may apply according to how the AI is written and what condition that must be satisfied to execute an action. This includes aggro, amount of damage taken, amount of remaining HP/MP, etc.
In order to make a much sensible AI, you don't actually have to make them smart. Make them too smart and rest assured the player will rage quit soon or later, mostly sooner than expected.

And now, if you've read the preamble of mine above, let's get into my example.

------------------------------------

Golem
Melee unit, Bruiser/Tank
Effective range: 3 tiles
Behaviors:
  • Normally, attack the strongest enemy within their effective range.
  • If the closest prioritized enemy is beyond effective range but positioned at 12 o'clock from its position OR there are more than 2 enemies positioned in a line straight ahead of its current position, shoot "Ether Beam" straight ahead.
  • Once every 2 turns, perform "Pulverize" and seal the proximity with an obstacle. Enemies in 3x3 tiles will take damage. Prioritizes spot with most enemies clustered around.
  • If an enemy unit deals more than 200 damage to it, performs retaliation attack to the attacker, dealing 200-300% base damage to the target and enemies within 3x3 tiles. Can only be done once per turn.
Corrupted Priest
Ranged unit, Support
Effective range: 7 tiles
Behaviors:
  • Always check for allies with least HP then heal them with "Healing Wave" anytime an ally has below 75% HP.
  • Once every 4 turns, casts "Dark Incantation" that boosts allies' HP regeneration and defense rating. Prioritizes position adjacent to most allies as the epicenter of the spell.
  • At the first turn and every 4 turns onward, inflict "Curse" on target enemy, prioritizing Casters and Supports. The curse silences and frails damage the output of the target enemy for 3 turns.
  • If silenced, has insufficient MP to cast spells or requirements for the aforementioned actions are not satisfied, perform a normal attack to target enemy with the least HP within effective range.
  • When dies, casts "Unholy Blast" on the attacker who did the last hit on him.
Except for bosses, I don't generally make standard enemies too complicated.
I give them one or two quirks and done.
Oh, I definitely agree with you there. The average mook doesn't need much, but I do prefer bosses to be a bit smarter/complex.

For the grid battle system, however, my planned AI will be complicated to implement. But simple to understand.

The behavior of the AI will be determined by the listed action as the default RPG Maker. Each skill will have a targeting grid. The action will be filtered if any of the valid actions (conditionally true like state, hp, etc) has target available. If there is no available target at the targeting grid, they move at random during that turn.
I highly commend you for undertaking such a project. Respect! (too bad I use MV, oh wells lol) I do have one suggestion though. Instead of having the unit move at random, perhaps have the AI either move towards or away from the nearest player unit depending on whether the AI unit is a melee or ranged unit (or any other archetypes you can think of). This is why LTBS comes with these 2 unit categories. Since you mentioned this is for if there is no target within the skill's scope, you should have it search the entire map/battlefield for the nearest possible target, and move according to the unit archetype. This would better position the AI unit for the following turn and ensure there aren't any nonsensical behaviors like having a melee unit move away from the player units by random chance. Other than that, it sounds very promising! I love that you've incorporated aggro as well.

If two or more action has target available, pick the action randomly based on the rating like default engine. Then began to calculate the aggro. Each grid has 0 aggro value except when it is occupied by the target. Say, the default aggro value is 100, the AI will roll the targetable grid based on the aggro value. The higher the aggro value, the higher chance to get selected. That said, if the skill is AoE, say it has a 3x3 range, the aggro value will be accumulated based on the affected area. If two targets are in the AoE range, the aggro value of the center explosion will be 200 and the AI will more likely to target that spot.
So is your aggro system tile-based instead of unit/entity based? If so, that's quite interesting...I hadn't considered that. It could allow for greater versatility. I can see that's how you took AoE into consideration.

Personally I have implemented several AI-related stuff for my game, some of them are already tested and true but there's still room for expansion as well as improvisation.
The thing is, in order to make enemies make much sense in combat, I think there's no such thing as generalized AI for all enemies. Enemies with tailored AI make the combat more sensible and promotes strategy in each encounter.
Thank you for the detailed response. It definitely makes sense to tailor the AI to certain enemies, I wasn't trying to suggest making a one size fits all AI. The stuff I listed was just the basic default behavior patterns that came with LTBS, which also allows you to create your own custom AI patterns. That's basically why I made this thread. I'm so grateful for your post, it's pointed out some areas where I can improve on the default LTBS settings.

From what I can tell, it is probably more efficient to have an AI unit move only when a skill/attack necessitates it (before acting I mean). After the AI unit has used an attack or skill and has not moved position as a result OR simply has not used an attack or skill (for whatever reason, such as conditions or lack of valid targets), it can then move according to its unit archetype (melee or ranged). This minimizes the possibility of wasted turns. This would also be how you implement a kiting ranged unit as you mentioned.

Position-wise, there's always a moment where enemies will just reposition themselves or simply standstill for the rest of their turn. If there's an enemy that is immobile for some reason, make it so its turn won't be wasted on being a sitting duck for player's characters to spectacularly pwn it;
This is definitely something I want to add an extra condition for, so if the AI unit is stuck/immobile, it will act defensively or use a heal/support skill. Thank you.

If the closest prioritized enemy is beyond effective range but positioned at 12 o'clock from its position OR there are more than 2 enemies positioned in a line straight ahead of its current position, shoot "Ether Beam" straight ahead.
Hmm, would it still look for the 12 o'clock position no matter if the Golem was facing up vs down vs left vs right? If this can be taken into consideration, it could be extrapolated to target any unit that's in a straight cardinal direction relative to the Golem. Neat, ima do some research on this...

At the first turn and every 4 turns onward, inflict "Curse" on target enemy, prioritizing Casters and Supports. The curse silences and frails damage the output of the target enemy for 3 turns.
Now, this is interesting...having the AI unit target certain player units depending on that unit's role. I will definitely be looking into implementing this. It would be interesting to imagine how it would interact with a possible aggro system though. Perhaps bypass the aggro mechanic for this condition? Alternatively, simply have different roles/archetypes generate various amounts of aggro so this skill would naturally target the casters/supports.
From what I can tell, it is probably more efficient to have an AI unit move only when a skill/attack necessitates it (before acting I mean). After the AI unit has used an attack or skill and has not moved position as a result OR simply has not used an attack or skill (for whatever reason, such as conditions or lack of valid targets), it can then move according to its unit archetype (melee or ranged). This minimizes the possibility of wasted turns.
But how about enemies who cannot attack, cannot cast skills/spells BUT can set up their attack/skills/spells if they're in a better position or simply evade any possible incoming harms coming to them? Like chess, sometimes you need to move your unit to another position to secure them or to set up an even better strike in the next turn. If I were you, I'll consider this as something to put into factors.

Hmm, would it still look for the 12 o'clock position no matter if the Golem was facing up vs down vs left vs right?
Simply put, it'll just beam anyone and everyone dead ahead in front of it, relative to its facing direction, even if there's an ally in the possible trajectory. This raises another question of whether the beam might worth the sacrifice or not.

Now, this is interesting...having the AI unit target certain player units depending on that unit's role. I will definitely be looking into implementing this. It would be interesting to imagine how it would interact with a possible aggro system though. Perhaps bypass the aggro mechanic for this condition?
In this case, aggro is still the top priority, but when it's combined with certain rules like archetype or unit's particular criteria, the query might yield a slightly different result when the enemy picks a target. It might mess up a bit of targeting system but if you wanna make enemies look and feel smart, you gotta take a dip in.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-ai-design.124200/