Tactical Combat AI Mod

A place for discussion of making game modifications.
User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Tactical Combat AI Mod

Postby sven » Tue Apr 10, 2018 5:22 am

harpy eagle wrote:I actually just got some ideas for how this might be done, to help the AI to keep it's ships together. It kind of relies on the AI's ships already being in a good formation to begin with though.


As you mull this over, it might be worth knowing that, at a low-level, the "game rules" do allow ships moving as part of the same tactical order to have non-symmetric destinations. More exactly, when the player does a multi-ship move, they're creating a command that says something like:

Code: Select all

order.move_ships {ship1,x1,y1,r, ship2, x2, y2, r,  ship3, x3, y3, r }


Where all xi,yi are chosen in a way that preserves the relative distances between the three ships. But, technically, as long as each target xi,yi,ri destination is a legal destination for the associated ship, you can do a multiple ship move with any arguments, and the engine will accept this as 'legal'. In other words, it's possible to do a "formation move" in which the ships involved aren't actually moving in formation.

Years ago, I had plans to use this feature with an advanced tactical AI script, on the theory that it would let the AI take relatively good advantage of mutual point defense during moves without otherwise complicating the logic. Needless to say, I've yet to get around to implementing that plan, and there are various reasons why exploiting this feature in an ai script could prove to be hard and/or unwise. But... the capability is there, at least in theory.

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

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 10, 2018 9:19 am

Carriers are staying behind during bombardment - I think this was already change previously so that they move together with other fleet elements

Moving tougher ships first would additionally help the attackers but even more if bomber/Strike Fighter payload is delivered after the rockets so that the later can soak up PD fire (they use the same tech but small crafts can make unlimited rounds until not destroyed and should thus be more valuable)
Attachments
Behind the line.png
Behind the line.png (979.6 KiB) Viewed 18196 times

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

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 10, 2018 10:35 am

Carrier A seems to be blocked in its movement by a disabled Military Transport and does not fire rockets and missiles from this distance
Carrier B seems to be blocked by the three heavy Cruisers and does not fire at the base
Carrier C ignores the priority settings and targets planetary defenses even though fortress is still in game: this might be due to it trying to board the base but being in range of the planet it does not ignore it?

Save for scenario: https://www.dropbox.com/s/zzl7oroeoeapv ... 7.rar?dl=0
Attachments
Move and Priority.png
Move and Priority.png (911.67 KiB) Viewed 18191 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 10, 2018 5:18 pm

zolobolo wrote:Carrier A seems to be blocked in its movement by a disabled Military Transport and does not fire rockets and missiles from this distance
Carrier B seems to be blocked by the three heavy Cruisers and does not fire at the base

Haha, I've noticed ships getting blocked by other ships before (only happens when the ships are so slow they don't have enough movement points to make it to the other side), but I haven't seen it cause such a huge problem before this case.

If it weren't for them being blocked I'm guessing all 3 would be up there against the fleet base.

While it would be solved by moving ships together, there's no way I know of to tell when a ships movement is blocked by another ship, so I'm not sure what could be done.

The move other changes might help this one particular case, but there's no guarantee since it doesn't actually know about movement dependencies.

zolobolo wrote:Carrier C ignores the priority settings and targets planetary defenses even though fortress is still in game: this might be due to it trying to board the base but being in range of the planet it does not ignore it?

Pretty much. I think it's doing the right thing. One the planet is a relevant threat for the carrier it's going to be able to destroy the planet defences a lot quicker than the fleet base.

sven wrote:As you mull this over, it might be worth knowing that, at a low-level, the "game rules" do allow ships moving as part of the same tactical order to have non-symmetric destinations.

Cool, I think I will be able to make use of that.


Okay, so the list of things TODO is then:

  • Improve tactical movement
  • Improve how missiles/bombers are factored into the fleet power calculation DONE!
Last edited by harpy eagle on Wed Apr 11, 2018 2:02 am, edited 1 time in total.

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

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 10, 2018 5:22 pm

harpy eagle wrote:While it would be solved by moving ships together, there's no way I know of to tell when a ships movement is blocked by another ship, so I'm not sure what could be done.

Actually... If it's possible to determine whether a ships desired position as returned by get_min_facing_move_L2() overlaps with another ship, it might be possible.

Though if the cruisers weren't moving, it still wouldn't help in that particular case.

User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Tactical Combat AI Mod

Postby sven » Tue Apr 10, 2018 7:27 pm

harpy eagle wrote:
harpy eagle wrote:While it would be solved by moving ships together, there's no way I know of to tell when a ships movement is blocked by another ship, so I'm not sure what could be done.

Actually... If it's possible to determine whether a ships desired position as returned by get_min_facing_move_L2() overlaps with another ship, it might be possible.


get_min_facing_move_L2() should always return a 'valid' move, in the sense that it won't recommend a position that's illegal due to excessive overlap with another ship. (all ship squares are allowed to overlap by 1 tile, but, not more than that.)

