Author Topic: Combat System #4: AI for Turn-based Combat Systems

HobGoblin42

  • Administrator
  • Wildland Warrior
  • 5
  • Joined
    Aug 03, 2016
    Posts
    275
    Location
    Munich
#1405 February 20, 2019, Wednesday, 12:55 am
When we started out working on the combat system we had a lot to do to lay the basic foundations. We had to get our character animation system running and implement stuff like combat logic, hexboard generation from level topology, or hexboard queries for paths and floodings at runtime.

That left little time to care about something as high level as AI (Artificial Intelligence). As a consequence our first prototype for AI ‘grew’ with time. At first, all it could do were melee attacks. Then we added ranged attacks. Then we implemented an enemy spell AI for intelligent placing of area spells (trying to maximize hits on enemies and minimize hits on allies). Finally we included rather specific routines (like fleeing) for characters that suffered from spells like fear. We realized that AI has to be able to deal with script spells that are loaded at runtime (a feature that could be interesting for future modifications). To allow for that we coded routines that simulate spell executions and judge their effects in a more general way.

Thus our prototype grew and grew until we were sure that we covered every capability that could possibly be required. Then we started to build it from scratch to make it more flexible and debugable. And now we feel like we can finally talk about AI.


Combat AI Debug Visualization in Realms Beyond

 The paradigm we had in mind for development has always been: What do we expect from a turn based AI?
Well, technically, we expect a lot! A demon wizard that fails to choose his fireball spell over a magic missile, or who fails to place the fireball in a way that maximizes damage on the player party is a no-go. An assassin who simply attacks her closest target instead of trying to stab your wizard in the back is not only little immersive – it also obliterates strategic bottlenecks like doors. And a human NPC ally that is not able to plan his path avoiding enemy attacks of opportunity is an annoyance. So when we talk about expectations from a ‘technical’ point of view, one can say that we expect ‘a lot’. A good (D&D 3.5 based) AI has to be able to perform a lot of intelligent choices for enemies that we expect to behave intelligent.

Assuming that we built an AI that is able to live up to those expectations, it is time to consider a different connotation: What do we expect from AI not in terms of quality but in terms of personality?
If every enemy behaved optimally the challenge would be maximized – and immersion would be gone. We want goblins to horde around their closest enemy. We want orcs to ignore attacks of opportunity. And an ogre might even be too stupid to leave an area that is affected by a damage-over-time spell. Even beyond ‘intelligence’ enemies should show personality in every decision that gameplay offers: While most races ignore unconscious or otherwise helpless enemies on the battle field and proceed to face those player characters that can still fight, certain foul creatures like goblins or gnolls should be known for finishing off their helpless foes. It’s those little twists that make combats immersive.

We hope that – apart from the challenge of making our AI capable of  ‘good’ decisions – we also do a good job to diversify enemy behaviours enough to allow you to detect patterns and become especially hateful of one enemy or the other.


A combat in 'Knights of the Chalice'

Once again, allow us to mention Knights of the Chalice here. It is owing to that game that we had a very precise idea about what we had to do when we first started prototyping our CPU-controlled opponents. The AI of KotC (and, of course, its excellent encounter design) made almost all combats interesting. It may be prone to crowd in bottlenecks (a fact can be exploited a lot once you get the stone wall spell) but hey – weaknesses are something you also expect from an AI to have fun, another fact that we are well aware of.

Hopefully, we can soon present you some more combat vids that display various AI behaviours. Until then, feel invited to tell us what you think about our ideas and what you consider important for a turn-based AI. And if you have a memorable story to tell about a combat against an especially cunning AI: please share it with us.
Goto Blog Post
Last edited: February 20, 2019, Wednesday, 01:14 pm by HobGoblin42

Lucumo

  • Town Guard
  • Gelatinous Cube
  • 3
  • Joined
    Oct 17, 2018
    Posts
    51
#1406 February 20, 2019, Wednesday, 11:41 am
Well...not much to think about since I pretty much share the same ideas. And as long as not all of a certain enemy type share the same "personality", it is all good. After all, not all ogres are equally dumb. Anyway, good job with the line of thought.

Woozy-Wizard

  • Member
  • Marsh Goblin
  • 2
  • Joined
    Nov 14, 2018
    Posts
    17
#1407 February 20, 2019, Wednesday, 12:59 pm
Excellent ideas!  Encounters with challenging AI using all available advantages and terrain/cover to the fullest is exactly what I was hoping for, because I plan do just that with my party.  Will random encounters be fought on randomly generated maps, or will there be a limited number of generic pre-generated maps used like in TOEE?  BTW, my evil aligned cleric could "Command" some of those undead to fight for my party, just saying.  :salute:

