Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Pages: [1] 2

Author Topic: What design paradigm does Starsector's AI follow?  (Read 6359 times)

heskey30

  • Commander
  • ***
  • Posts: 168
    • View Profile
What design paradigm does Starsector's AI follow?
« on: November 12, 2016, 01:24:58 PM »

I've always thought Starsector's AI was an example of really good AI, and I know its behavior is very complex and it has evolved over a long time. I'm very interested in game AI (I'm in school for Game design for better or for worse) So, its there in the subject - what is the AI in Starsector really? A state machine? A behavior tree? A set of if statements?

Also, if I may steal just a drop of precious time from Alex's schedule - do you regret your choice of AI paradigm now that you've had to deal with it for years? Or if not, do you have any tips to deal with its downsides?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #1 on: November 12, 2016, 09:42:06 PM »

First off, thanks for the kind words about the AI :)

To answer your question... well, pretty much all code is a state machine in some sense, right? But for any more reasonable definition, the ship AI is pretty much a huge collection of if statements and special cases.

There are several independent modules - controlling movement, weapons fire, shields, flux venting, ship systems, etc. These communicate with each other by setting flags in a shared object. For example, one module might say "do not back off", "hold fire", "do not generate flux", etc, and other modules are coded to generally respect that, unless they have an overwhelming reason not to. There's also a 2nd-tier module whose job it is to look at longer-term trends and force behaviors based on that if necessary. An example of that might be detecting that the ship has been trying to back off for a while, but is not having success doing so.

You might note that this setup doesn't lend itself well to "planning" - i.e. there's nothing that would make the AI decide, "I'm going to close in, fire off my torpedoes, and then back away". Behind the scenes, the code actually supports this sort of thing, but it generally doesn't work out in practice - combat situations are too fluid and a plan has to be constantly re-evaluated to see if it still makes any sense in the current tactical context. It's often easier to not have a plan in the first place.

One sort-of exception here is the AI controlling phase cloaking, where the AI decides to go on an attack run and unphase behind the enemy ship. It does this by setting a few flags in that shared object, with the movement module having some explicit support for handling the movements required.

Also, if I may steal just a drop of precious time from Alex's schedule - do you regret your choice of AI paradigm now that you've had to deal with it for years? Or if not, do you have any tips to deal with its downsides?

I'll go with "no, I don't regret it", mainly because the paradigm evolved along the way to fit what was necessary. The original design was more focused on plans - a sequence of maneuvers - which, as noted above, didn't work out. If I had to rewrite it from scratch, it'd be about the same thing but a bit cleaner and better-performing.

The main thing, I think, is to not worry about the code unless you need to worry about the code. What I mean is, 95% of the code in a game can be total spaghetti, and that's fine. It just needs to be modular enough that you can replace the pieces as needed. Not that I'd advocate writing bad code on purpose, rather just not tweaking code past the point where it works (which includes performance, etc).

I'm not sure the above is useful advice, since so much of that is feel and experience. I do remember, way back in the days before Starsector, being concerned about the "quality" of the code I was writing, getting the design just so, etc. And I can't even say that was entirely useless, since those things require some thinking about to understand. And then you have to forget about them most of the time.

Eh, that ended up being a bit of a tangent. To bring it back on point somewhat, I don't think the ship AI is held back at all by the way the AI code is structured. It's flexible enough that anything practical could be hacked-in on an as-needed basis.
Logged

Cycerin

  • Admiral
  • *****
  • Posts: 1665
  • beyond the infinite void
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #2 on: November 13, 2016, 06:37:20 AM »

Very interesting. Starsector's AI manages to feel more "human" than most games' AIs in a convincing manner, why would you say that is?
Logged

Sy

  • Admiral
  • *****
  • Posts: 1225
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #3 on: November 13, 2016, 07:08:25 AM »

Very interesting. Starsector's AI manages to feel more "human" than most games' AIs in a convincing manner, why would you say that is?
just from a player view, as someone who has very little coding knowledge, something that's always helped make the AI feel rather human to me is that it generally seems to act rather intelligently while still making some very human mistakes. for example, it's quite possible to overload an enemy with sudden burst damage against its shields. i'm guessing the AI has been actively 'taught' to make that mistake, to simulate a human-like reaction time.
Logged

