AI War 2:AI Mechanisms

From Arcen Wiki
Jump to navigation Jump to search

The Original AI War

The AI for the original AI War was described in a series of articles that wound up making the front page of reddit, hacker news, slashdot, and various other sites back in 2009. It was an entirely novel approach to AI in strategy games, and basically the most immediately distinctive thing in the game. Heck, it's even right there in the title!

Hey, That Evolved!

What is less apparent is that the AI in the first AI War was continually revised and expanded after those articles were written. AI War Classic was in active post-launch development on and off through 2014, and Keith LaMothe in particular added a variety of other kinds of AIs on top of what Chris McElligott Park originally wrote about.

A lot of what was added was more "traditional AI" that used things like decision trees to augment the emergent flocking behaviors.

Other pieces that were added were... kind of a hybrid of approaches. These were things added by both Chris and Keith to say something like "override the general flocking behavior in these specific conditions" to make things more intelligent. We also added in various rules like "if you're a single ship going to attack a planet, don't go in unless there are buddies there with you that would make your death meaningful, or even make you win."

This sort of "wait at the wormhole to a planet before attacking" was something you could easily notice, and you'd have a "threat meter" in the galaxy showing how many ships were doing that sort of thing. When Chris wrote the original articles about the emergent AI, none of this existed yet. But these bits were actually just adding more layers of emergence, based on more inputs and more decisions that could happen based on those inputs (an input here being the recognition that "I shouldn't go in alone."

Ultimately, however, there was a wall that was hit where the AI just couldn't get any better. So when it came time to design the sequel's AI structure, Keith and Chris had some very specific ideas and goals. And then Badger came along and added some huge other layers on top of that.

Structurally Speaking about AI War 2


