The AI From Within - Part 3: Targets To Kill
Before we begin, there are a few announcements.
First: New rewards!
We've added three new reward tiers focusing on the revised Mercenary Mechanic. In a nutshell, this mechanic allows you to spend huge amounts of metal to warp randomly selected groups of hooligans-with-heavy-weapons straight to your Ark's system. You could spend huge amounts of metal on Mercenaries in Classic, too, but this is much cooler.
The reward tiers are Bronze Merc ($100), Silver Merc ($250), and Gold Merc ($350). Please check out the rewards sidebar and the big rewards image in the campaign itself for more details.
The paypal option for funding is now available. Sorry about the delay.
Back to your Regularly Scheduled Program
Last time in this series we looked at where an AI ship decides to go. Now we're going to discuss how ships (human and AI) decide to prioritize targets. With such large battles across so many systems, it's important for units on both sides to take reasonable shots even when they have no specific attack orders. The following takes a look at the logic we used in AIWC, and also notes some changes we are going to be making.
Without further ado, let's get it straight from the horse's mouth from my trusted assistant....(checks clipboard)... Anonymous Disposable Fighter #2044876-g!
So many targets. So little time.
Anonymous Disposable Fighter #2044876-g here.
Hi Mom! Check it out, you can see me, right there in the middle!
Oh, btw Keith, I’m still waiting on my personalized nameplate paperwork to clear through the system...
Okay, down to business:
A fighter, a bomber, and a missile corvette walk into a bar. I've got no orders, so who do I shoot first?
First, I'm only looking at ships on sides that are hostile to me. No friendly-fire for me. Nope, we've never had any bugs where the programmer accidentally told us to shoot everyone in the designated area. (Editor’s Note: Nor any followup bugs in The Last Federation where ships only shot their allies and not the enemy.)
Pick the targets...
Next, I go through each of those hostile ships and exclude ones I would simply never fire at:
- Is it out of range? If I'm a free-roaming defender or an AI threat ship I may not care, but otherwise I ignore stuff I can't get to.
- Is it already at zero health or flagged for removal from the game? The Dead Horse Protection Act of 3122 forbids me from firing upon them further.
- Can my shots not actually hit and damage the thing? My Anti-Quixote module kicks in there.
- Do I shoot missiles, and is my target covered by something that shoots down missiles (similar with other ammo types)? My predecessors in Classic had to deal with that, I'm really glad I don't have to.
- Is the thing cloaked? If so, I have to pretend I don't see it.
- Is my controlling AI Chivalric and is the target a irreplaceable non-combatant? Oh well, gotta live by the code and all that.
- Is the thing protected by some external provider of invincibility? (Keith's note: With Command Shield posts and Core Shield Generators gone this may be gone too, but it might still be on something)
Take their measurements...
For anything that passes those filters, I compute the following:
- How far away is it?
- How much damage would I actually do?
- Does it get the "WorkingIsReallyAnnoyingGravTurretIWantToGoKillRightNow" flag? Yes, that's the actual variable name in my code. If I'm caught by an artificial grav generator, and it's not under a shield, I really want to kill it.
- Does it get the Overkill flag? That is, is this unit already expected to die based on shots already fired at it? Also, if I have an insta-hit weapon I only consider other insta-hit shots aimed at it, and not slower projectiles.
- If I'm using focus fire, how many shots would it take me to kill this target?
Focus-fire is based on settings for player units because one of the programmers (Editor’s note: the right one) thinks maximizing enemy DPS-loss is the path to victory, and one of them (Editor’s note: the other one) thinks spreading the fire out is superior due to minimizing overkill. This gives us ships considerable amusement.
So, after those computations, I put the target it in my objects-to-kill-all list. Also, if it's currently in range I’ll put it in my objects-to-kill-in-range list (Keith’s note: This is a perfectly acceptable variable name, stop looking at me.). If my list of in-range targets is long enough, I’ll stick with those, otherwise I’ll use the larger kill-all list.
Line them up...
Either way, now I load my the target sorter algorithm which is based upon my ship type (examples: Normal, Prioritizes-Engine-Damage, Prioritizes-Paralysis-Damage, Reclamator, AOE), and apply that sorter to the relevant objects-to-kill list. I use this logic to guide my quicksort algorithm. Effectively, I evaluate each pair of unranked targets to determine which is higher or lower, then repeat until everything is ranked.
Here's the Normal sorter's list of rules. I start at the top and work my way down the list. When I find that one of the target pair is preferred based upon the current rule, I put that one higher in the ordered list, skip the rest of the rules, and then go on to start ordering the next pairing. So the later rules only get checked if I haven’t made a decision based on an earlier rule.
- If only one of the pair is a low-priority target, prefer the other.
- If only one is an Overkill target, prefer the other.
- If I have to get super-close, and one target has more attackers going after it, prefer the other.
- If only one is protected by a decoy that works on my shots, prefer the other.
- If only one is protected by a shield (other than its own), prefer the other.
- If only one is my current preferred target (set by the player), prefer it.
- If only one can reflect my attack, prefer the other.
- If I'm focus firing and one would take fewer shots to kill than the other, prefer it.
- If only one has the WorkingIsReallyAnnoyingGravTurretIWantToGoKillRightNow flag, prefer it.
- If one is 4x closer than the other, prefer it.
- If one would take 10x as much damage as the other, prefer it.
- If I have a coordinator and one is the target of my coordinator, prefer it. Generally only ships in Exogalactic Strikeforces have coordinators. They have all the real fun.
- If I'm not focus firing and one has 5+ more attackers targeting it than the other, prefer the other.
- If only one is immobile, prefer the other.
- If one is somewhat closer, prefer it.
And there's the sorted target list, so now I know what to kill! And knowing is half the ba-aaaahhhhh! (Cliche Electrocution Circuit shuts off audio-out channel)
(nameplate request cancelled, thank you for using Sirius Identification Services)
Ahem. Keith here again. So there you have it. Some of this is changing in the sequel, obviously, but you can see why we're looking forward to having squads of the smaller units so battles of 4,000 ships vs 4,000 ships don't lead to 4000 ships each sorting 4000-long target lists (if you're keeping score, that's theoretically 64,000,000,000 comparisons in the worst case, though even in classic we pared the work way down compared to that).
Either way, I'm looking forward to seeing some of you particularly devious modders work out your own target filters and sorters. To improve your own units performance, of course. You'd never assign an inferior one to the AI units. Of course not. (if you do, just rename the AI units "DumBot" and "BlunderBot", and we'll call it a fair trade)
We're coming up on the end of the campaign. Thanks again for all your support! It's been amazing.
There's several more parts of this series to go through, but this is probably the last one during the campaign itself. I still plan to continue the series in weeks to come, as it's entertaining to you (I hope), and helpful to us as we summarize the old and new designs. It's also good to lay some groundwork reading for potential modders.
So next up we've got a third combat video planned for Friday and then the campaign ends Monday. We might also have some updates over the weekend, if it seems appropriate. On the one hand we don't want to spam you (despite appearances), on the other there will be a lot of new eyes looking at the campaign during that time.
Have a nice day, and remember: robots are your friends!