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

Consciousness

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