Tactical Combat AI Mod

A place for discussion of making game modifications.
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

Thanks a bunch! I figured there were probably a bunch of things that I overlooked, I'm glad to have someone bring them to my attention.
zolobolo wrote: - All interceptors are launched on a single missile pack (would be better to maximize their deployment to a single squadron per missile salvo is possible)
Aha right. I added a system to let the AI keep track of missiles that are assigned to targets, but other than that all weapons are handled individually. So every interceptor squadron is completely unaware of what the others are doing. I will address this.
zolobolo wrote: - Interceptors do not engage enemy ships even if enemy fleet has fired all their PD weapons in the previous turn (it would be great if they would engage if in direct range and enemy PD capacity is at least 50% depleted)
Sounds like a good thing to do. It's a bit more situational so will probably go a bit lower on the TODO list, but I intend to try it out. Depending on the size of the fleets involved 50% PD may still be pretty dangerous to fightercraft, so I'm hoping I'll figure out a better criterion.
zolobolo wrote: - Strike Fighters seems to behave as interceptors. As they are a mix of the two they would benefit from a combined behaviour
Huh, I haven't got around to testing strike fighters yet but I was expecting based on what I have coded that they would have a combined behaviour. But now that you mention it, when evaluating their priorities, their priority as a bomber is reduced when the threatening targets are far away, but their priority as an interceptor is not affected by distance. I think changing the carrier engagement range (as you mentioned) will help, but I'll see if I can factor distance into the interceptor priorities - it will probably help keep them alive if they go for closer missiles or even potentially wait a turn until the missiles get closer.
zolobolo wrote: - Enemy ships select their target based on target threat level - seems to be working nicely but needs more testing with all the various special scenarios
There's only so much testing I can do on my own, again, thank you for sharing some of your time.
zolobolo wrote: - Raiding is not utilized anywhere else due to the per-requirement of engines needing to be disabled (which almost never happens) and the AI avoiding utilization of boarding module (this is due to the vanilla code)
Yeah, ships usually die before taking major systems damage in vanilla. There is a mod that tweaks combat damage so that ships are more likely to be crippled/disabled in combat, not to shamelessly plug my own work... :lol:
zolobolo wrote: - Assault Shuttles do not utilize raiding even if enemy crew is larger. They should probably be effected by the mod, but Assault Shuttles currently seem to be prevented by a bug of sorts from being utilized as it has been mentioned that they should work
Haven't tested the assault shuttles yet, or even looked at what code they use. I was hoping they would automatically pick up on the boarding changes. I intend to work on this.
zolobolo wrote: Also noticed though that the carrier was holding its starting position, and not closing to enemy vessels. This made the small crafts less effective due to the amount of turns it takes for them to get to the target and back, and vulnerable to other guns outside of automated PD counter - would make sense to bring carriers close enough so that their squadrons can unload their payload in a single turn
For some reason when I started out I thought it would be good to keep the carriers a little further back, but you're right they probably are more effective up close. Another reason why a second opinion really helps.
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

