Tactical Combat AI Mod
Re: Tactical Combat AI Mod
If the code is so complex for positioning there is no sense in packing this: the AI does not need to execute perfect maneuvers, but put up a decent fight and not throw away anything
That is why I suggest (if possible) instead to flat out reduce the tactical speed of all ships within an attack-fleet to that of the slowest functional attack unit (meaning: engine still functional so that the whole fleet is not blocked). Kinda like damage is handled. It would not effect the exact positioning of individual fleet elements but keep the pack together so that they can provide cover fire/squadrons to each other and engage the enemy simultaneously
I imagine this action to be a sort of low hanging fruit which prevents losses to AI controlled fleets when invading and increase attack effectiveness
That is why I suggest (if possible) instead to flat out reduce the tactical speed of all ships within an attack-fleet to that of the slowest functional attack unit (meaning: engine still functional so that the whole fleet is not blocked). Kinda like damage is handled. It would not effect the exact positioning of individual fleet elements but keep the pack together so that they can provide cover fire/squadrons to each other and engage the enemy simultaneously
I imagine this action to be a sort of low hanging fruit which prevents losses to AI controlled fleets when invading and increase attack effectiveness
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
Here's the idea I have (no plans to implement it yet, just throwing an idea out there).
First we figure out the desired fleet movement speed. We take an average, weighted by attack power squared so that if a significant majority of the fleet's offensive power is in fast moving ships, they aren't held back by a slow vessel. We may not even need to ignore immobilized ships, if for example the fleet's centerpiece is a pair of starbases, it may make sense for the rest of the fleet to hang back with them anyways, even if it does mean that the other side gets to shoot missiles at them.
Then we figure out the 2D unit vector from our fleet's average position to the enemy fleet's average position. Call it df. Again, it's a unit vector, that's important for the next part.
Then, once a ship decides on the x,y position it wants to move to this turn (ds), we shrink it along the axis indicated by df so that df [dot] ds == the desired fleet move speed. That way lateral movements are not affected.
It's kind of hacky, since it would be better if this sort of thing was handled by the code that actually chooses a ship's movement goal. But that's in C++, so I think this is the best we can do with a mod.
First we figure out the desired fleet movement speed. We take an average, weighted by attack power squared so that if a significant majority of the fleet's offensive power is in fast moving ships, they aren't held back by a slow vessel. We may not even need to ignore immobilized ships, if for example the fleet's centerpiece is a pair of starbases, it may make sense for the rest of the fleet to hang back with them anyways, even if it does mean that the other side gets to shoot missiles at them.
Then we figure out the 2D unit vector from our fleet's average position to the enemy fleet's average position. Call it df. Again, it's a unit vector, that's important for the next part.
Then, once a ship decides on the x,y position it wants to move to this turn (ds), we shrink it along the axis indicated by df so that df [dot] ds == the desired fleet move speed. That way lateral movements are not affected.
It's kind of hacky, since it would be better if this sort of thing was handled by the code that actually chooses a ship's movement goal. But that's in C++, so I think this is the best we can do with a mod.
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
Turns out my idea doesn't work out so well.harpy eagle wrote:Hmm, I have an idea for how this could be handled.zolobolo wrote:There doesn't seem to be any activity during the below marked enemy turn stages
Does the AI actually do something there or could it be removed to reduce wait time for the other side?
It involved checking last_event_command()=="end_turn( )" in case anyone was wondering. But the problem is then you just constantly switch between moving one turn and doing nothing the next.
Re: Tactical Combat AI Mod
So did you find out what is causing those idle events?harpy eagle wrote: Turns out my idea doesn't work out so well.
Re: Tactical Combat AI Mod
Does the AI currently factor in planetary defense missiles/torpedoes and small craft when evaluating retreat?
I just had a great fight where the AI has made good progress at decimating my fleet but only decided to retreat with its last Orthin carrier when it was facing 2 Yoral heavy cruisers, 3 Destroyers and PD full of rockets...
One of the Heavy Cruisers was damaged but still, it has waited a tad too long to draw out (1-2 turns late)
Maybe it is that it didn't consider that it has lost its interceptors an bombers?
Save is here if you would like to take a look: https://www.dropbox.com/s/a8w524lhq05y1 ... 1.rar?dl=0
Overall the tactic used here is impressive (rocket heavy configurations are also not that effected by positioning) - only thing is that it might consider pulling out a turn or two earlier to save some of its fleet against overwhelming odds
I just had a great fight where the AI has made good progress at decimating my fleet but only decided to retreat with its last Orthin carrier when it was facing 2 Yoral heavy cruisers, 3 Destroyers and PD full of rockets...
One of the Heavy Cruisers was damaged but still, it has waited a tad too long to draw out (1-2 turns late)
Maybe it is that it didn't consider that it has lost its interceptors an bombers?
Save is here if you would like to take a look: https://www.dropbox.com/s/a8w524lhq05y1 ... 1.rar?dl=0
Overall the tactic used here is impressive (rocket heavy configurations are also not that effected by positioning) - only thing is that it might consider pulling out a turn or two earlier to save some of its fleet against overwhelming odds
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
Right now it's pretty simple, the AI retreats all it's forces once the enemy total combat power is more than 3-5x the friendly combat power.zolobolo wrote:Does the AI currently factor in planetary defense missiles/torpedoes and small craft when evaluating retreat?
It's usually 3x, however if the AI is defending a planet then it's 5x, so its usually a lot more stubborn about retreating when there's a friendly planet present. It doesn't consider anything about the planet, just if there is a planet to defend. Although any defences the planet has will be added to the total combat power score.
Re: Tactical Combat AI Mod
Ok, it might have been just under x3, but it should have been very close:harpy eagle wrote: It's usually 3x, however if the AI is defending a planet then it's 5x, so its usually a lot more stubborn about retreating when there's a friendly planet present..
One missile destroyer + Carrier vs 2 Heavy Cruisers, 3 Destroyers + PD - and they didn't retreat, only when they lost the destroyer.
Maybe they didn't take the lost squadrons into calculation? - Withouth those the power ration was surely >x3
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
It should take lost squadrons into the calculation.zolobolo wrote:Ok, it might have been just under x3, but it should have been very close:
One missile destroyer + Carrier vs 2 Heavy Cruisers, 3 Destroyers + PD - and they didn't retreat, only when they lost the destroyer.
Maybe they didn't take the lost squadrons into calculation? - Withouth those the power ration was surely >x3
If you add the following to the bottom of AI\CloseAndAttack.lua, and hit F1, when you save the file you should see a printout of each side's forces, including their attack power, defence power, and combat power.
Code: Select all
if lua_load_complete
local attack = all_attacks[get_attack_id()]
for empire ; attack.sides
print("Force Summary for", empire.name)
local ai_turn = CombatAI_Method.init_turn()
print_force_summary(ai_turn, empire)
end
end
Re: Tactical Combat AI Mod
This sounds really useful but cannot find the valuesharpy eagle wrote: If you add the following to the bottom of AI\CloseAndAttack.lua, and hit F1, when you save the file you should see a printout of each side's forces, including their attack power, defence power, and combat power
Get an additional file titled battle.lua with below entry:
-- active battle
pre_battle_seed = 178783967
attack_id = 427838
And the console prints out the content of meta.table containing only game setup parameters
Should the individual fleet attack/defense values be displayed in the console or one of the output files in the save folder?
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
It should be displayed in the console. It's triggered when you save the file, so you may need to add and delete a space depending on your text editor. It also only works during an active battle, not with replays.
I don't know how to print to any files in the save folder, but it sounds like it could be useful.
I don't know how to print to any files in the save folder, but it sounds like it could be useful.
Re: Tactical Combat AI Mod
I am testing it via active battle and saving but only the contents of meta.table is displayedharpy eagle wrote:It should be displayed in the console. It's triggered when you save the file, so you may need to add and delete a space depending on your text editor. It also only works during an active battle, not with replays.
I don't know how to print to any files in the save folder, but it sounds like it could be useful.
Console output is the superior method no question about (no one needs another trace file in their lives
Maybe its just me presumptions that prevent me from seeing it as I am looking something along the lines of:
Orthin 1 Total Offense Power=2.3
Gremak 1 Total Offense Power=3.1
Or is it the below values?
- Attachments
-
- Values.png (28.59 KiB) Viewed 17971 times
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
It should look like this:
Again, I've opened up Mods\CombatAI\AI\CloseAndAttack.lua, and at the bottom of the file, pasted the following:
Then when the game detects modifications to the file, it will reload it and run the code I've inserted at the bottom.
You may need to scroll up to see it, depending on how many other things are also spamming the console.
Again, I've opened up Mods\CombatAI\AI\CloseAndAttack.lua, and at the bottom of the file, pasted the following:
Code: Select all
if lua_load_complete
local attack = all_attacks[get_attack_id()]
for empire ; attack.sides
print("Force Summary for", empire.name)
local ai_turn = CombatAI_Method.init_turn()
print_force_summary(ai_turn, empire)
print()
end
end
You may need to scroll up to see it, depending on how many other things are also spamming the console.
Re: Tactical Combat AI Mod
Sorry it didn't work
Also took out the spaces and the end of CloseAndAttack.lua now looks like the below screen - nothing of the sort in the console during battle/save
So I navigated again to the situation and crunched the number manually - see screenshot of state attached
Defender Total Attack Value (that is me)= 346
Attacker Total Attack value= 152 (Ac module not accounted for, one of the destroyers is dead in the water, missile munition is depleted for all and carrier does not have any fighters/bombers anymore)
Defense value of attackers is roughly double of the defending fleet as they typicality use 2 Battle-shields whereas my Gremak ships 1 Battle Shield and 1 Distortion Generator
So they do in fact have more then a third of attack power and also hold a relative advantage in defense, but since they cannot actually do any damage anymore it is a strange situation but the important thing is that the rule works as intended. Replayed the battle a couple of times and they mostly retreat one ship at a time, and it is rare that the situation occurs.
The rule of thumb is this: when all munition is depleted and no squadrons are left, they still need to reserve PD against Viper launchers (Gremak special tech that does not need munition) and thus their effective power in the above example is in fact not 152 but something around 40 (rest is reserved PD). So if at all, the rule would need to take into account that the potential offensive power of the fleet has diminished considerably (over 60%) and the majority of the remaining offensive power cannot be utilized (but again this is quite a unique situation which can probably only come up against Gremak and Tinkers + I always use squadrons and rockets as PlanetDefence which again do not rely on munition)
Also took out the spaces and the end of CloseAndAttack.lua now looks like the below screen - nothing of the sort in the console during battle/save
So I navigated again to the situation and crunched the number manually - see screenshot of state attached
Defender Total Attack Value (that is me)= 346
Attacker Total Attack value= 152 (Ac module not accounted for, one of the destroyers is dead in the water, missile munition is depleted for all and carrier does not have any fighters/bombers anymore)
Defense value of attackers is roughly double of the defending fleet as they typicality use 2 Battle-shields whereas my Gremak ships 1 Battle Shield and 1 Distortion Generator
So they do in fact have more then a third of attack power and also hold a relative advantage in defense, but since they cannot actually do any damage anymore it is a strange situation but the important thing is that the rule works as intended. Replayed the battle a couple of times and they mostly retreat one ship at a time, and it is rare that the situation occurs.
The rule of thumb is this: when all munition is depleted and no squadrons are left, they still need to reserve PD against Viper launchers (Gremak special tech that does not need munition) and thus their effective power in the above example is in fact not 152 but something around 40 (rest is reserved PD). So if at all, the rule would need to take into account that the potential offensive power of the fleet has diminished considerably (over 60%) and the majority of the remaining offensive power cannot be utilized (but again this is quite a unique situation which can probably only come up against Gremak and Tinkers + I always use squadrons and rockets as PlanetDefence which again do not rely on munition)
- Attachments
-
- Situation.png (465.81 KiB) Viewed 17972 times
-
- Code.png (12.25 KiB) Viewed 17972 times
- harpy eagle
- Posts: 296
- Joined: Sat Mar 10, 2018 3:25 am
Re: Tactical Combat AI Mod
Update v1.3 has some significant changes behind the scenes, but primarily adds the ability for the AI to include shield and armor piercing effects when calculating the priority of potential targets.
For example, when deciding what to shoot at with coilguns, the AI won't see as much of a difference between a ship with deflector screens compared to a similar ship without deflector screens. And ships with no shields will be high priority for X-ray lasers.
For example, when deciding what to shoot at with coilguns, the AI won't see as much of a difference between a ship with deflector screens compared to a similar ship without deflector screens. And ships with no shields will be high priority for X-ray lasers.
Re: Tactical Combat AI Mod
Found an interesting side-effect: when ordering retreat to scout against harpies, the ship actually engages them and gets destroyed
Seems like it is ignoring the retreat order as well as the 3X power disadvantage
Save has been attached
Seems like it is ignoring the retreat order as well as the 3X power disadvantage
Save has been attached
- Attachments
-
- Orthin Third.rar
- (66.79 KiB) Downloaded 587 times