HobGoblin42

  • Administrator
  • Wildland Warrior
  • 5
  • Joined
    Aug 03, 2016
    Posts
    275
    Location
    Munich
#1408 February 20, 2019, Wednesday, 03:05 pm
Will random encounters be fought on randomly generated maps, or will there be a limited number of generic pre-generated maps used like in TOEE?

We don't have purely randomized maps but we combine different pre-edited parts to create individual encounter/wilderness maps that correspond to the environment of the world map.

Woozy-Wizard

  • Member
  • Marsh Goblin
  • 2
  • Joined
    Nov 14, 2018
    Posts
    17
#1410 February 20, 2019, Wednesday, 07:16 pm
We don't have purely randomized maps but we combine different pre-edited parts to create individual encounter/wilderness maps that correspond to the environment of the world map.

That souds similar to the tactical rpg "Battle Brothers", where each terrain has it's own unique features, but randomly placed to create a unique map every encounter.  It's just that fighting on the same maps everytime would get old very fast.  Thanks.

Claudius33

  • Town Guard
  • Beach Crab
  • 1
  • Joined
    Nov 16, 2018
    Posts
    9
#1411 February 20, 2019, Wednesday, 10:01 pm
Behaviour can be categorized indeed :

- Berserkers such as fearless orcs rushing to the closest enemy.
- Assault fighters rushing toward archers and spellcasters.
- Archers targetting first spell casters and enemy archers, aiming fighters if they run closer.
- Solid fighters such as dwarves staying in front of weak spellcasters to protect them.
- Cunning people such as humans/elves using cover and  stealth targetting the weakest  enemy, knowing when to use a bow, when to go melee, when to cast a spell.
- Tacticians trying to flank the party, targetting isolated enemy and spellcasters.
- Cowards seeking for cover first.
- Lone wolves in hide surprising the enemy when he comes close.
- Erratic dudes such as goblins randomly fighting, sometimes cleverly most of the time stupidly, ...

Not only it provides diversity but the player would have to adapt.

For the sake of curiosity does the engine take into account lines of sight (LOS)? For instance can a character hide behind a wall, so be unseen from enemy shooters or spell casters?
Do obstacles like rocks, trees, fences provide cover and/or cut of LOS)? How is stealth taken into account? What about choke points such as bridges and doors?
This would add to the tactical depth.

However  keep  in mind than a too well designed AI may deter several players. So an easy/normal/hard/insane option would be welcomed.

Though much less sophisticated than Jagged Alliance 2 or Silent Storm, I found Expeditions Vikings' TB combat engine well done. No magic (replaced by special capabilities) but interesting.

Pathfinder

  • Town Guard
  • Marsh Goblin
  • 2
  • Joined
    Nov 02, 2018
    Posts
    14
    Location
    Stolen Lands
#1412 February 21, 2019, Thursday, 06:45 am
What would be nice, but we most likely do not see (except maybe for scripted battles) is:

