Most players are quite likely not aware of the complexity of the Artificial Intelligence working behind the scenes in our RPG series.
This is not really surprising.
I’ve been discussing this topic with some of my friends who happen to be seasoned nerds (uhm, I mean IT engineers), and most of them underestimated the complexity entirely (including myself even quite some time after I’ve started to work on our first title Sw&Ear).
The battlefield size, the respawn / barracks system, and mainly the skill system with over 60 skills lead to a number of possible moves per turn which is way beyond those of a chess game.
This is a statement you probably have to chew on first (at least I had to once I realized this).
So is writing the AI for a game like Kingturn more difficult than writing a chess AI?
Fortunately not, because there is one substantial advantage over chess.
It is much easier to evaluate right away whether a resulting position / outcome is good or not.
That’s why it is (almost) pointless to calculate several moves / turns in advance (which is mandatory for a good chess AI).
That said, we had (and have) to deal with a couple of other problems, though:
- Computer chess AI has been researched for many years by quite a lot of people. This is obviously not the case for an RPG AI, since every game has its own set of rules.
- The limited cpu speed and available memory on mobile phones (this becomes less of an issue for sure, but it is still nothing to be ignored entirely)
- The battery life (the more calculations are done, the higher the battery drainage)
- A unit move should be done almost instantly
For a PC version I would quite likely have gone down the road of a simulation approach: Calculate all (or most) possible moves and take the one with the best outcome.
Due to the formerly mentioned constraints, I decided to take a different approach for Sw&Ear / Knighturn / Kingturn, though.
Our AI system is based on several heuristics with an enhanced aggro system as the most fundamental one:
Each attack or skill usage adds a certain amount of aggro to the performing unit. E.g. the higher the previously done damage, the higher the aggro. Additional aggro is granted if a unit has very low HP, in order to make it a primary target.
Furthermore, the closer a unit comes to enemy barracks, the more aggro is applied to it.
The aggro of a player unit that occupies an enemy base is sky rocketing, for example.
Player units with the highest aggro will be dealt with first, provided they are within move + attack range of a game controlled unit.
There are plenty of others heuristics that deal with more complex decisions like using the right skill (e.g. single target or multiple targets) or chosing the right position for an attack.
(Maybe) surprisingly, the most difficult decision is whether it is a good idea to position a unit on top of the own base in order to guard it.
This decision depends on various circumstances: Remaining number of spawns, opportunity to block an opponent’s path, or the chance of defeating an opponent that could take over the own base otherwise.
The last mentioned decision / heuristics has been probably the weakest spot of our previous titles Sw&Ear and Knighturn.
So we’ve been working hard to improve the AI of Kingturn especially in this regard.
May the opponents in Kingturn beat the hell out of you …
Enjoy our games!
Added note:
I should probably explain how the term ‘heuristics’ is used in an IT context.
This basically means that a perfect solution is sacrificed for the benefit of far less required calculations. How close you come with this approach to a ‘perfect solution’ mainly depends on the quality of the involved estimations and assumptions.
Heuristics are commonly used for path finding calculations, by the way (A-Star algorithm).