Update:
  • Carriers now try to move in closer, and targets that are within 1 turn range are treated with much higher priority for fighters/bombers.
  • Missiles that are already targeted by interceptors have reduced priority when choosing targets for the next weapon or interceptor (haven't really tested this yet, sorry).
  • Interceptors/strike fighters treat missiles/bombers that are farther away with lower priority.
  • Major tweaks to the priority calculation used when targeting fightercraft with weapons. Fightercraft now have an inherent priority that reflects the fact that unlike missiles, destroying a fightercraft is like destroying a weapon system, it reduces the offensive capability of the opposing fleet. This priority is calculated much like that of ships, in order to ensure they are mutually comparable. It's based on the damage dealt by the fighter/bomber group vs it's health.
  • Shield regeneration now matters more when considering how vulnerable a potential target is.
  • Now any non-PD weapon that can target missiles/bombers may choose to do so.
Didn't test the strike fighters, but the carriers moving in closer and the changes to priority should encourage them to attack ships more. Fighters and bombers are now treated with much higher priority than before though, so expect the strike fighters to act like interceptors if any of those are around. It makes sense, since craft are much more vulnerable than shielded/armoured ships, and killing them is like destroying ship weapons. From what I was able to test, the AI seems to handle interceptors much more intelligently now, so that's nice.

Still on the TODO list: having the AI take enemy PD into consideration, assault shuttles.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

- Carrier now moves into range
- Strike Fighters are deployed in Turn 1 - Might want to prevent scrambling of small crafts in turn 1 for player 1, as this exposes them to the maximum amount of anti-craft power (PD and other) + exploit of moving PD elements in the front. There might be an exception to this rule when considering the second player's turn 1 as it might make sense to scramble fighters against torpedoes, missiles or bombers (if first turn was made by a player as AI would not send out anything at turn one at this point). Thus would this make sense?: At turn 1 for Player 1 (making initial move), do not scramble small crafts against vessels. Scrambling against other small crafts, missiles and torpedoes would thus be allowed even at turn 1 for player 2
- Prioritization: Attacking fleet ignores fleet carrier once all 3 of its squadrons have been eliminated and goes straight for planetary defenses before returning to the carrier to finish it off - this seems a great result as it minimizes exposure towards planetary defenses fire
- Prioritization: Strike Fighters will attack vessel out of range, while PD heavy vessels are in range and softer targets. Not sure if this is a bad thing, but will reduce carrier effectiveness in the long run.
- Non-PD weapons target small crafts: works like a charm
- PD seems to be reserved for a while if I reserve my Strike Fighters and still have missiles - this has lead to a great event where I launched bombers against a group of destroyers in short range and they outright annihilated all 2 squadrons :)
- Interceptors and Strike Fighters of attacking fleet are not deployed, if fortress is defending planet: this is probably due to its PD capacity.
- Interceptors are not deployed against bombers
- Bomber squadrons have attacked different ships in numerous occasions which is great as it makes the enemy more unpredictable and focused PD fire will not work that well anymore - great work! :)
- Fleet movement: in one occasions the attacking fleet of 3 destroyers, Military Transport and Fleet Carrier did not close on two enemy fortresses for around 20 Turns. Neither side had missiles left at that point, but the carrier did have an interceptor squadron reserved: they probably were not willing to go into close range due to having the interceptors but were also not willing to send it out to a suicide run. They did eventually close in to the base after a while though... See picture below on the stalemate phase

On the side note: the Military Transport did move to Raid one of the Fortresses once so your rule does apply to Assault Shuttles (they consider bases to have disabled engines and the vanilla mechanic generally seem to work against bases because of this)

AI is the most difficult part to do for a strategy game, so naturally there are a lot of things to consider - Thanks a lot for your efforts :)
Attachments
No move.png
No move.png (1.17 MiB) Viewed 12723 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

zolobolo wrote:- Fleet movement: in one occasions the attacking fleet of 3 destroyers, Military Transport and Fleet Carrier did not close on two enemy fortresses for around 20 Turns. Neither side had missiles left at that point, but the carrier did have an interceptor squadron reserved: they probably were not willing to go into close range due to having the interceptors but were also not willing to send it out to a suicide run. They did eventually close in to the base after a while though... See picture below on the stalemate phase
I recently noticed that myself. As you noticed it's not so much related to fleet movement as it is to the vanilla "stand off and bombard" feature combined with the mod's ability to have the AI reserve interceptors/strike fighters.

What's happening is that once all ships in the opponent's fleet are immobile, the AI goes into "stand off and bombard" mode, which causes it to stop all ship movement and only use missiles/craft. It ends when the fleet runs out of missiles/craft or the battle hits turn 30. The reason nothing is happening is that the AI on both sides sees the other's strike fighters in their hangars, and because the potential ship targets are so far away it decides it's not worth it to attack any ships and so reserves the fighters to intercept the other side's fighters.

I think you will find that once the "stand off and bombard" mode ends, and the ships move into range, the strike fighters will sortie. I think the AI is making the right decision here, the problem is that the AI doesn't recognize that there is a stalemate and end "stand off and bombard" mode.

It's a problem I'm not sure how to solve since I can't have any variables that persist across turns, other than what is provided by the game engine (see the earlier conversation with sven), but I did make it so that the battle comes to a draw at turn 50 instead of turn 30, so that the AIs are guaranteed to get at least 20 turns of combat in. I don't think this is an issue against a human player, since a human will either sortie their fighters or move their ships in, and the AI will act appropriately.
zolobolo wrote:On the side note: the Military Transport did move to Raid one of the Fortresses once so your rule does apply to Assault Shuttles (they consider bases to have disabled engines and the vanilla mechanic generally seem to work against bases because of this)
Yeah, it wasn't hard to see what the issue is once I looked into it, the AI doesn't realize that it can use assault shuttles against non-immobilized ships.

The hard part (for me) will be figuring out how the AI should prioritize ships carrying assault shuttles, in terms of threat level.
zolobolo wrote: - Interceptors and Strike Fighters of attacking fleet are not deployed, if fortress is defending planet: this is probably due to its PD capacity.
- Interceptors are not deployed against bombers
That's curious, it seems like a bad prioritization issue. How close were the bombers and were there any launchers/hangers in the bomber's fleet that had reserved craft or missiles?