Clockwork Owl

  • Admiral
  • *****
  • Posts: 790
    • View Profile
    • Starsector South Korean Community
Re: What design paradigm does Starsector's AI follow?
« Reply #4 on: November 13, 2016, 08:52:25 AM »

There are several independent modules - controlling movement, weapons fire, shields, flux venting, ship systems, etc. These communicate with each other by setting flags in a shared object. For example, one module might say "do not back off", "hold fire", "do not generate flux", etc, and other modules are coded to generally respect that, unless they have an overwhelming reason not to. There's also a 2nd-tier module whose job it is to look at longer-term trends and force behaviors based on that if necessary. An example of that might be detecting that the ship has been trying to back off for a while, but is not having success doing so.
So we got something like actual officers and captain in there. Interesting...
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #5 on: November 13, 2016, 09:43:46 AM »

Very interesting. Starsector's AI manages to feel more "human" than most games' AIs in a convincing manner, why would you say that is?

It's hard to say what that "human" means exactly, isn't it? In theory, players want that from an AI, but in reality an AI is held to different standards than a human opponent. For example, humans will make the kinds of mistakes that would not be forgiven in an AI, even if it made them rarely.

IMO, the goal for an AI is to 1) avoid as many screw-ups as possible, while 2) exhibiting the least amount of robot-like behavior (perfect reactions, etc). This isn't really going to produce a "human-like" opponent, but should produce one that feels more "human-like", if that makes sense - because it's got less rough edges to remind you that it's an AI.

As to why that might be case in Starsector (if it is - and, btw, thank you for the compliment), I think it follows that it'd be from a large amount of iteration to smooth away as many of those rough edges as possible.


A related issue is being aware of the AI while designing stuff like ship systems etc - they've got to be easy to use in a non-stupid way, and ideally with a higher skill ceiling to make them fun for the player as well. Basically, the skill floor for those has to be high, and if it isn't, it'd better be a very high-impact system pulling its weight, to warrant the extra AI work it'll generate.

An example of a complicated system from an AI perspective is burn drive, with its potential to get ships into trouble and the evaluation of that being very challenging. But, IMO it's such a cool and ship-line defining system that it's worth it.


just from a player view, as someone who has very little coding knowledge, something that's always helped make the AI feel rather human to me is that it generally seems to act rather intelligently while still making some very human mistakes. for example, it's quite possible to overload an enemy with sudden burst damage against its shields. i'm guessing the AI has been actively 'taught' to make that mistake, to simulate a human-like reaction time.

The way that works is the AI evaluates incoming fire every couple of frames instead of every frame - both for performance reasons, and to avoid being "perfect". This example is particularly interesting, because isn't getting overloaded making a mistake, and obvious mistakes in an AI aren't usually forgiven? But on the flip side, never getting overloaded is a great example of looking too robotic.


So we got something like actual officers and captain in there. Interesting...

Huh, that's really neat - never thought of it that way, but the similarities are almost uncanny.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #6 on: November 13, 2016, 09:55:21 PM »

This thread is awesome.  :)

One of my favorite things about Starsector's AI is that it is generally hard to "break" through stat changes or the addition of new weapons, even ones with roles outside of Starsector's vanilla weapons. When you play around with Starsector's data, its easy to take for granted that you can do things like give a hi-tech ship a ton of armor, and the AI will actually use that fact intelligently without any additional scripting. I think thats pretty rare in games today. In many cases, AI is coded the "lazy" way for specific use-cases or set-pieces, and there isn't any depth to it or a general use-case like in Starsector.

For instance, I changed how missiles operate and made them real burst damage dealers and the A.I picked up on the "damage potential" in each salvo and automatically adjusted attack patterns to capitalize on it when ships overloaded, stocked new missiles in cases where it couldn't effectively hit new targets, etc. Its honestly impressive to me that it just seems to casually adjust like that despite switching things around so much.

I'm not 100% sure what goes on under the hood and its cool to get a glimpse here, but all I know is the cases where scripting is required are the rare exceptions rather than the standard rule. The fringe cases where the AI is weakest get rarer each update and I for one love that.
Logged

Sy

  • Admiral
  • *****
  • Posts: 1225
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #7 on: November 14, 2016, 07:43:26 AM »