- Somekind of "learning" or "intelligence". Like if you try and fail to hit that tank in front of the party maybe you leave just one or few attacker (defender) there, go around / attack other targers? I do NOT mean that every single time fight start everyone start attacking party caster and ignore pretty much samekind of outfit using party monk (so please no cheating "we attack low AC target first, because "we know"  what target that is). But "We try to attack everyone and first we manage to hit.. ..hey that is good target for me" is OK and make total sense (instead of, I will keep attacking same target for all the fight totally ignoring the fact that I keep missing, everyone around me is dead and enemy stop fighting and player is lauhging and taking screenshots).

- "Feelings" like you have 2 lovers, brothers, family fighting against your party. When was last time when you notised that enemy stop his/her fight and rush to another side, try to proteck his/her retreat, give a healing potion / use healing magic or just go for berserk fury and try to kill person who killed his/her loved one / family member / best friend or so. (Naturally it helps if they shout / talk something instead of just use grunting, sweat, hits and blood a way to communicate)

That can allso be used for "more higher level tactics" even if that is to protect archer / healer / caster instead of just rushing all in toward first enemy instead of working as a group and protecting your own.

- Ability to have morale, not only based on spells (like fear) but how things are going in battlefield. Like if most around you are dying why not run if you are small goblinoid? Or if your party have managed to slay most of enemies surely rest of your party is inspired, even reckless and high spirited  no matter if some are badly beaten.

- Use enemy greed in advantage? True, it do not work most of the times but surely if you flee you can slow down some enemies just dropping meat / gold or what ever they care for.. ..heck it might even work during fight. Some enemies keep eating a dead horse / dog / any corpse atleast if they are hungry enough (and if pack of wolf choose to attack you they must be hungry) or loot the corpse / take items / money you drop at battlefield.

- Caltrops, wagons, natural or made up "cover", using trees and rocks to cover and attack behind them. Taunting your warrior and running away while rest of enemies try to shoot that warrior (if she/he choose to chace that nimble teaser). I can totally see some pixies using that kind of tactics.

Edit: actual "higher level" tactics would be kind of nice but would need scripting and ability to change map while you are at it (like logs/rocks you can make unstable and fall down at hill, a rope you can cut to make trap spring or bridge to collapse, dry weed, puddle of grease or oil you have created/put in land or web to burst in flames from torch/spell/fire arrow). Not to mention a change to change world map a bit (like forest fire...)
Last edited: February 21, 2019, Thursday, 07:00 am by Pathfinder
"Road to the man's heart go through the chest"

MadBeard

  • Town Guard
  • Beach Crab
  • 1
  • Joined
    Jan 11, 2019
    Posts
    7
#1413 February 21, 2019, Thursday, 06:26 pm
- Somekind of "learning" or "intelligence".

I was thinking something like in Red Hand of Doom adventure for 3.5ed. I'll put an excerpt from the book in spoiler tags just in case.

Sorry but you are not allowed to view spoiler contents.
I'd have to be a warrior, a slave I couldn't be.
A soldier and a conqueror, fighting to be free.

Pathfinder

  • Town Guard
  • Marsh Goblin
  • 2
  • Joined
    Nov 02, 2018
    Posts
    14
    Location
    Stolen Lands
#1414 February 21, 2019, Thursday, 09:01 pm
- Somekind of "learning" or "intelligence".

I was thinking something like in Red Hand of Doom adventure for 3.5ed. I'll put an excerpt from the book in spoiler tags just in case.

Sorry but you are not allowed to view spoiler contents.

I was thinking more of "during one fight" instead of "during scale of full game".

Naturally there should be (at some point) be somekind of reputation system, what I guess might be reason why high level party usually never encounter really low level enemies (you naturally do not get any XP from them and idea for level 15 PC paying "good money" for street kids just to gather rats at basement for him / her to kill for XP would be kind of fun idea but err..) but I guess if this game will be more like Baldur's Gate or Pathfinder Kingdom (you can choose where you go but you have only youself to blame if you encounter WAY too high level enemy) you will encounter sooner or later high level experienced enemies.

These enemies (if intelligent) should use multiple different styles in fight I guess. Something what fit for them best based on they background, items and so on. Do they use horses and try to avoid melee using just bows and riding circle around enemies? Maybe they sneak way behind waiting party to make camp then ambush party trying to poison food and attack at night when party is sleeping? There might be platforms build high at tree tops and only way to get there is to try and climb up.. ..not so easy job when enemies shoot at you all around. Naturally if they do have intelligence and they spot party first they surely use ambush and lay traps around, not just fallen tree across the road.

Allso when party have certain reputation it would make sense to meet sooner or later parties who are specific created against that (player) party. Who actually KNOW what abilities, skills and tactics players usually do and try to counter them. What players will do if fight start when they are relaxing after a fight, gathering loot for "normal encounter" (hired trash thugs from city nearby) and suddenly out of no where come: silence spell for caster, paralyze for monk, fear for tank and maybe blidness spell for party archer? Then start a real fight... <= these kind of things should be quite rare still. Something what are mean to iritate player and want to make revenge, get to know truth behind these hired forces (who want them dead and why).
Last edited: February 21, 2019, Thursday, 09:04 pm by Pathfinder
"Road to the man's heart go through the chest"

Archmage

  • Citizen
  • Beach Crab
  • 1
  • Joined
    Nov 16, 2018
    Posts
    7
#1420 February 23, 2019, Saturday, 12:22 am
Is Realms Beyond using multithreading, multiprocessing, hyper-threading?

HobGoblin42

  • Administrator
  • Wildland Warrior
  • 5
  • Joined
    Aug 03, 2016
    Posts
    275
    Location
    Munich
#1428 February 24, 2019, Sunday, 04:46 pm
Is Realms Beyond using multithreading, multiprocessing, hyper-threading?

We're using threads, but with a turn-based combat system, you can't really benefit from parallel computing except the AI evaluation process.

Outside combat, some NPC tasks are running in different threads (like pathfinding).

Dark_Ansem

  • Town Guard
  • Ogre Zombie
  • 4
  • Joined
    Oct 26, 2018
    Posts
    197
    Location
    World of Darkness
#1516 April 08, 2019, Monday, 04:35 pm
Is Realms Beyond using multithreading, multiprocessing, hyper-threading?

We're using threads, but with a turn-based combat system, you can't really benefit from parallel computing except the AI evaluation process.

Outside combat, some NPC tasks are running in different threads (like pathfinding).

Isn't it wonderful?
One who knows nothing can understand nothing.