naselus naselus

Strategic AI modding discussion thread

Strategic AI modding discussion thread

Not a thread for talking about how terribad the AI is, but a thread for discussing the contents of AI-related files and how we can mod them. I also want to keep tactical battle behaviour out of this thread - it's not really the same thing, since the player cannot really take advantage of it to the same extent.

 

Thus far, we appear to have determined that the AI is directly affected by the settings in the following files (I'll update this as we find more):

 

AIStrategydefs.xml - this largely determines the AI's spending and shipbuilding priorities, along with impacting on the tech choices.

Factiondefs.xml - This has some bearing on the AI's tech choices

Governordefs.xml - This determines what the AI builds on planets.

Galciv3AIDefs.xml - This sets difficulty bonuses, and controls AI diplo and combat behaviour.

*techdefs.xml - these have AI category weighting on the techs to help determine which technologies they like.

 

It will also only build ships that are defined in Shipblueprintdefs.xml, which for our purposes counts as the 'shipyard AI' (though the player also has access to these blueprint types).

 

If you find any more, report them here and I'll add them to the list; if you find how an AI settings works or what it does, post it and I'll add it to the posts below (only for AIStratdefs, Factiondefs and Galciv3AIDefs - the other two are pretty much just build queues). let's discuss how to make it work better.

 

EDIT: I dug up this thread: http://forums.littletinyfrogs.com/462863/GalCiv_III_AI_moddingscratch_pad where Brad explains how AI tech choices work, which might come in handy.

45,867 views 54 replies
Reply #26 Top

Quoting rspiccaver, reply 25

Naselus. FYI and anyone else currently working on the AI.


I've been working on some changes and doing more testing (I'm close to OCD when it comes to testing, haha) and this is going to produce a couple of difficulties that I'm having a hard time currently getting around.

 

    • On Normal difficulty, the AI will not colonise before ~ turn 20. (Except Drengin who start from the first turn)

 

    • On Gifted AI, they start colonising ships at ~ turn 10 (Again except Drengin)

 

    • On Genius+ they all start colonising from the get go.

 


There is one exception to this, and that seems to be based on proximity, which allows the races to colonise their home system planets. The Krynn will produce 1 further colony ship then stop. Also, if there is a planet VERY close to their homeworld, the AI will colonise it.

This is also the cause of a problem I mentioned in my other thread previously, where the Thalans/Yor (factions with only 1 starting planet) are decommissioning their starting colony ship. The idle time is kicking in before they are able to start the colony spam.

This is a huge positive for the Drengin clearly and likely a bug. But presents us with a problem when it comes to making the AI more aggressive at colonisation. I've spent ages combing through the xml trying to figure out what is causing this and I'm starting to fear we might not be able to manipulate it. If anyone has any insights please share, maybe it's me missing something or just from me looking too long and not seeing.

R

End of rspiccaver's quote

 

Hmmm, I'm really not seeing this behaviour - I've got it sat on 'normal' and several AIs were colonizing from the get-go, and continuously.

 

You *may* be seeing this because on lower-end difficulty they need to scout worlds first. This would explain why the AI will go for 'nearby' planets (because they can see them already) but disbands starting colony ships otherwise (because there's nothing it's aware of to colonize). It would also go some way to explaining why I'm not seeing it - I made sensors more effective because on Insane maps, they kind of need to be. 

 

Try boosting the sensor radius granted by colony capitals to some really big number (so the AI should be able to see multiple empty worlds) and then re-running the sim. 

Reply #27 Top

Quoting naselus, reply 26

Try boosting the sensor radius granted by colony capitals to some really big number (so the AI should be able to see multiple empty worlds) and then re-running the sim.
End of naselus's quote

Bingo, you hit it in one.

I did think it might be something similar but what was throwing me off was seeing the AI go directly to a planet/resource regardless of whether they have uncovered it in the FoW (they definitely have knowledge of the uncovered map even on normal). I tested by adding large sensors as you suggested and they will start to use their starting colony ships as long as they find a planet before turn 12/13.

All I can think of is the FoW is being unlocked for the AI at turn 20 on normal, 10 on genius and turn 0 for above. Since at these checkpoints all the AI would start colonising no matter how little they have scouted. I still wonder why the Drengin seem to be excluded from this.

Knowing this actually complicates matters from my viewpoint  :annoyed: , the logical reaction would be to make scouting a higher priority for them, but I'm not actually convinced that will be useful, since at turn 20 it becomes irrelevant and it takes that long for them to build a fleet of scouts (not to mention AI has a limit to the number of scouts it will produce)...

R

 

Reply #28 Top

I'm not sure that FOW is actually lifted on turn 20 for normal AIs - they do seem to react to exploration treaties with sudden bursts of colonization, which implies they still aren't aware of the worlds until then - but they do get 'inspiration' as to where habitable worlds are. It may be turn 20 is when the first of those flashes of intuition comes in. This means scouts do remain of some use on lower difficulty levels.

 