This example is particularly interesting, because isn't getting overloaded making a mistake, and obvious mistakes in an AI aren't usually forgiven? But on the flip side, never getting overloaded is a great example of looking too robotic.
i think it's less about "the AI mustn't make mistakes" than "the AI mustn't make mistakes that i wouldn't make". losing an allied ship because of something that wasn't your fault is always a bit frustrating, but (for me, at least) losing a ship every now and then isn't really a problem by itself. it might actually be a necessary part of big battles, since both the battles themselves and thinking about fleet composition and loadouts would become less interesting if i was never at risk of loosing anything anyway.

but it does become a 'problem' when i lose a ship to a situation that i feel wouldn't be threatening if i was piloting the ship myself, where i clearly see what the AI did wrong and what i could've easily done better. although sometimes this feeling might be due to missing something the AI had to deal with, because i only take a quick glance at what's going somewhere else in the heat of battle.

in situations where it's not about losing a ship myself, it's usually the AI being unable (or, seemingly, unwilling) to capitalize on a beneficial situation and push an obvious advantage. especially in 1v1 simulator tests, i frequently think "just attack now and take him out, goddamnit! why are you backing off? you're fine!".
but this seems to happen less, or less obviously, in large battles, so it's also more "annoyance" than "problem".


if a mistake of the AI helps to make it feel more like i'm fighting human-like enemies, and if seeing my own allies making that same mistakes doesn't make me think "i would've easily done better", then i'd say it's a very positive aspect of the AI overall.
« Last Edit: November 14, 2016, 07:48:48 AM by Sy »
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #8 on: November 14, 2016, 12:20:23 PM »

in situations where it's not about losing a ship myself, it's usually the AI being unable (or, seemingly, unwilling) to capitalize on a beneficial situation and push an obvious advantage. especially in 1v1 simulator tests, i frequently think "just attack now and take him out, goddamnit! why are you backing off? you're fine!".
but this seems to happen less, or less obviously, in large battles, so it's also more "annoyance" than "problem".

Yeah this seems to just be a 1v1 thing. I run into this with the A.I too and its usually only when I'm in the simulator trying out loadouts. For whatever reason the A.I often backs off immediately when a ship overloads 1v1.

I think its because it is trying to vent its flux to get ready for a renewed assault while its theoretical allies swoop in to capitalize on the vulnerable enemy, so it makes sense to do this in group engagements. You wouldn't typically notice this anyway, since 1v1 situations tend to be resolved through direct player control.
Logged

Midnight Kitsune

  • Admiral
  • *****
  • Posts: 2846
  • Your Friendly Forum Friend
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #9 on: November 14, 2016, 12:38:32 PM »

in situations where it's not about losing a ship myself, it's usually the AI being unable (or, seemingly, unwilling) to capitalize on a beneficial situation and push an obvious advantage. especially in 1v1 simulator tests, i frequently think "just attack now and take him out, goddamnit! why are you backing off? you're fine!".
but this seems to happen less, or less obviously, in large battles, so it's also more "annoyance" than "problem".

Yeah this seems to just be a 1v1 thing. I run into this with the A.I too and its usually only when I'm in the simulator trying out loadouts. For whatever reason the A.I often backs off immediately when a ship overloads 1v1.

I think its because it is trying to vent its flux to get ready for a renewed assault while its theoretical allies swoop in to capitalize on the vulnerable enemy, so it makes sense to do this in group engagements. You wouldn't typically notice this anyway, since 1v1 situations tend to be resolved through direct player control.
Yeah, I've noticed that the AI is better at its job when it has around the same amount of ships the enemy has. Well that an the fact that the AI seems to have ADD and can't concentrate on killing killing an enemy dead before switching targets. That is one reason why I either solo or use a small fleet of hardy ships
Logged
Help out MesoTroniK, a modder in need

2021 is 2020 won
2022 is 2020 too

Thaago

  • Global Moderator
  • Admiral
  • *****
  • Posts: 7174
  • Harpoon Affectionado
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #10 on: November 14, 2016, 01:28:15 PM »

This thread is awesome.  :)
...

Agreed! Thanks to both the heskey30 and Alex for the interesting reading! (You 'tricked' Alex into giving us an extra blogpost ;))

