Realms Beyond – A classic turn-based fantasy RPG

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

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 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.

Comments in the forum