but this touches on one of the biggest barriers i see with getting the AI to use multi-ship move commands. get_min_facing_move_L2() checks the board state assuming just one ship is changing position; but if you have N different ships all moving at once, figuring out if a given ship's move is valid is actually more complex. there's another helper function, ShipSetMotion.valid_move, that does do the calculation to figure out if a multi-ship move is valid for a given *set* of ships, but, accessing that function from the tactical AI would be awkward; and in any case, what you really need, i think, is an expanded version of get_min_facing_move_L2 that can execute with the assumption that some other other ships are also going to be moving at the same time. i could write you that expanded get_min_facing_move_L2 function -- but, it would take a little bit of C++ coding. so... let me know if you really do want to dive down this rabbit hole :)

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

Re: Tactical Combat AI Mod

Postby zolobolo » Tue Apr 10, 2018 7:32 pm

Close in and attack error when engaging a large fleet of Harpies via Super Dred

Save: https://www.dropbox.com/s/w63x0efpgt5s7 ... 8.rar?dl=0
Attachments
Close and Attack.png
Close and Attack.png (156.35 KiB) Viewed 18173 times

User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Tactical Combat AI Mod

Postby sven » Tue Apr 10, 2018 8:41 pm

zolobolo wrote:Close in and attack error when engaging a large fleet of Harpies via Super Dred

This one is almost certainly due to the fact that under the hood, try_use_electrocyte uses find_max_boarding_move to close in on it's target, and you can't board fighters/missiles.

However, you can electrocyte them. There's an undocumented function, find_min_move_L2(), that works just like find_min_facing_move_L2(), except that it doesn't try to face the target. Substituting that for find_max_boarding_move in the case that the target is a tracking object would, potentially, be a good fix for this bug.

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

Re: Tactical Combat AI Mod

Postby harpy eagle » Tue Apr 10, 2018 9:37 pm

sven wrote:
zolobolo wrote:Close in and attack error when engaging a large fleet of Harpies via Super Dred

This one is almost certainly due to the fact that under the hood, try_use_electrocyte uses find_max_boarding_move to close in on it's target, and you can't board fighters/missiles.

However, you can electrocyte them. There's an undocumented function, find_min_move_L2(), that works just like find_min_facing_move_L2(), except that it doesn't try to face the target. Substituting that for find_max_boarding_move in the case that the target is a tracking object would, potentially, be a good fix for this bug.

Thanks for the advice. I was going to exclude trackers for try_use_electrocyte(), but I'll try this instead.

sven wrote:but this touches on one of the biggest barriers i see with getting the AI to use multi-ship move commands. get_min_facing_move_L2() checks the board state assuming just one ship is changing position; but if you have N different ships all moving at once, figuring out if a given ship's move is valid is actually more complex. there's another helper function, ShipSetMotion.valid_move, that does do the calculation to figure out if a multi-ship move is valid for a given *set* of ships, but, accessing that function from the tactical AI would be awkward; and in any case, what you really need, i think, is an expanded version of get_min_facing_move_L2 that can execute with the assumption that some other other ships are also going to be moving at the same time. i could write you that expanded get_min_facing_move_L2 function -- but, it would take a little bit of C++ coding. so... let me know if you really do want to dive down this rabbit hole

Right, I hadn't considered any of that. It's not a huge priority, for now I can just move them one by one.

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

Re: Tactical Combat AI Mod

Postby harpy eagle » Wed Apr 11, 2018 3:26 am

Okay, this update fixes the electrocyte bug (didn't get around to testing it yet), and improves the way fleet power is calculated (used when deciding to call a general retreat). The AI now performs the same evaluation of it's own point defence as it does for the enemy fleet, and value of missile launchers and hangar bays (of both fleets) is adjusted based on this evaluation when comparing fleet power.

Also, zolobolo, I put together a few tweaks for the strategic AI. It's not transformational, but it does make the AI aware of its mineral income and the build time of ships when assigning build orders. It also accounts for current progress when choosing what ship to build so hopefully the AI switches build orders less. The idea is to get the AI to build less fleet bases everywhere and mind it's mineral use more to prevent the late mid-game wasteland. I figured it could help testing since the AI being choked on minerals less => building more ships => more combats.

Next thing I'm working on is decoupling ship movement order from attack order.
Attachments
CombatAIMod v1.1indev (94c4eb7).zip
(21.84 KiB) Downloaded 606 times
StrategicAI.zip
(9.28 KiB) Downloaded 610 times

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

Re: Tactical Combat AI Mod

Postby zolobolo » Wed Apr 11, 2018 10:22 am

harpy eagle wrote:I put together a few tweaks for the strategic AI. It's not transformational, but it does make the AI aware of its mineral income and the build time of ships when assigning build orders. It also accounts for current progress when choosing what ship to build so hopefully the AI switches build orders less.

So far I can tell you that the late-game megalomania has decreased considerably: seems that the AI is still building larger ships but is also producing smaller ones in greater number (specifically Military Transports in my test case which is generally a good idea but hope it will switch them up occasionally to avoid homogeneous fleets.

It is going to be more difficult to test strategic AI then tactical due to the nature of it being long-term and all but I will try to do my best

Overall there are currently 3 well distinguishable segments:
1. Early game skirmishes - Has been working well in vanilla and works perfectly with your Tactical AI + Shield and Hull Damage Rebalance mod
2. Mid game wasteland - Has been delayed and somewhat relieved by the Tactical AI mod and Strategic AI mod seems to be addressing this directly so far
3. Late game megalomania (only building largest ship) - Seems to be heading into the right direction with the Strategic AI mod

Thus it seems you will have addressed both mid and late game phases with the new Strategic AI mod :)

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

Re: Tactical Combat AI Mod

Postby harpy eagle » Wed Apr 11, 2018 2:05 pm

zolobolo wrote:It is going to be more difficult to test strategic AI then tactical due to the nature of it being long-term and all but I will try to do my best

There's no need to test any changes to the strategic AI at this point. I thought I'd just upload it in case you were interested, since we were talking about it earlier in the thread :)

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

