Developer Blog #5: Artificial Intelligence and Tactical Combat
Over the past month we've been working hard on tactical combat as the second key part of Lord of Rigel we're planning on releasing as a demo. Tactical combat is one of the more challenging parts of Lord of Rigel to implement because it not only combines most of the systems in the game, but it also involves coding artificial intelligence.
As someone who plays games I expect two things out of the AI. It should first provide a fair and decent challenge. Second, it should provide a reasonable approximation of the behaviors that a human player may do. The first expectation is much easier than the second. One thing that we also realized is any scifi setting there tend to be unique cultural issues that should change the behavior of how different species approach combat.
So for LoR, the AI for tactical combat is adjusted for different species. The Katraxi will prioritize targets and treat issues such as when to retreat differently than the Humans. Whether the AI decides to try to flank ships, target the strongest or weakest shield facings, are all things that become different depending on the species. So this means that some species actually use non-optimal (i.e. not flanking and ganging up on one target) tactics when it fits their character. We felt this would go a long way in establishing that each species is different.
Coding wise our AI is done using something that we call “behavior trees” and each species uses a different behavior tree. This allows us to extend our base AI behavior and add custom behaviors to each species. What’s cool about the behavior trees is that it can pass any kind of behavior or value to the base AI resolver which is what executes AI behaviors. The AI can query ships by structural hits, armor strength, shield strength even by ship loadout and crew. What’s even better is that how the AI uses all of this information can bemodified externally using tables like .json files.For this example we’ll take a look at the Katraxi behavior tree. The Katraxi are an aggressive specie that focus on destroying the weakest ships on the battleground. The Katraxi behavior tree keeps track of all ships in a global list, and updates it every turn providing the best target for each ship. But originally this gave us few problems with targeting. For example, you could “kite” Katraxi ship by sending a lighter ship and luring all the Katraxi fleet to go after him , so we limited the search for the weakest ship in a certain radius. We’ll provide a flow chart for the Katraxi AI , without the behavior tree itself.
So the first step of this flow chart would be to pick a target, and this is essentially being done by the behavior tree. In this case, when the tactical combat loads up, the game recognizes Katraxi on the enemy side, it assigns the appropriate behavior tree for it and runs the query on the tree itself. This behavior tree would query the battleground by “WeakestShip” attribute , which encapsulates all the things like structural strength,shield and armor strength,drive and computer hit points, and returns the weakest ship out there, basically the ship it can blow up first.
Overall, behavior trees like this one lets us customize how different species approach the game. Which will add character to Lord of Rigel.