I'm currently stuck using a mobile hotspot with very limited data allowance, so rather than modding much I'm gonna keep playing my test game; I genuinely wasn't in a position to take advantage of the AI's early weakness pre-turn 100, which I'm very pleased about, but that was almost entirely down to the balance changes rather than the AI doing anything particularly special itself. I'm also currently experimenting with re-scaling population to max at 100 (with production scaled down appropriately), so I'm not sure that what I eventually come out with will be directly transferable to vanilla. But I'll continue to report my results.

Reply #29 Top

Quoting naselus, reply 28

I'm not sure that FOW is actually lifted on turn 20 for normal AIs - they do seem to react to exploration treaties with sudden bursts of colonization, which implies they still aren't aware of the worlds until then - but they do get 'inspiration' as to where habitable worlds are. It may be turn 20 is when the first of those flashes of intuition comes in. This means scouts do remain of some use on lower difficulty levels.
End of naselus's quote

Yes, this seems to be the case. The AI colony ships are very bad at running into pirates and getting blown up so I'm more than inclined to agree that the full FoW isn't being lifted. However these 'inspirations' definitely kick off the colony spam at turn 20. That's when all races are starting to build colony ships (the AI refuses to build a colony ship if it doesn't know about a habitable planet).

The AI also will not build more than about 3-4 scouts in the early days, which is a bit of a pain.  I'd rather they built those instead of too many constructors and then get bogged down trying to build durantium refineries as a first building on a new colony.

I've come up with a compromise and have made them hold back most of their starting cash (I left enough for them to buy a couple factories). Then I've forced them to rush buy colony ships at turn 20. This stops them blowing it on scouts/constructors and is working quite well so far.

Quoting naselus, reply 28

I'm also currently experimenting with re-scaling population to max at 100 (with production scaled down appropriately), so I'm not sure that what I eventually come out with will be directly transferable to vanilla. But I'll continue to report my results.
End of naselus's quote

Yup, it's easier to tailor to one group of settings, I'm trying to keep mine as encompassing as possible at the moment but we'll see.

R

Reply #30 Top

why not just disable constructors in the StartStrat, give colony ships a big weight and scouts a small weight? That way, the AI won't waste time building starbases for goods it can't use, and will build scouts until it sees an empty planet, where upon it will build and send a colony ship.

Reply #31 Top

Quoting naselus, reply 30

why not just disable constructors in the StartStrat, give colony ships a big weight and scouts a small weight? That way, the AI won't waste time building starbases for goods it can't use, and will build scouts until it sees an empty planet, where upon it will build and send a colony ship.
End of naselus's quote

I tried that early on, and due to the AI refusing to build more than 3-4 scouts the shipyards sit idle, I'd rather them do something :-/ I might divert a bit more production to social for that period.

Reply #32 Top

Also, any idea how the AI picks between strategies when it's eligible for 2 yet? Like, say, an Aggressive Benevolent race has a choice between a bene and an Aggressive.

Reply #33 Top

Quoting naselus, reply 32

Also, any idea how the AI picks between strategies when it's eligible for 2 yet? Like, say, an Aggressive Benevolent race has a choice between a bene and an Aggressive.
End of naselus's quote

Not yet, it's on my list of 'to figure out' but I've got side-tracked :p - Probably do it tonight or tomorrow, I'll keep you updated if I learn anything.

Reply #34 Top

Oh, and just to report back - yes, you CAN add extra strategies. I've written up a 9 strategies for Beneviolent (turn 1-20 and then 1 every 10 turns til 100) and 'Neutral'; currently running a soak to see how the do by turn 100.

 

Also think I've figured out what 'turnlifetime' actually does - the whole system works as a series of logic gates. Every time turnlifetime runs out, it follows the gates until it finds a strategy which fulfills all the triggers. If there's no triggers, then it follows that if nothing else triggers it.

 

This offers some cool ideas:

 

1. Background strategies. You can code a generic 'background' strategy for AIs to fall back on over long periods, and then set triggers to move it out of that strategy. This means we could, for instance, define a 1-50 strategy, give it a turn lifetime of 10, and then drop a 'Trader only' strat in at turn 30 for with a 5-turn lifetime spamming freighters. After 5 turns of doing that, the trader AI will revert to the same pattern as everyone else. The triggers are presently rather limited, but I suspect if we experiment with the code we might find more work (or Brad may smile upon us and add triggers if we ask really ,really nicely). I suggest trying some of the things relating to planets under threat from GC3AIdefs.xml

 

2. We can adjust the AI's reaction time for war. While we can't teach it to pre-empt it, if we lower turn lifetimes to 1 then it will immediately switch to a war footing when attacked. This may impact on turn times, though.

 