I wonder if there's a way to attach tooltips to craft, that you could hover over to see what they were thinking when they launched. Right now I dump that stuff into the F1 console but it gets cluttered.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

Yes, like you said and visible in the time bar, the attack did eventually continue and the ships closed in for an attack
At this point obviously they did not stand a chance and retreat should have been the logical decision, but the reason for the standoff is clear.
Would it make sense to reduce the standoff timer max from 50 to 40? What would be the scenario where the AI can utilize the lat 10 turns?

The issue with boarding seems logical. As the AI does not utilize the boarding module, never noticed if they know at all that ships can be attacked even if engine is operational, given the appropriate module. Can this be translated into a IF Boarding Module exist, THEN use action: boarding on target when evaluating the attack? Instead of IF Engine_state=Disabled Then Board

Generally, replacing the logic of disabled engines with existence of boarding mod3eul would make sense don't you think?
The only real loss here would be the attackers efficiency against bases

Regarding interceptor behaviour:
1. Interceptors and Strike Fighters are not launched in the scenario seen below in the picture. The Fortress has reserved interceptors but they would not be in range. So in this scenario we have two issues: The bomber role does not take priority for the Assault Fighters even though enemy vessels are in range and no PD in range reserved (there is PD and interceptors available on the star-base though which is probably the source of the issue)
2. For the other case where interceptors are not launched I do not have the save anymore, but it was like this: Enemy launched bombers against my carriers, pushed auto turn, and my carriers did not launch Assault Fighters. This might be due to: 1. Enemy carriers still had interceptors reserved, Enemy had serious PD power with destroyers, Assault Fighters took bomber role as priority but did not want to launch yet
Attachments
No attack.png
No attack.png (933.99 KiB) Viewed 12718 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

zolobolo wrote:Would it make sense to reduce the standoff timer max from 50 to 40? What would be the scenario where the AI can utilize the lat 10 turns?
Not sure what you mean, the standoff timer max is 30 turns. As a work-around I modified the battle timer itself to last 50 turns, so that there would be at least 20 turns of non-standoff combat.
Last edited by harpy eagle on Sun Apr 01, 2018 4:50 pm, edited 2 times in total.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

harpy eagle wrote: Not sure what you mean, the standoff timer max is 30 turns. As a work-around I modified the battle timer itself to last 50 turns, so that there would be at least 20 turns of non-standoff combat.
Ah, I see what you mean... makes sense - also saved the battle in this case as it allowed it to move forward in the end :)
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

zolobolo wrote: 1. Interceptors and Strike Fighters are not launched in the scenario seen below in the picture. The Fortress has reserved interceptors but they would not be in range. So in this scenario we have two issues: The bomber role does not take priority for the Assault Fighters even though enemy vessels are in range and no PD in range reserved (there is PD and interceptors available on the star-base though which is probably the source of the issue)
The craft on the star-base causing the interceptors/strike fighters to reserve themselves would be my guess as well. The AI weighs the various priorities and it might need some tuning, although, they do already get a huge bonus to prioritizing targets that are in launch range, so I want to take a closer look myself to see exactly why it felt those craft on the star-base were so dangerous before tweaking things. If you have a save with undo enabled that might help.
zolobolo wrote: 2. For the other case where interceptors are not launched I do not have the save anymore, but it was like this: Enemy launched bombers against my carriers, pushed auto turn, and my carriers did not launch Assault Fighters. This might be due to: 1. Enemy carriers still had interceptors reserved, Enemy had serious PD power with destroyers, Assault Fighters took bomber role as priority but did not want to launch yet
That's weird. I'll probably have to recreate that situation to know what was really going on. If it was from before the last update (of this mod) then it was could have been due to craft not having as high an intercept priority as they should. I'll post the revision number whenever I update the mod from now on.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

