AI Ticket System
The goal of this prototype was to create an AI who executes actions based on its surroundings, as a member of a team. The Ticket System seemed like the best approach for this type of objective. Using a ticket system I could easily set priority of tickets, set maximum number of each ticket type available, and decide who gets to take the ticket. The AI actors can also drop their current ticket for a higher priority one. This all makes for a more dynamic and responsive team playing AI.
The foundation of each class is written in C++, and used in Blueprints to complete the prototype. This helped speed up the process by not having to recompile and restart the editor all the time, while also providing the speed increase that comes with using functions and algorithms written in C++.
The Ticket System
The Ticket System is responsible for keeping track of which AI has priority on the individual tickets. This means that a ticket will go to the best suited AI. The best suited AI is, for example, the closest one to the target. The ticket system also keeps track of how many tickets of each type is allowed. This can be use to prohibit multiple AIs to have the same objective. The system will always try to push the highest priority ticket to the active AI.
The ticket system is set to auto-generate a selection of tickets at start. Other tickets are generated in runtime, for example when an actor gets below a certain percentage of health a "Heal" ticket will be generated.
The Scoring System
When an actor has an action it wants to execute, it generates a heat map of all tiles in range. This heat map scores tiles depending on a couple of factors:
Enemies responses to first action
Environmental features (cover, walls)
Proximity to target (objective, friendly, enemy)
If the move is offensive (scoring, attacking), or defensive (healing or hiding)
After the actor has picked its best scoring tile, it broadcasts its intention to all enemies. They can now react, either by shooting or by dodging. After each enemy announced its reactions, the active actor calculates its second action. It then runs its first action, waits for enemy reactions to execute, then runs its second action.
Code snippet from tile scoring system calculating Objective Score bonus.
The AI has a strict set of game rules to adhere to. I chose these rules to give the AI more depth, and to give them the need to think multiple steps ahead.
Each AI can execute two successive actions each activation, and can also react to other AI actions when they are themself NOT active. An activation executes in following order:
Active AI takes top priority ticket IF it is the best fit, OR calculates best action if not using ticket system.
Active AI generates a heat map from the given action.
Active AI declares its intention to enemies.
Enemy AI in line of sight of active AI can react to active AI action.
Active AI recalculates its second action according to enemy AI reactions.
Active AI executes action 1.
Enemy AI reacts to active AI.
Active AI executes action 2.
The goal of each team is to HOLD objectives (purple tiles) while denying enemies holding objectives by killing them.
1. Active actor calculates first action
Here the active actor grabs a ticket to score the objective. It then generates a heat map and sets a target tile, before broadcasts its intention to enemies.
2. Enemies decides on reaction
Enemies that have Line of Sight to the active actor decides how to react.
3. Active actor calculates second action
The active actor now decides on its second action based on its active ticket and enemy reactions.