Hey everyone! I thought I would try something a little more interesting this week and dive a bit deeper into how the AI systems in MAV work.
Before I start talking about how I ‘solved’ Ai in MAV, lets talk about what the actual requirements for the AI are.
There are 390 parts in MAV and with the most conservative estimates there are well over 100 MILLION ways to build a MAV. The AI has to be able to use them all as best as possible.
The levels in MAV are non-linear in nature. It would be impractical to mark them up with static waypoints or cover nodes. The AI has to work in any level type.
MAV is a team game, with teamwork winning over raw skill and firepower 90% of the time. The AI has to know how to work as a team.
And, most importantly, MAV is constantly changing. Part stats get tweaked, levels change, even tactics change mid battle. The AI has to be able to keep up!
Enter the modular AI design.
Why try to design an AI that can do everything? Instead, I broke the AI problem up into a logical separation of responsibility management. Each block on this chart is a fully autonomous AI system which communicates with the other systems. This allows the AI to make complicated, unscripted, choices, which do not have to be individually engineered.
More so, this allows the AI to be unpredictable. It will be very hard to ‘trap’ an AI into a set loop of events, as there are so many inputs driving the decisions that it’s almost impossible to maintain the inputs in a controllable way. All it takes is for 1 component to make a different choice and you get a completely different emergent behavior. It is in this way that the whole AI framework combines in a large scale pseudo neural net for final AI behavior. By having each node be autonomous as well, the neural net becomes self structuring as well! You can blow weapons off of an AI and the network will dynamically readjust to compensate for loosing the weighted input of those AI nodes!
Lets dig into the individual components and see how they work:
Team AI Module
The team AI system is responsible for gathering high level data from the game state and individual AI MAVs and directing them through an order system. It also evaluates the current set of game rules to help set order priorities. And finally, it provides the AI on a team a common blackboard system for sharing information discovered by the team members. The goal of the AI is to ‘cheat’ as little as possible, so this information sharing is the equivalent of the AI using voice chat to communicate and call out targets.
The Strategy System:
The Strategy system is how the Team AI can directly influence the overall team tactics. This system will evaluate a selected strategy against the current game state and issue orders into an order queue. It can also cancel already existing orders. There are currently 6 different types of orders; Attack, Defend, Flank, Guard, Search, and Reinforce. Each order can carry a position and specific target information as well.
The strategies themselves are modular, using a plugin type architecture. They can be very simple, such as only generating attack orders for a single target, or more complex, like evaluating each MAV on the team for capabilities and adjusting the order types on the fly to account for these capabilities.
The Game Info System:
This is a pure data gathering system. It takes into context the current game rules, the information posted to the AI blackboard, and digests it into a single prediction of how well the match is proceeding for the current team. This prediction is then used by several other internal systems.
The Strategy Evaluator:
This system is used to examine how well the current strategy system is doing at winning the game. By using the historical output of the Game Info system, it can determine a trend-line from the currently evaluating strategy. It will also poll additional information from the Game Info system to account for things like running out of time, secondary win conditions, and team strengths. It will then evaluate all this data against each possible strategy, assigning a rank based on predicted outcome, and if it is warranted, force the strategy system to switch the strategy it is using.
This is just a place for other AI systems to write information to so other systems within the same team can access it. Things like recently seen enemy positions, locations of deployables, and current positions are all shared through this system.
When you combine these modules together, you can start to see levels of teamwork emerging from the AI. They will space out uplink deployable systems to ensure the best range of coverage. They will protect each other when in battle and will start to fall back when the base is under attack. They can also use this system to distract an enemy, then ambush them with multiple team mates.
The Core MAV AI
While this might be the ‘Core’ MAV AI, it actually does some of the least work of all the systems! This system holds all the information about what the current MAV is. It will make simple evaluations to report it’s self as one of the 6 role types [Sniper, Engineer, Support, Scout, Attacker, Defender] and it will also select orders to complete from the Team AI. When I say ‘Select’ I truly mean that each individual AI has the autonomy to select the orders it wants to complete, based on it’s situation, vs having the Team AI dictate the orders to each AI. The MAV AI can also cancel an order it has accepted at any time, allowing another AI to pick up it’s task. This is very helpful when an AI finds it’s self in combat and determines that fighting is a better choice than the order it was following.
One other very important function of the Core AI is target selection. The core AI maintains a list of possible targets, their weight, and contains target decay logic. This ranked list of targets is used by all the child AI systems to select a target from. They are not limited to selecting the same target though!
The Movement Module
Now we are getting into the meat and potatoes of the AI. The movement module does exactly what it sounds like, it issues the move inputs to position the MAV in the manner it feels best given the current situation.
It makes this determination by factoring in the surrounding enemies, the current order type and position, the speed and turning ability of it’s own MAV, and the requested distance from the Turret AI module.
This AI system also integrates in with the path finding system and makes path requests and does terrain evaluations as it moves. This helps it prevent it’s self from falling off cliffs and taking fall damage. Because of the dynamic nature of the MAV levels, it also has to factor into dynamic obstacles like buildings, trees, and deployables as it’s navigating around.
Since this AI is tracking all the local surroundings, it will also update the Core AI system when it sees an enemy and what that enemy’s position was. This get farther relayed up to the Team AI system, but is processed at the Core AI level for evaluating threats and ranking the targets. And when I say ‘sees’ the enemy, I do mean that as much as possible. While the Movement AI does have a 360 degree field of view, it does have to have visual line of sight to a certain percentage of an enemy before it will consider that enemy seen. It’s also this system that allows the AI to dynamically take cover, by evaluating how much of it’s self an enemy can see!
The Turret Module
So we can take orders and move around, but in a game about combat, that is not going to be doing much! Enter the Turret AI, the fire control systems of the MAV AI system!
The turret AI is responsible for selecting the target that is in range and poses the biggest threat, then aiming at that target and firing! The target selection is fairly straight forward. The list of ranked targets from the core AI system provide a great starting point, but we want a better threat model for our target selection here. For this, the Turret AI will layer on the amount of damage a target has caused and the amount of time it took to receive that damage. With this, it ensures the AI will try and destroy enemies that are delivering a high amount of damage over the shortest time frames, as these prove to be the biggest immediate threats to the AI. This is very similar to ‘Agro’ from other AI systems.
But, it’s not as easy as point and pull the trigger. Each weapon in game has a different optimal aim point to ensure the greatest success at hitting. Because of this, the turret AI will select a primary weapon from all the weapons it has available. This will be a weapon that is currently ready to fire, has the best chance of hitting the target with the given situation, and does the most damage. Once the Turret AI has successfully aimed at a point that it feels can hit the target, it fires the primary weapon. It will then start to check other weapons for likeliness to hit the target and begin firing secondary weapons.
As it’s firing, it will do it’s best to counter the recoil generated. It is also responsible for recovering when the cockpit is hit by a high impact round.
While we have covered the fundamental systems that make up the MAV AI system, there are some micro modules that feed into both the Turret AI and the Movement AI systems.
Since each weapon can be so unique with how it fires and how to aim it, the weapon module provides a simple interface for getting the aimpoint for any possible weapon combination in the game. While it’s a very simple module, it is incredibly math heavy to account for accelerating projectiles, bullet drop, and target leading and prediction.
The Deployment and Auxiliary systems in MAV are very diverse. Because of this, the auxiliary systems themselves contain logic modules with if they can be used at any giving time. This data is fed into the AI system through the Turret Module which then makes the determination on if the deployment system should be used or not.
Wow, this turned out much longer than I thought! There are many other components of AI in MAV that are used to dynamically construct MAV’s as well, but that is a post for a different time.
I do hope that this post shows some insight into my AI design. Most AI in games is much more scripted, relying on behavior trees and detailed markup within the level environments themselves. My hope was to approach the problem of AI in a novel way that allowed them the most freedom and allowed them to play MAV more like a player would than at bot would. Of course, the highest compliment an AI designer can get is for players to mistake the AI for actual players! While I don’t think the AI in MAV is quite at that level, I do feel it is improving everyday and hope to extend the modular design of the current system to continue to add more functionality and tricks to the AI!
I would love to hear about AI designs you have seen in other games in the comments!
To end the post, I will leave you with a video of the AI surprising me in my own game!
Wow, as someone that’s been fascinated with AI since the days I tried my hand at scripting in Age of Empires 2 (albeit I’m an out-of-practice novice at best), this was a good read and quite an eye opening one at just how complex yet surprisingly understandable it all is.
Some of the tidbits here really explain some of the behaviors I often see, for instance it’s common to see Attacker and Scout AI charging toward you with their turret facing the exact wrong direction despite the entity clearly being aware of you; simply due to the fact that while the movement AI can see you and is moving toward you, the turret AI hasn’t selected you as a target since you’re beyond the range of their weapons.
An amazing and readable update. Thanks cyber. The part about teaching the AI ‘tricks’ was interesting. Oh the possibilities. Remember perfect dark ‘dark’ ai were virtually terminators. Id love to see some seriously tough ai for players to challenge themselves. E.g. Having them get extremely high accuracy and deadliness. Or doing cheeky stuff life lobbing canon, mg or rifles shots the way the normally wouldn’t
Or if the Insane AI difficulty cheated, kind of like how the AI throughout the Command & Conquer series their Brutal AI was identical to the Hard difficulty AI but with the key difference being that their harvesters brought in double the resources.
Say, if Insane difficulty MAVs had doubled durability and did 35% more damage. Kind of curious how that would play out.
Ai using weapon groups when?
Once the AI builder is smart enough to create the weapon groups in a reasonable way, I will switch the Turret AI module to using them.
Firing is the only thing in the game that the AI triggers manually and not through the same control interface as a human player.