harpy eagle wrote:
zolobolo wrote: 1. Interceptors and Strike Fighters are not launched in the scenario seen below in the picture. The Fortress has reserved interceptors but they would not be in range. So in this scenario we have two issues: The bomber role does not take priority for the Assault Fighters even though enemy vessels are in range and no PD in range reserved (there is PD and interceptors available on the star-base though which is probably the source of the issue)
The craft on the star-base causing the interceptors/strike fighters to reserve themselves would be my guess as well. The AI weighs the various priorities and it might need some tuning, although, they do already get a huge bonus to prioritizing targets that are in launch range, so I want to take a closer look myself to see exactly why it felt those craft on the star-base were so dangerous before tweaking things. If you have a save with undo enabled that might help.
You can see the scenario in the picture above: possible targets include destroyers and Cruisers.
Now to be fair: our shield tech is beyond them, so none of these two types can really make a dent in our carriers. Could this be a reason why our strike craft don't want to engage them?
harpy eagle wrote:
zolobolo wrote: 2. For the other case where interceptors are not launched I do not have the save anymore, but it was like this: Enemy launched bombers against my carriers, pushed auto turn, and my carriers did not launch Assault Fighters. This might be due to: 1. Enemy carriers still had interceptors reserved, Enemy had serious PD power with destroyers, Assault Fighters took bomber role as priority but did not want to launch yet
That's weird. I'll probably have to recreate that situation to know what was really going on. If it was from before the last update (of this mod) then it was could have been due to craft not having as high an intercept priority as they should. I'll post the revision number whenever I update the mod from now on.
Have to generate a new save for this myself. It is a difficult scenario as I have to make the AI attack my fleet equipped with bombers or start a bombing run against a fleet with interceptors. Last time I just started a game on hardest difficulty and max number of Colonials and imperials and was waiting for the battles between the two to cover carrier vs carrier scenarios
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

This is a new scenario but similar result:
Defenders scramble all bombers against a carrier, but the carrier does not scramble fighters to defend against them. Now its shields and PD can easily deflect the attack so maybe I am just not giving the AI enough credit on this...

Later in this battle, the bombers of the carrier do get intercepted by one of the star-bases before they reach their target: the planet itself. Apparently they figured that as a viable target which is sub-optimal though due to distance.

This scenario also includes a standoff between the carrier and Cruiser and the bases
Regarding standoff: sorry for asking this again but last time I misunderstood the setting: So is it possible to reduce the standoff timer by 10 to 20 Turns? Accordingly your extended turn limit of 50 could also be reduced to 40. The rational would be that by turn 20 there will be no more missiles left on either side, and heavy weapons should have done the job by then else there is no reason to carry on for another 10 Turns
Attachments
Scenario.png
Scenario.png (1.18 MiB) Viewed 12715 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

zolobolo wrote: You can see the scenario in the picture above: possible targets include destroyers and Cruisers.
Now to be fair: our shield tech is beyond them, so none of these two types can really make a dent in our carriers. Could this be a reason why our strike craft don't want to engage them?
Unfortunately not. When deciding to reserve interceptors the comparison is roughly like this: (value of target ship)*(potential damage of the strike fighter group) vs (MAX{value of the most valuable ship in our fleet (used as an approximation for the value of a hypothetical bomber target), value of the bomber group itself as a target})*(potential damage of the bomber group)

Pretty much all decision making by the AI (with regards to choosing targets/reserving weapons) is done by throwing these priority scores into a table and choosing the highest one each turn, fundamentally it's pretty simple.

The value of a ship is calculated from it's threat level (total damage of all functioning weapons on the ship) vs it's vulnerability (so ships with lots of armour/shields/shield regen are not considered as valuable since damage done to them does not bring as much of an immediate benefit)

There also are a bunch of adjustments applied, for example, if the target ship is within range, it's value is multiplied by 3.

My hunch right now is that the value of the bomber group itself as a target is what is tipping the balance for the AI, since bomber groups are almost always high value (they can do a good amount of damage and have very low health, so attacks made against them are usually pretty beneficial). That said, there is a 3x multiplier on the value of the nearby ships so maybe it's something else.

If you could send me the save file it would help avoid a lot of guess work.
zolobolo wrote: Later in this battle, the bombers of the carrier do get intercepted by one of the star-bases before they reach their target: the planet itself. Apparently they figured that as a viable target which is sub-optimal though due to distance.
Well, the planet is probably a much more appealing target than the starbases due to having a lot of weaponry and not so much shields. More importantly though, the planet doesn't really look that much farther away than the starbases are... so I don't think it's exactly correct to say that it is sub-optimal due to distance.

I think it's sub-optimal due to the starbases being in-between the bombers and their target, thus exposing them to a lot of PD. Unfortunately I don't know if the engine really provides any tools for the AI to understand such things. So right now the AI has no sense of ships in front or behind others, only their relative distances. I don't really have any plans to address that right now, it seems like potentially a lot of complexity for something that isn't too too sub-optimal (I hope).
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

zolobolo wrote: Regarding standoff: sorry for asking this again but last time I misunderstood the setting: So is it possible to reduce the standoff timer by 10 to 20 Turns? Accordingly your extended turn limit of 50 could also be reduced to 40. The rational would be that by turn 20 there will be no more missiles left on either side, and heavy weapons should have done the job by then else there is no reason to carry on for another 10 Turns
Yeah, this should be no problem.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

