The AI From Within - Part 2: Places To Go
Keith here. Previously we looked at an overview of the different parts of The AI. Today we'll go into detail on the central piece of logic: the individual AI ship asking over and over again: "what shall I do?"
Look, there's an AI ship! (yoink)
Let's ask them: So, Mr. AI Ship, how do you decide?
(sounds of lasers firing)
(Keith’s Note: ship was reprogrammed to be more cooperative.)
Trying again, So, Mr. AI Ship, how do you decide?
Ship: Is that a herring sandwich? No? Oh. Anyway, about that priority logic…
Am I on a Mission?
First, do I have have a Galaxy-Wide-Chase Target? This is used for certain special ships and for ships in an Exogalactic Strikeforce.
This algorithm is very simple: Charge & Attack.
Charge: If I'm in the target's system, pursue it. If I'm not, find the shortest path to the target's system and move to the next system on that path.
Attack: There's no nuance here, no waiting for an advantage. If I'm in range of the target, I start shooting. Otherwise I shoot at whatever floats my boat, while I bumrush the target.
Death or glory!
If I don't have such a target, proceed to the next section...
Is there something important to smash?
Just inflicting casualties doesn't usually help much. Human players regenerate faster than trolls. So let's see if there's an irreplaceable human unit in the system worth pursuing.
Irreplaceables obviously include the Ark, but also Advanced Factories and other production facilities that the human can't rebuild if destroyed.
There are some caveats: if my controlling AI has the ChivalricAI trait, ignore non-combatant irreplaceables. Also, some irreplaceables are ignored unless the AI has local superiority in the system. Finally, if the irreplaceable can leave the system (e.g., a Golem) and I'm not in an AI-controlled system, look for a better, juicier target.
Next I have to consider shields. Humans are really sneaky and like to bury their irreplaceable units under piles and piles of shield generators. Then while you're uselessly hammering on the shield the human ships laugh at you and put "kick-me" signs on your back. So if I don't have many local friends I'll ignore something under a shield.
However! If I have a lot of friends in the system who are good against shields, and they're not too busy, it might just be worth a go. Specifically, if all those friends have enough firepower to knock down the shield in less than a minute, I'll ask them to crash the party.
In the happy circumstance that the human has one or more unshielded irreplaceables, I prefer the one with a higher assigned value. In case of a tie, prefer the one with a smaller nearby allied military presence.
But even if I found a good irreplaceable target, I need to take a broader look...
Is this crowd my kind of people?
Next I consider the local balance of power.
For one, are there enough enemies in this system for me to care? To win, my fellow exterminators and I have to press any available advantage or opening. It's not my goal to stick around to kill every last human unit in a system before moving on. Of course, if I'm a Guard ship I have to stay here until the humans antagonize me.
On the other hand, what if there are enemies? What if there are a LOT of enemies? To win, my fellow misanthropes and I generally need to amass a large enough group of Threat ships to overwhelm the human fleet and defenses. So if I'm in a hopeless fight, I'd do better to retreat and rally later with a larger group of friends. That said, the irritating programmer requires me to wait at least 30 seconds after entering a system to consider retreating (if my controlling AI has the Cowardly AI trait it's 5 seconds). I also stick at it if there are enough Threat ships in the galaxy to simply overrun the humans, because then it's time to solve this infestation problem.
One important caveat: if the human Ark is present, and not covered by shields, I never retreat. I go for it. BANZAI! This logic is a carry-over from happier days when the thing couldn't run away, so maybe you sneaky humans will exploit this somehow. If so the programmer will be receive angry binary messages until a logic update is provided (along with heated leather seats and powered windows!).
But what if things are as they should be, and my side has massive local superiority in the system? Then I need to decide if I'm really needed here or whether I can move on and leave the cleanup to others.
In that case I check how many of my friends are already planning to stay here (notably, any in a Threat Fleet or Special Forces Fleet). If these guys have more than 10 times the strength of the local human infestation, I’ll go look for another party while they clean up. You can thank RockyBst for this behavior. Thank you RockyBst!
So, where do I have lunch?
If the previous algorithm concluded that I’m not needed here, where do I go?
If I'm retreating, I just find an adjacent system where the humans don't have such a local advantage. If there are humans everywhere, I just pick a random adjacent system.
If I'm in a Threat Fleet or Special Forces Fleet, the decision's already been made by the fleet algorithm and I obey that. Orders are orders, after all. (Keith’s note: We’ll go into details on their decision making when we get to their part of this series).
Otherwise, if one of my home or core systems is under attack and needs my help, I’ll go there.
But if I'm just a normal Threat ship and there aren't any emergencies back home... well, now I'm getting into the meat of the algorithm. Except it isn't meat, because I'm not a meatbag. Like you.
First, I look at every system in the galaxy and determine the total desirability of all important human targets in that system. I also determine how much strength the humans have locally and in nearby fleets.
Second, I consider how eager I am to attack. If the human's mobile strength is largely engaged outside human territory, I’m much more likely to give it a try. On the other hand, if my controlling AI has the Cowardly AI trait, I’m a lot less eager.
Third, on each of those systems I deduct the local AI strength to arrive at a balance of power.
Fourth, starting with my current location, I work outwards calculating the difficulty of reaching and attacking each infested system. Further away systems are more difficult to reach due to the extra hops and any heavily human infested systems are further penalized. (It’s all the junk-food wrappers. Could you guys clean up after yourselves?)
Fifth , I sort these systems by difficulty categories and the juiciness of the irreplaceable targets present.
Then I look at the first system in the list. If the Ark is there, that's where I go. Otherwise, I have a 2/3rds chance of picking it anyway. Otherwise, I check the next system in the list and so forth.
What to do when you're the only one on time
Life as a Threat ship is frustrating. Sometimes you get a juicy undefended target and it's just great. But most of the time those annoying meatbags block the way with all kinds of nasty, pointy defenses. So even if you have a destination system, it's often not the greatest idea to just waltz in the front door as soon as you get there.
If I’m about to enter a system where the humans have local superiority, I’ll generally wait some distance away from the wormhole. In the meantime, others may attack that system or join the siege. Once the balance of power has tipped in my favor... It’s party time!
Furthermore, if there's an Exogalactic Strikeforce just about to hit the target system, I'll also consider their strength. Generally, as a team player, I’ll try to kick down the door for them and take the hit so the Exo retains enough strength to accomplish its mission. Unlike selfish humans, I’ll willingly throw myself under the bus for the greater good. No resentment here! No worries over dashed hopes and dreams!
On the other hand, if I’ve been waiting five minutes or so, I'll give up on the waiting and go join a Threat Fleet. It's like joining an interstellar motorcycle gang, only with more explosions. (Keith’s note: We’ll go into details on their decision making when we get to their part of this series)
Proper etiquette when exterminating player units
All that routing aside: If I am where I need to be, and there's a fight, I now have to decide what unit to go after. The earlier questions about irreplaceables are important but not always decisive.
If I'm one of the most deadly AI ship types, I may have the special Bullheaded targeting algorithm. This gives me very simple and effective priorities on what key control and defense structures I need to kill, because I've got the strength to get the job done myself.
But normally, if there's an eligible irreplaceable to go after, and this is not an AI-controlled system, I have to decide whether to join a full court press to take it out. If my side has overwhelming local superiority in the system, or there's so many Threat ships in the galaxy that they can just swarm the humans, I'll go for it.
Otherwise, I just need to find some appropriate human unit to maim.
So I look at all the enemy units in the system. Some I will disregard because I can't effectively hurt them. I then sort the remaining ships by my targeting preferences (I’ve always hated the green ones the most) and pick one of those to pursue.
The preference algorithm is amazingly complex and delicate code, the best really. Let me start by... (Keith’s note: Blah blah blah. Moving right along). Fine. So I shoot the green ones.
… or I calculate the optimal impact efficiency of my siege-plasma torpedo relative to the..
Keith’s note: As you were saying, the green ones...
Fine. So I shoot the green ones. <Insert remarks concerning Keith’s ancestry>.
(Ship mysteriously explodes)
I hope you enjoyed those, er, insights. My next post will probably be on the lore (meant to post that today, but it's not ready). Next time in this series we'll go into the target preference algorithm. This one's very important because it's also used for any situations where any ship's weapon (human or AI) needs to decide which target to shoot at. One of the greatest things about AIW classic is how you can generally trust your fleets to pick targets well, and getting them to do so ain't easy.