And just a few ideas for strategies we can make:

 

Turns 1-50 in 5-turn chunks for every ideology.

Separate and distinct early, mid- and late-game war strategies

Military rush AI.

Colony rush AI

Late-game rush-buying AI

 

 

Reply #35 Top

Quoting naselus, reply 34


Turns 1-50 in 5-turn chunks for every ideology.

Separate and distinct early, mid- and late-game war strategies

Military rush AI.

Colony rush AI

Late-game rush-buying AI
 
End of naselus's quote

What happens to the AI's current building if it changes strategy?

For example, the AI is building a colony ship, but then switches into a new strategy. Does it finish the colony ship, cancel it, put it at the bottom of the queue?

Reply #36 Top

Quoting Stalker0, reply 35

What happens to the AI's current building if it changes strategy?


For example, the AI is building a colony ship, but then switches into a new strategy. Does it finish the colony ship, cancel it, put it at the bottom of the queue?

End of Stalker0's quote

 

I'm pretty sure it completes whatever it was doing.

Reply #37 Top

Quoting naselus, reply 36

I'm pretty sure it completes whatever it was doing.
End of naselus's quote

Yup, it does. Each time the shipyard becomes idle it checks the strategy for the next item to build.

Reply #38 Top

Quoting naselus, reply 34

Also think I've figured out what 'turnlifetime' actually does - the whole system works as a series of logic gates. Every time turnlifetime runs out, it follows the gates until it finds a strategy which fulfills all the triggers. If there's no triggers, then it follows that if nothing else triggers it.
End of naselus's quote

Yes I suspect it does, and I also suspect they intended to allow for more complexity but it didn't get implemented. I'll see if I can find which personality traits take precedent, but the only other things we have to set a criteria are 'at war', and the research/ascension victory thingy. I don't think the schema will allow for anything else but it's worth a try I guess. Maybe you should buy the devs a drink :)

Reply #39 Top

Precedent goes to the last strategy defined in the AIStrategyDef.xls which meets the factions criteria.

Also, the <TechAge> is not the current age the faction is in, it is a check to see if the faction has unlocked that age or beyond.

In the vanilla xml these two reasons are why Aggressive_Strategy_General is never used. ExpansionStrat_Aggressive is defined afterwards (it should have appeared before) and takes precedent, the AgeOfExpansion requirement for it has been met.

Therefore if you want to define 'background' strategies you must ensure they appear earlier in the xml so that more specific instructions supersede them. Strategies relating to later ages must also appear later than earlier ones.

Careful consideration will be needed to separate factions with multiple personality types (I suggest not running too many 'flavour strats' during the same turn periods.)

R

Reply #40 Top

Quoting rspiccaver, reply 39

Precedent goes to the last strategy defined in the AIStrategyDef.xls which meets the factions criteria.

Also, the <TechAge> is not the current age the faction is in, it is a check to see if the faction has unlocked that age or beyond.

In the vanilla xml these two reasons are why Aggressive_Strategy_General is never used. ExpansionStrat_Aggressive is defined afterwards (it should have appeared before) and takes precedent, the AgeOfExpansion requirement for it has been met.

Therefore if you want to define 'background' strategies you must ensure they appear earlier in the xml so that more specific instructions supersede them. Strategies relating to later ages must also appear later than earlier ones.

Careful consideration will be needed to separate factions with multiple personality types (I suggest not running too many 'flavour strats' during the same turn periods.)

R
End of rspiccaver's quote

 

Hmm. That complicates things a bit, since if we use multiple files we have to muck about with file names to ensure that they load in the right order.

 

I've now written tailored strategies for all but cruel, cultural, greedy, merciless, opportunistic, peaceful and spiritual for the first 100 turns; keeping a watch on the AI may offer some clues as to which is favoured (though I suspect it's just going to go with the same precedence that you're outlined above).

Reply #41 Top

For some reason, the AI has stopped moving its scouts in my current build; it builds them and just leaves them parked immediately outside the shipyard. Are you seeing anything similar, or is this a result of something I've changed?

Reply #42 Top

Decomissioning their starting colony ship. Yep we're with Deep Blue's cousin Shallow Yellow.

Reply #43 Top

Well, from another soak I can see a few things:

 

The base-game AI is massively weaker than the ones I've written. Seriously, the AIs do very well upto turn 100 and then falls off a cliff as it reverts to the 'normal' AI pattern. This is probably partly due to my other changes (the expansionist AIs cut very close to bankruptcy and in my first soak actually fell into the hole, with their budget becoming hopelessly in the red from colony maintenance), but the generalist strategy is a very sudden change of priorities. I think the AI needs to be scripted end-to-end. My first 100-turn strats have a plan and follow similar priorities all along; the base-game strategies are pretty vague and wishy-washy by comparison. 

 