As with the first AI War, a lot of the "higher level thinking" (aka what we'd call "consciousness") needs to happen on background threads so that they can think about things for "a long time" (aka a few seconds at a time). Unlike the first game, there isn't just a single background thread that runs the consciousness for all the AIs, however. There are now any number of background threads, one per type of faction-that-is-not-a-human-player, in fact, and many of them run at the same time. If you have multiple instances of the same type of faction (aka multiple AIs), then there's still only one thread for them all, but it runs one thread for one, then one for the next, etc.

Unlike the first game, however, the other factions are not an afterthought. Having any factions other than "the AIs" and "the humans" was not in the original design for AI War Classic, and was not added until the first or second expansion. It was always a bit hacky to get them in there, and they couldn't really have the same degree of sophistication that the AIs themselves did. In this sequel, some of the secondary factions are substantially more complicated and advanced than the main AIs themselves, and there's no real bound on how many of them there can be. All the various factions can use entirely different styles of AI coding, and many of them do, which leads to them feeling extremely distinct from one another. It has given both us as developers and modders a lot of room to experiment with different styles of AI programming and pit them against one another or against the player or both.

The Subconscious

A lot of other bits take place as part of the simulation, still, though, so that we have the "subconscious" fast reactions to stimuli. These sort of subconscious decisions get about 100ms, at the absolute most, to do all their calculations. This is compared to roughly 50ms in the first game.

But actually, that's an exaggeration in both cases. That's how much time there is for ALL the calculations (and draw logic) per sim cycle in both games (though draw logic is on a different thread from any sim logic in AI War 2), so the subconscious could never really take that long to think about things. In reality, probably they need to take something more like 15ms in the first game, and 30ms in the second game, max, in order to actually keep the simulation running at full speed.

Subconscious logic is SUPER important, and often plays into things like "who do I shoot who is near me right now?" This sort of logic is actually incredibly complicated, and one of the most expensive things for us to calculate in terms of ship logic in both games. This is something that has to be calculated for every faction, including for the human players' own ships. If you move one of your ships near an enemy, you expect them to start shooting very rapidly. And you also expect them to shoot the ideal target if there are many possible targets within a short area.

In order to solve what is kind of an impossible problem, we actually have some MORE background threads in AI War 2 that do a lot of precalculations in a rolling fashion, and which tells us things like "what targets are most attractive that are in range or kinda-sorta-near-being-in-range." And it then keeps those scored target lists for a few seconds or even just part of a second before discarding them and getting a new one.

This then lets the subconscious skip a lot of the most expensive stuff to calculate, and it just bases its own logic on the scored lists that it already has. This keeps the simulation humming along, and after a heck of a lot of work and rework, it almost never leads to delays in targeting that a player would notice.

This makes the primary job of the subconscious to carry out orders it already has, and to actually do things like fire weapons or move through space or wormholes, etc. Even things like "decollision logic" to have ships not bunch up on top of one another has been moved to a background thread, which instructs the subconscious periodically. The decollision logic is the number two most expensive part of the "subconscious logic" in both games, so moving this out of the main simulation thread was a big win for performance and the ability to scale things. It's definitely possible to notice a delay before things decollide in the sequel, though, compared to the first game -- but the simulation speed never drops like it did in the first game.

The Components of "The AI" Faction In AI War 2

Q from dEAdOnE77: I remember reading an article from ChrisPark about the different AI´s in AIWar1, which had 2 parts:

  • The GrandStategeyAI, who moved Units in the Galaxy map;
  • and each Ship had its own AI for target selecting, moving and fleeing;
  • and they could overlap or interfere, which resulted in emergent properties/behavior.

So now that we have Fireteams in AIWAR2, i was wondering how all these AI´s in AIWAR2 work

A from Chris: It is... much more complicated.

For one thing, there is no longer a single "consciousness" just even for a single AI faction, anyhow. They now have four distinct groups:

AI Sentinels

These guys are most like what was in the original game, and are basically "ships that are defending, and/or reacting to some sort of recent incursion you made, and/or attacking you after popping out of a wave attack."

These guys mostly work like the first game. They don't use fireteams at all.

They're very... primal. As with the first game, they're excellent at using surprising flocking tactics and doing all sorts of unexpected things. But they also lack certain higher-order intelligence.

HOWEVER, there is a higher-level intelligence -- along the lines of the Grand Strategy AI from the first game -- that is directing where they get waves, where they get reinforcements, and so on. But it's constrained based on some rules as to what information it's allowed to use/know about you and your activities.

AI Warden

This is kind of an evolution of the Special Forces group of units from the first game. The main difference is that in the first game, the Special Forces were allowed to work on offense or defense, and they mostly used the swarm-style intelligence but with some extra rules that would cause them to do things like bunch up at wormholes and wait to attack in a group, etc.

In the sequel, these guys are technically their own sub-faction. They have their own distinct budgets and AI rulesets, and sometimes they donate to the main sentinels faction or vice-versa. They are also not allowed to pass through planets owned by human players in almost all circumstances. So these folks are now fully defense-oriented.

They do use fireteams to coordinate, and this has become part of their consciousness that their subconscious has no idea about. Prior to fireteams, there was one "warden fleet" for the faction, and it would act as a group and move around doing whatever it wanted to do. It was not really using that much emergent logic, and was more traditional in its AI coding style. Decision trees, etc. Now that there are fireteams in place, each fireteam works in that fashion... but the combination of many fireteams working together often has emergent properties. So it kind of moved back toward the middle.

Fireteams were one of the major inventions of Badger, it's worth noting. But he's also had an enormous hand in refining basically every aspect of the consciousness of all the factions. Keith built the original framework and logic for that, and then Chris has been focused most on the subconscious and its related functions.

AI Hunter Fleet

This is kind of an evolution of something called the "threatfleet" in the first AI War, which evolved over time out of Keith's continual improvements in that game to make "loose ships" (aka threat) act as intelligently as possible. In the first game, threatfleet ships came from few sources:

  • Ships that were part of a battle but then ran away from it.
  • Ships that got freed from "guard duty" but that the player didn't kill (maybe because the player lost that battle).
  • Ships that were part of a wave against the player, but which either fled from the wave's battle or won the wave's battle, and now need something new to do.

I think that was about it. At any rate, these were some of the most interesting parts of the AI in the first game, especially as the AI continued to evolve. So in the second game, we built on this concept and expanded it far further.

The source of ships for the hunter fleet in the second game is mostly the same as in the first, although they also start with some ships now, and they get a bit of budget to buy ships directly. But mostly they get donations from the sentinels after a retreat or a victory.

The hunter fleet has then been massively upgraded to use fireteams, however, and it has a lot of expanded logic for explicitly looking for weaknesses in player defenses and then striking from multiple angles. It also has notable amounts of logic for hiding several hops away from its intended targets, specifically so that it will go unnoticed by players until it is too late. It's hard to see the buildup of the hunter fleet and know exactly where they are headed, especially on more open map topographies.

It's also worth noting that, because Badger felt rather constrained by the core design of the hunter fleet, he later came back and designed the Scourge, which were basically his vision of how the hunter fleet could be if they were really super duper excellent at hunting you and making your life miserable. The power and ferocity of the scourge are really something to behold, and a great example of why it's nice that we can have more arbitrary factions that can use any number of AI design and coding styles. The scourge would probably be inappropriately hard for a "base faction" that is always there, so it's a great balance to have them as a separate faction you can turn on, instead.

One other thing that's worth noting about the hunter fleet in this game is that, like the first game, they don't give a flip about defense. Feel free to kill the AI Overlord for all they care—all they see is a potential opening to kill your stuff in return. These guys are pure aggression, with no regard to self preservation. If the warden and sentinels can't hold the line on defense on their own, then that's just too bad. These guys are busy being velociraptors.

AI Praetorian Guard

This was a very late addition to AI War 2, and is another sub-faction of the AI. It was something that Badger added after he and Chris were talking about some of the player and AI behaviors they were seeing and how some of it was a bit suboptimal.

Essentially, the warden is great at defense, but it's a very... forward sort of defense. The warden intentionally spends most of its time near the AI's borders with you, preparing to come to the aid of AI planets that you might attack. It's not really concerned with deep strikes against the AI unless it sees you actually doing that—in which case it follows, and intercepts.

What we had observed was that players would often try to draw the warden very far away from the AI Overlords with one group, and then they'd attack the much-more-exposed Overlord while the warden was off dealing with the fake threat. This was very clever on the part of players, but it exposed a hole in the part of the warden AI: it needed to also be able to prioritize defending the overlord. But... that's very contradictory with its goal of defending the front lines.

What we quickly realized was that we needed to define a new goal and let the two groups each run their own distinct logic. So the Praetorian Guard was born in order to "play goalie" while the warden "plays midfield" if we're going to use a soccer/football metaphor. And yes, the PG uses fireteams.

The praetorian guard is another sub-faction that doesn't really get much budget directly, and so is dependent on donations from the sentinels or even the warden.

How The Consciousness Ties In

The Praetorian Guard not having much budget of its own is a great example of where the overall higher AI consciousness comes in.

First of all, the main AI Sentinels logic has a lot of parts where it allocates budget income to its budget items, and those build up. These are things like waves, planet reinforcements, cross planet attacks, warden, reconquest waves, hunter fleet, praetorean guard, and wormhole invasions. Some of these things are actually sub-factions, and others are not.

Depending on the situation, it can shift modes substantially to fund things differently -- such as when its Overlord is threatened, it vastly steps up how much is given to the praetorean guard and completely cuts off new funding to reconquest and wormhole invasions.

Most of the rest of the time it lets the sub-factions live with whatever budget they get, and so if the humans whittle down the hunter fleet to next to nothing, the AI won't suddenly give a surge of income to the hunters. That might be interesting as an enhancement in the future, but honestly that could both be an exploit for players to use, as well as something that makes things less fun: having all your hard work of killing the hunters be immediately overturned isn't something that would feel good, and the fact that it's pulling budget from elsewhere wouldn't really be visible to you as a player.

At any rate, there are finite caps on how much budget can go to each of the categories that are mentioned, and so if the AI realizes that they have completely stocked up on all the pratorean guard that they could possible want for now -- very likely if you've not approached their homeworld and the game has been going on for a long while -- then it will donate the budget that would have gone to the PG to other purposes based on what is NOT at cap. So at that point, the hunter and warden fleets would probably rebound relatively quicker, for instance.

Circling back to the sub-AIs:

From a combat-decision-making standpoint, it is far simpler and more effective to have single-purpose sub-AIs that have very distinct goals that they can focus on: front-line defense, offense, and deep-goalie-style-defense. There can be a lot of nuance and strategy in how to achieve those goals, but those sub-factions work with whatever they have on hand. They're not concerned with generating more income, or "I could do this if I just had X more ships." Work with what you have.

From the grand-strategic sense, the overall AI consciousness looks at that forest instead of the trees. It doesn't try to intelligently allocate based on past losses (as that would probably backfire in terms of the actual fun factor), but it does allocate differently based on certain specific situations that might come up (overlord threatened, etc), and it also allocates differently when something is over-funded. The overall end effect is that you can feel the impact of smashing part of the AI, and it doesn't instantly rebound; but at the same time it will naturally heal based on budget caps, eventually, which is a good middle-ground.