I occasionally dislike the caution the AI exhibits, but its a good thing. My own crazy maneuvers get me maimed or killed an embarrassingly large percentage of the time, and I would be filled with wroth should my AI allies do the same.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #11 on: November 15, 2016, 03:10:01 PM »

Spoiler
This thread is awesome.  :)

One of my favorite things about Starsector's AI is that it is generally hard to "break" through stat changes or the addition of new weapons, even ones with roles outside of Starsector's vanilla weapons. When you play around with Starsector's data, its easy to take for granted that you can do things like give a hi-tech ship a ton of armor, and the AI will actually use that fact intelligently without any additional scripting. I think thats pretty rare in games today. In many cases, AI is coded the "lazy" way for specific use-cases or set-pieces, and there isn't any depth to it or a general use-case like in Starsector.

For instance, I changed how missiles operate and made them real burst damage dealers and the A.I picked up on the "damage potential" in each salvo and automatically adjusted attack patterns to capitalize on it when ships overloaded, stocked new missiles in cases where it couldn't effectively hit new targets, etc. Its honestly impressive to me that it just seems to casually adjust like that despite switching things around so much.

I'm not 100% sure what goes on under the hood and its cool to get a glimpse here, but all I know is the cases where scripting is required are the rare exceptions rather than the standard rule. The fringe cases where the AI is weakest get rarer each update and I for one love that.
[close]

:D Happy to hear that's actually working well! I do try and keep the code as general-purpose as possible, though a few things to end up being hard-coded.

i think it's less about "the AI mustn't make mistakes" than "the AI mustn't make mistakes that i wouldn't make".

I see what you're saying, but there's an important difference here - when the AI makes a mistake, it will often repeatedly make the same mistake in the same circumstances. It might be the same sort of mistake that a human would make, but a human wouldn't keep making it. Well, one would hope not, anyway.

The point I'm trying to make is that a "mistake a human would make" stops being that when it's made repeatedly, and this considerably reduces the set of mistakes that might be forgiven.

So, not really anything counter to what you're saying, but perhaps a bit of a different way of looking at it :)
Logged

Megas

  • Admiral
  • *****
  • Posts: 12118
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #12 on: November 15, 2016, 04:00:54 PM »

Yeah, I've noticed that the AI is better at its job when it has around the same amount of ships the enemy has. Well that an the fact that the AI seems to have ADD and can't concentrate on killing killing an enemy dead before switching targets. That is one reason why I either solo or use a small fleet of hardy ships
I said this before, but this is a reason why I solo fleets.  When I cannot match the numbers the AI can have in the most rewarding battles (i.e., greater-than-simulator-sized extended battles) due to 25 ship limit, the most sensible option is to solo every non-pursuit battle with one overpowered ship.  If I deploy my ten elite combat ships against a hundred or even a few dozen enemy ships, I expect everyone except my ship get slaughtered, not unlike trying to kill Hegemony System Defense Fleets with 40 or less DP worth of ship in earlier versions.

AI works better when they match or have an advantage over the enemy.  Player will not have that much at endgame.
Logged

Kanil

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #13 on: November 16, 2016, 12:15:56 AM »

I really like how the AI deals with collisions. It's sort of novel to fly up behind a slower AI ship and watch it adjust heading a couple of degrees and get out of your way, instead of having to do that yourself. I also like how the AI will raise it's shields when a collision is unavoidable, and you just sorta bounce off one another and carry on.
Logged

Cycerin

  • Admiral
  • *****
  • Posts: 1665
  • beyond the infinite void
    • View Profile
Re: What design paradigm does Starsector's AI follow?
« Reply #14 on: November 16, 2016, 05:36:03 AM »

Yeah, the adaptability of the game's AI is part of why it feels intelligent and human in many ways. Most mods wouldn't be able to work nearly as well as they did if the AI wasn't as adaptable. One of my favorite things as a modder is when I have a new ship up and running and put it in the simulator, fully loaded out for the first time, to see how it acts and works. Some ships almost get a personality of their own.

BRDY as a whole deviates from vanilla enough that custom AI is needed in places (mostly to get ships to vent more often and under pressure) but even radically different ship systems can work with vanilla ship system AI.

A system that sucks in missiles and projectiles and turns it into a blast of damaging energy simply runs on vanilla phase cloak AI, with pretty satisfactory results!
Logged
Pages: [1] 2