However, the fact that I've managed to improve AI performance in spite of making some pretty far-reaching changes to the game is hugely encouraging. In my present build, I've implemented a number of anti-spam measures, rewarding 'tall' play against 'wide'. The AI needs to be able to afford stacking maintenance without collapsing. Every colony costs 3+(0.1*X) in maintenance, where X is the total number of colonies; this makes colonies past 50 or so very expensive. The AI is blasting through that barrier with no issues. I've also tweaked the population model to max at 100 and population produce half the production; with sufficient tweaks, the AI has taken this in it's stride and is producing growth buildings (which are practically required) and and generating high-pop worlds. I'm seeing the top spot changing hands regularly between half a dozen or more empires, following various strategies.

 

I'm gonna dive in and play a game now; see how it compares to what I can manage myself in comparison to the AI.

Reply #44 Top

Quoting naselus, reply 41

For some reason, the AI has stopped moving its scouts in my current build; it builds them and just leaves them parked immediately outside the shipyard. Are you seeing anything similar, or is this a result of something I've changed?
End of naselus's quote

No I haven't noticed this. It does happen for the controlled faction if I use the 'fow' command in the console to watch other AIs in a soak though. Also stops that faction surveying oddly enough.

Reply #45 Top

Ah, might be due to the fow command thing.

 

EDIT: Yeah, definitely was, I'm now seeing the AI moving scouts around happily. Weird that it turned theirs off too; it didn't seem to make them any better at spotting planets in the early game.

Reply #46 Top

Not much to say except that I am reading this with interest.  Perhaps we should buy YOU a drink after you're done.  

Reply #47 Top

It's looking very promising indeed thb.

 

Last night I ran a couple of proper playthroughs rather than soaks. In both, at least one AI managed to get much larger numbers of plents than me (Iridium in the first game had 3 times as many as me by turn 150, Krynn in the second had twice as many) while most other AI players were at about level pegging with me. Now, I wasn't playing all-out - no cheese tactics or super-min-maxing - but the difference in the AI's performance was pretty extreme. I had genuine military threats to worry about early (aggressive races start military build-ups by around turn 30, and by turn 90 are pretty heavily armed); I had enemy empires with bigger economies than me (greedy empires make pots of cash); I had enemy empires which were much larger than I was (expansionists go wide very, very fast); and I had enemies competing with me on tech (scientist and peaceful empires). And all this, again, on Normal difficulty. 

 

It's worth noting that the AI was fleeting its ships. The big empires will tend to churn out 100+ ships in a very short space of time and then amass them; the improved performance of their economies has resulted in a much better military performance in terms of numbers - though not in terms of tactics. In the first game, the Iridium DoW'd me when they had no warships near me, and I was able to quickly overrun half a dozen of their worlds.

 

Maintenance is presently working, but may be a little low. I set it down to 0.1 stacking on top of the base 3, in order to make sure that expansionist AIs didn't kill themselves; I don't know if that's still needed since I slightly buffed production (it's at 0.5 per pop; in vanilla this is 1 but I'm letting populations grow to 100 rather than 30 so this means an effective 66% increase...eventually).

 

Rescaling farming, incidentally, works wonders. It allows you to leave growth very low and then put the real bonuses on the growth building line, so that mindless colony spam is no longer the best way to grow your pop. Since farms are giving 10 food, and approval 10 morale, it's now very important to get a colonial hospital down ASAP - which the AI does. It's all looking very promising.

 

Tonight, I'm going to go through some of the techs and traits which I've made obsolete with changes; once that's done, I'll be ready to upload for some wider testing.

Reply #48 Top

Quoting naselus, reply 45

Ah, might be due to the fow command thing.

 

EDIT: Yeah, definitely was, I'm now seeing the AI moving scouts around happily. Weird that it turned theirs off too; it didn't seem to make them any better at spotting planets in the early game.
End of naselus's quote

 

there's a fowtrans command which lets you see objects through the FoW, including AI faction objects. I *believe* this lets the AI continue to act as if they had FoW, even though you as the player can see what they're up to.

 

 


 

Naselus, can you put your AI code up on Github or somewhere similar? 

Reply #49 Top

Quoting TurielD, reply 48

Naselus, can you put your AI code up on Github or somewhere similar? 

End of TurielD's quote

 

I'll be putting the WIP version of IAB on dropbox probably tonight, provided I have internet when I get home - I moved house last weekend and have been connecting through a very limited hotspot from my mobile phone for the last few days, but should have unlimited fibre online today. They said 'any time between midday and midnight', though, so I may have gone to bed by the time they put us online. If so, I'll just upload the AI files before bed for you guys to look at; do remember that they've been preped for different mechanics though (I wouldn't have them building hospitals on normal, and would have less social consolidation phases). It would be interesting to see how the AI strats do in a vainlla game though.