Tactical Combat AI Mod

A place for discussion of making game modifications.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Mon Apr 23, 2018 7:09 am

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

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Mon Apr 23, 2018 11:06 pm

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.

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Mon Apr 23, 2018 11:16 pm

harpy eagle wrote:
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?

Hmm, I have an idea for how this could be handled.

Turns out my idea doesn't work out so well.

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.

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 11:48 am

harpy eagle wrote:Turns out my idea doesn't work out so well.

So did you find out what is causing those idle events?

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 2:00 pm

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

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 24, 2018 3:31 pm

zolobolo wrote:Does the AI currently factor in planetary defense missiles/torpedoes and small craft when evaluating retreat?

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.

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.

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 3:36 pm

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..

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

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 24, 2018 3:43 pm

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

It should take lost squadrons into the calculation.

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

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 5:18 pm

harpy 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

This sounds really useful but cannot find the values

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?

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 24, 2018 5:45 pm

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.

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 6:13 pm

harpy 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.

I am testing it via active battle and saving but only the contents of meta.table is displayed

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
Values.png (28.59 KiB) Viewed 17595 times

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 24, 2018 6:36 pm

It should look like this:

Image

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


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.

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 24, 2018 7:18 pm

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)
Attachments
Situation.png
Situation.png (465.81 KiB) Viewed 17596 times
Code.png
Code.png (12.25 KiB) Viewed 17596 times

User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Tactical Combat AI Mod

Postby harpy eagle » Thu Apr 26, 2018 9:06 am

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.

zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Tactical Combat AI Mod

Postby zolobolo » Fri Apr 27, 2018 6:35 pm

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
Attachments
Orthin Third.rar
(66.79 KiB) Downloaded 577 times


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 18 guests

cron