harpy eagle wrote: The value of a ship is calculated from it's threat level (total damage of all functioning weapons on the ship) vs it's vulnerability (so ships with lots of armour/shields/shield regen are not considered as valuable since damage done to them does not bring as much of an immediate benefit)

There also are a bunch of adjustments applied, for example, if the target ship is within range, it's value is multiplied by 3.
Sounds like a logical approach to catch all those pesky ENV variables - need to think about this (the achilles heels here are probably mobility and ships in between like mentioned below) but so far the logic generally holds up. Most of the tactical AI behaviour is very fun to fight against as it frequently surprises and being efficient at the same time.
harpy eagle wrote: If you could send me the save file it would help avoid a lot of guess work.
Save has been attached - it contains a test game I have described earlier: good for producing lots of test scenarios involving small crafts
harpy eagle wrote: Unfortunately I don't know if the engine really provides any tools for the AI to understand such things. So right now the AI has no sense of ships in front or behind others, only their relative distances. I don't really have any plans to address that right now, it seems like potentially a lot of complexity for something that isn't too too sub-optimal (I hope).
Agreed: this is most definitively a side note only. Like mentioned above the logic generally holds up in most circumstances and if the AI script has no parameter to tweak it by, then is better left alone.

Behavior concerning small crafts and PD was the issue that brings the most value and you managed to tighten the logic quite a bit
In my opinion, Assault Shuttles are the second largest issue for the AI as (contrary to boarding module) these are actually produced and there are numerous ship designs that solely rely on the module which in turn is effecting the performance of at least half of all the races even on the strategic map. I have done some testing sending with these and they are crazy efficient against destroyers (Boarding) and capital ships (Raiding) alike. They are even the single best source to steal tech but are left unused altogether
Attachments
Mod Testing 2.rar
(1.93 MiB) Downloaded 406 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Post by harpy eagle »

Thanks for the save file. I had a look at the values the AI had assigned to the different parts of the priority calculation in the battle around Cheleb, and it seems what was happening was this:
  • The fleet carrier's defensive capability was such that the AI didn't care that the bombers were attacking it, and only considered the bomber's value as something to potentially destroy.
  • The bombers were armed with only nuclear missiles, while the interceptors at the star base were armed with disruptors (14*10=140 damage vs (8+18)/2*17=221 damage), so the bombers weren't even that valuable.
  • The AI gives a large bonus to the bombers for being close, but doesn't penalize interceptors for being far away when deciding to reserve interceptors to them, should they launch
The result is that reserving for the interceptors beats out attacking the bombers by a smallish margin (roughly 66.1 to 55.6).

I guess of the three, the last point could possibly be improved. Initially the reason that I don't penalize for distance when deciding to reserve was that we expect that any launched trackers will get closer eventually, and we don't want the interceptors flying off in the meantime.

However now that I'm looking at it again, it does make sense that we would not want to reserve fighters for a target that we wouldn't then be interested in intercepting later. I'll see about possibly tweaking this.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Post by zolobolo »

harpy eagle wrote: The result is that reserving for the interceptors beats out attacking the bombers by a smallish margin (roughly 66.1 to 55.6).
This is perfectly fine then: the fact that it recognises the bombers do not pose any threat to it validates the decision perfectly, so no need to tweak any futhter just for the third point. This is even more the case if interceptors can take damage from bombers/interceptors or assault fighters when engaging (no sense in taking damage if the shields can absorb the payload) - though admittedly I never notived this (even though some bombers have graphical PD element on them)
harpy eagle wrote: However now that I'm looking at it again, it does make sense that we would not want to reserve fighters for a target that we wouldn't then be interested in intercepting later. I'll see about possibly tweaking this.
Wouldnt the intereptors be intercepted though? Could they not penetrate the shields with disruptors?

The more important question here might be: why the bombers have been sent out if the calculation is aware that they will not be doing any damage? Shouldnt they be reserved untill the enemy gets close and other weapons can open fire as well?

Originally I though the AI can make use of the same mechanic early chess games were using by evaluating the various potential move scenarios (especially considering the builtin undo mechanic), hence a lot of my suggestions going in the direction of: if interceptor losses <50% then attack ship, and though it handily incorporates all the possible variables such as PD heavy bases in the way, admittedly this would have lead to deadlocks and bad performance.

I like this system a lot more: was it already in the game or did you spice up the code with this target priorisation mechanic yourself?
Post Reply