Re: Tactical Combat AI Mod

Postby zolobolo » Wed Apr 11, 2018 3:35 pm

Of course I am interested

If you feel that there will be substation changes to it coming soon, I can ditch the systematic approach and just test it as I go through normal games but the effects were promising so far and I already got too excited :)


BTW, if you would like to see the mod in an extreme case, here is a late game example:
https://www.dropbox.com/s/x3xtipt9mgnig ... 9.rar?dl=0

No errors, just a bit long processing time (around half-a a minute to process the battle automatically :)) - considering the scenario, it is understandable though. Most of the ships don't seem to be able to move as they are stacked so tight together that they are boxed in by their pals and some of the front ships start within firing range from the get-go.

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

Re: Tactical Combat AI Mod

Postby zolobolo » Thu Apr 12, 2018 12:32 pm

Some thoughts on strategic AI

For starters it would help a lot for testing and generally the players to see all parameters of other empires: Research, Production, Food and trade fleet size/capacity (other resources are already listed in Diplomacy menu but these for some reason are not)

This information can already be calculated by clicking through the individual enemy planets, is the bases of diplomatic bonuses and penalties, and should be a basis of AI (and player) strategy

Designing the strategy around long term plans and following these through despite numerous variables taking up unexpected values is probably not feasible, but utilizing the same prioritization matrix mechanic as in tactical AI mod, the strategic AI might be able to outsmart the player when it comes to positioning of the fleets.

Relevant objects would be: all fleets (won, friendly, neutral or ally) and colonies (own and that of other empires). Systems could also be considered but that level could ignore the individual value of a colony within (e.g.: there might be fortress world in the system but also two undefended ones)
Relevant parameters would be: Combat Power, Distance, Range (boolean), Value (in case of colonies this could be the weighted aggregation of the individual production ranks within the empire, while in case of fleets the potential to occupy own colonies)

E.g: A mining colony that is in the top rank of metal production of the hostile empire but with no other strategic value would be a priority target for a fleet that has enough force to take it but cannot engage other more valuable targets

OR: Colonies with the top food production within a hostile empire are primary targets for an AI if it has the advantage in fleet size but is not expected to be able to take actual planets. Moving small fleets into blocking position is enough to cripple the enemy via starvation and revolts if they cannot engage these blockade fast enough even if they have the technological and overall firepower superiority

Defending own planets could work the same way, but of course this does not say anything on how the interface between production and research algorithms could interact with each other in a meaningful way. If the positioning script can be modded separately from thee other aspects, that would be great as that activity of the AI is the most exposed to the player

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

Re: Tactical Combat AI Mod

Postby harpy eagle » Thu Apr 12, 2018 3:05 pm

zolobolo wrote:For starters it would help a lot for testing and generally the players to see all parameters of other empires: Research, Production, Food and trade fleet size/capacity


Well, you can switch to the AI empires and view their stats that way. That's what I do anyways. I assume you mean for AI development and testing purposes.

But if we don't want the AI to be too cheaty we probably want it to base its evaluation of enemy plants on the same data the player has available: population, and built improvements

zolobolo wrote:Designing the strategy around long term plans and following these through despite numerous variables taking up unexpected values is probably not feasible, but utilizing the same prioritization matrix mechanic as in tactical AI mod, the strategic AI might be able to outsmart the player when it comes to positioning of the fleets.


I've updated my collection of strategic AI tweaks and I think it does a decent job at managing economy now. I didn't go as far as to make the AI optimize it's economy or anything, but it does now take into account some basic things that were really hamstringing the AI before. I'll create a new thread for it and we can discuss strategic AI improvements there.

Fleet AI improvement would be nice too, it does tend to be a bit scatterbrained sometimes, and I've noticed that sometimes it fails to defend a critical world (even letting the homeworld be captured!) even when it has a sizable fleet at a system just 2 or 3 turns away.


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 23 guests

cron