[MOD] Improved FFPlus AI

Secret_Squirrel

Chieftain
Joined
Jun 19, 2009
Messages
76
This is a small project I undertook in order to learn the basics of python, and so far its going well so I thought I would share it. Suggestions and feedback more than welcome.

Improved FFPlus AI - Version 2 Released!

The object of this modification is to make the AI make informed tech and unit choice decisions that are true to the flavour and playstyle of their race while maintaining a certain level of unpredictability. There is an equal focus on ensuring the AI economy will no longer crash due to poor economic teching.

Installation Instructions: Extract the zip file into your Fall Further Plus installation folder. If you have modified your CvGameUtils.py you should make a backup. The mod also relies on an unmodified PythonCallBackDefines.xml.

Note: If you have Odalrick's Modular Python mod installed, I'm pretty sure it would overwrite this but maybe not.

Changelog:
Spoiler :

Teching:

- ALL civs have had their early beelines changed so that they are more "flavourful", biased towards ensuring that each civ leverages its strengths, builds its Unique Buildings and fields its Unique Units and Heroes.

- AI will research the required worker techs if enough resources of that type are present in their territory. ("Stolen" and modified from Turinturambar's Economic AI for FFH)

- Oceanfaring techs researched if the AI has many coastal cities.

- AI will ensure they have early economic techs before teching their preferred Tier 2 military techs.

- Writing beeline no longer based on random numbers, AI will now ensure they have writing before they delve too much into advanced military.

- Archery prioritised for those who have emphasised the recon line and do not have Bronze. (Ensures adequate city defense).

- Education researched early if civ starts near a lot of flood plains.

- Civs will now react to Hell Terrain entering their lands or somebody bringing Hyborem into the world, they can do the following:
  • Non Evil civs will research Divination if hell terrain starts to appear and they do not have life mana.
  • Evil civs will research Infernal Pact (to adopt AV&StW) if hell terrain starts to take over their lands.
  • AI's forced to make a decision on which "side" they take by researching Way of the Wise/Wicked dependant on their alignment and their mana types (Life, Nature, Law increase chance of heading for the Overcouncil. Death, Entropy, Chaos - Undercouncil)

- AI will check for opportunities to snatch the free great people at Drama, Military Strategy and Arcane Lore if nobody else has had them.

- War will now make the AI react!:
  • If an early war occurs, the AI will check if it has Copper in its territory, and if it does, it will beeline Bronze Working to get those str 4 warriors. If not then it will tech Archery.
  • If the enemy is superior in technology and weapons during an early war, the AI will focus on defensive military techs.
  • The AI will now ensure it has sufficient siege to conduct a war if it is able to build them.

- Peace will make the AI focus more on economy and (affordable) expansion.

- Better Magic!:
  • Node building techs (Necromancy, Divination, etc) prioritised by alignment.
  • Civs with Enchantment mana will pick up KotE once they have Bronze Working.
  • Sorcery researched sooner if the AI acquires more mana types.
  • AI now has a strategy when building new mana nodes and is fully capable of death mana/spectre spam.
  • Everyone will pick up a single enchantment node if they have Alteration.
  • Most (living) civs will pick up a single body node if they have Alteration.
  • Elves will try to build a fire node asap.

- AI will go for late game civilization/religious heroes with as much zeal as the early ones.

- Some early game blocks for not so useful techs. Stirrups for example is useless if you have no Horse or equivalent resource. (Unless your civ does not require it).

Religion:

- Religion founding now a lot more diverse and unpredictable while maintaining flavour. (Most civs have 2 or more available religions they can consider founding when appropriate).

- If there are unfounded religions and the civ does not have much incentive to remain under a religion they did not found, they are likely to try and found another fitting religion for themselves.

- Priesthood heavily prioritised for those with the Holy City of their state religion.

- No disciple spamming by civs who do not have flavour affinity for their state religion or the holy city.

- Religious techs will not be researched by those with inappropriate alignment (evil civs wont found order, empy, etc).

- Religious Civics adopted asap if civ has the holy city of their state religion.

Unit production:

- Much greater stack diversity. A lot of work has gone into trying to provide variety while remaining effective.

- Limited workers to 3 per city during peace. 1 per city during war. (They will not disband any units, they just wont build more unless they lose a whole lot).

- Very controlled Settler production to ensure limited over/under expansion.

- Scouts limited to 4 (except Svartalfar).

- AI Will no longer build certain low strength units if their rivals have better units. Example: Horsemen limited to 5 for everyone except the Hippus if any neighbouring civ has Iron Working and Iron weapons.

- Will no longer produce their first settler without appropriate military defense.

- Javelin Throwers limited to 2 per city if the civ has Bronze Working.

- Priests limited to 3 per city until Theology. (To stop most notably, the tiger spam!)

- AI will not build Privateers if rivals have superior naval technologies.

- Archers limited to 5 per city for everyone except Ljosalfar and Amurites.

- Once Archery has been researched, total number of warriors allowed limited to 5 per city. (Ensures civs able to build archery ranges will not continue to use warriors as city defenders).

- World Units cannot be built in cities with poor production

- Heroes built as soon as they are available

- Illians get their Temple of the Hand sooner if the terrain around the city is poor.

Building production:

- AI will build more markets in general.

- Infernal AI will no longer build health buildings.

- Many MORE changes to influence how the AI handles building construction.

- Most civs are now quite fond of their unique buildings (Shrouded Woods, Warrens, etc).

- Unit training buildings built more often, and with more variety and intelligence. Taking into account traits, available mana, technologies, etc.

- Commerce and science improving buildings (Library, Money Changer, etc) will be built more often when the civ is not at war, and the AI now only prioritises them in cities with a high science/commerce rate.

- Courthouses built when maintenance is high.

- Forges prioritised in high production cities.

- Theoretically the AI is capable of a tower victory, but only if it acquires enough Mana types.

Improvements:

- Cottages will not be built under Aristocracy if there are other options.

- Workshops will not be built unless Guilds has been researched.

- Elves blocked from building Lumbermills.

Civics:

- Religion civic blocked for those without a state religion.

- Pacifism blocked when at war if leader does not have Philosophical trait, however the switch out of Pacifism is only allowed if the civ can afford the turn of anarchy (has enough defenders).

- Conquest blocked until Sanitation to prevent early adoption stifling growth. Later it can be adopted by AI's if the free XP provided allows them to reach the 5XP mark (or less for Charismatic leaders). For example, civ has or is building Form of the Titan and running the Apprenticeship civic.

- God King cannot be maintained if the civ acquires too many cities and they have the Cartography tech.

- Apprenticeship cannot be maintained once the civ has researched Taxation as by that point there are much better civics available.

- AI will now adopt Foreign Trade if it has lots of coastal cities and can benefit significantly from it.

- All the above changes take into account religious civics and AI's running those civics will not change due to any of the above circumstances.

Bugs/Known Problems:

- Kuriotates have a habit of building their settler unit and then never settling it, even when there are no external threats. I would try to change this using getCityFoundValue but that gets called 5 bazillion times per turn and just isnt viable.
- The supply cost bug in FF affecting summons can sometimes kill the AI's economy now that they are likely to utilise the summons more in general. I hope this bug is fixed soon!
- I had to remove the imported code from the Economic AI mod which gave instructions on when to build less/more adepts. For some reason it was causing certain civs to stop building completely in one or more of their cities. Since I removed this code, it has not happened since and I have no other references to Adepts/Mages at all any more. The AI still use them better than before but I dont strictly control how many they build any more. Not until I can come up with a better system or get this one working.

To Do:

- Specific Infernal/Mercurians AI. They wont do any worse, they just dont have as many instructions as all the other civs.
- Perhaps a more predictive rather than reactive approach in the AI's behaviour. I may have them check their neighbours' attitudes and have them react based on that. If everyone around them is getting along nicely they can be more builder oriented, if everyone hates them then prepare for war. I think this approach would be better than a strict is/is not at war system. (Assuming neighbours' attitudes can be measured using Python!)
- More playtests, its difficult for me to assess where to go with this now until I review their performance more. Its much faster if I just watch the AI play but after recently witnessing an AI clash between Abashi the Black Dragon and Sphener, I think I might just play it a bit more now instead.



Download Version 2:
 

Attachments

Shame this is for FF+ and not base or I'd be using it. May still have a look at it and see things.
 
Although I have tried to put as much FFPlus specific stuff into it as possible, there isnt an incredible amount. It should be pretty simple once I get it "finished" to port it over to FF if the demand is there.
 
Wow! This looks really good. I will definately use it when I play FF+ :D !

May I borrow this for Fallen Ages? I tried merging the Economic AI python mod, but it is rather complicated. This would work better for FF+, and would be easier to merge.

Great job! And, Valkrionn, I think you may be right. Fallen Ages was the first posted (Idea-wise) but this is the 1st released mod that I'm aware of that wasn't made by a team member.

x
 
I dunno, do you count the fact that my modular mods have always been viable for Fall Further Plus? If so, I had my mods out before Fall Plus was done :D
 
PLEASE MERGE THIS!!!!!! (Just a thought.)
 
I dunno, do you count the fact that my modular mods have always been viable for Fall Further Plus? If so, I had my mods out before Fall Plus was done :D

Nope. Those are 'compatible' but not 'exclusive'. :lol:

Even if they're linked to in the first post of the download thread... Need to add this one too.

PLEASE MERGE THIS!!!!!! (Just a thought.)

Planning on it, although I believe it's not a finished piece? Might merge just parts for now, incorporate more when it's finished.
 
Its not actually all that far away from what could be called a finished piece. I plan to add the missing races this week and do a little more play testing. Then I imagine there wont be much left to do and you can merge away.
 
Suggestion/Request:
Would it be possible to not outright limit the number of a specific unit an AI civ can build? Instead, perhaps, have them be limited based on a case by case appraisal of their economic situation? This would be a more complicated solution than the original; but, it seems that it would be more intellectual for the AI.

Also, regarding archer spam, sending over stacks of archers isn't really a bad idea, (this is referring to offensive archers in specific; as for defensive archers, having ten defending on an enemy city might be bad for you, but if their economy is proficient, then it is only good for them, otherwise defensive production of archers could be limited as the above paragraph suggests). The AI just needs to know to use offensive archers for siege purposes rather than a direct city-attack.
 
There arent many limits imposed and of those I agree that the archer limit could be troublesome, as it stands it is still possible for archers to be used offensively but they rarely form the majority in an offensive army unless flavourful for them to do so.

I could have the limit completely lifted by another tech that would provide adequate city defender replacements for archers but in general they are always better when used defensively, even if that means comprising a small defensive group in an offensive army.

As for them being supplementary siege, I try to encourage the AI to build catapults wherever possible as I find them more effective. The obvious exception being the elves. Consequently the Ljosalfar do not have any cap on their archers, that only leaves the Svartalfar, I may remove the limit entirely for them too.
 
I have not played your mod as I accidently removed FF+ thinking it was an old version of FF... yeah I am an idiot.

Anyway, On unit production limits - have you concidered a limit on the number of Scouts, Hunters, and Rangers for the non-recon centric races? and/or limits on adepts (not mages)?

It seems I get invaded by stacks of Adepts and Rangers currently and those are 2 of the worst to attempt to take cities with. I am talking a stack with 12 rangers, 9 adepts, 1 Champion, and 3 or 4 catapults. It would be much more appropriate to see stacks of 16 Champions, 3 Rangers, 2 or 3 adepts, and 3 or 4 catapults

I think a limit of 4 adepts, 4 rangers, 3 hunters, and 2 scouts per city might be a good place to start thinking about.
 
By siege I meant tile guarding in enemy fat-crosses, prioritizing the crippling of production and food for the city.

Also, nice mod this one is -other than my dislike of static AI unit production limitations-.

PS: Kuriotates might benefit from a higher cap, seeing as their cities can support a larger economic bubble, and that they have a limited number available.
 
Since the hard unit caps seem to be off-putting for some, i'll go into more detail about what is there, and what is currently under revision:

Scouts are currently limited to 4 for all races (considering removing this for Svartalfar).

Warriors are limited to 5 per city once the civ has researched Archery (helps with diverting hammers to get that first Archery Range up).

Javelin Throwers are limited to 2 per city once Bronze Working is researched.

Archers are limited to 5 per city once the civ (excluding elves) has researched Bronze Working (Will review for Kuriotates).

Adepts limited to 6 unless civ has Arcane trait or the Sorcery tech.

All tier 1 religious disciples limited to 3 unless civ has holy city or flavour-affinity for said religion (Example: Malakim - Empyrean).

Rangers are not limited because I find them a viable mainstay unit in the right circumstances, most of these "hard caps" are focused on the early game when mistakes are more fatal. I would like to apply as few of them as possible.

I have been doing some more play tests and tweaking so expect another version soon. I will also try to provide a more complete change log as its a little sparse compared to the number of actual changes.
 
I like those things you've posted up, Secret. Those seem like they'd actually really help the AI in the early game, where they tend to get eaten by barbs or other AIs with better teching.

Do you think it would be too off-flavor to order the Amurites to research Archery before going off down the Arcane line? They always tend to fair poorly in my games, and I think it's because they go straight for Adepts.
 
Since the hard unit caps seem to be off-putting for some, i'll go into more detail about what is there, and what is currently under revision:

That all makes sense. All the late stuff isn't limited at all, so it should be limited to the beginning of the game not late game.
 
Until I properly update the initial post, here's a short outline using the Amurites as an example of how the AI will tech using my system:

The first check is for resources, as it is for everyone. Then they have a choice of 3 techs (this ranges from 2-5 depending on how militarily focused the civ is). For the Amurites this is currently Archery, Knowledge Of The Ether or Education. A random number is then generated to "choose" the technology they then go on to research, this system could probably be refined but it works well at the moment. This results in an element of randomness while still having priorities. So it is possible and quite frequent that the Amurites will now go archery first and then perhaps even education and a few worker techs before they get Knowledge Of The Ether, but they will definitely pick it up before they move on to a higher "tier" technology. Upon moving to a higher tier there is then a similar restriction in place biasing a more "complete" range of useful Tier 2 technologies over moving onto end game techs.

The effect as a whole for all civs is one where it is unlikely that the AI will research an expensive Tier 2 or beyond technology (such as Iron Working) before they have rounded up most if not all of the cheaper useful technologies. It is possible for a "lucky" roll on the random numbers to allow a civ to beeline an expensive tech, but afterwards it would have to be extremely lucky to go for something else just as expensive, and would be more likely to pick up necessary economic or civic related technologies.
 
why 6 adepts only? 8 makes a lot more sense to me. you could get 4 liches and 4 archmages, or replace your 4 archmages if they get killed.
 
well... it is 6 adepts UNTIL the AI gets sorcery. Once the AI gets sorcery, then it will get more adepts. Personally, unless I really need it, I don't usually start building adepts except to cast inspiration/wall or stone etc. (units that never go on to become archmages), until I get sorcery. Too many hammers wasted on them that would be better spent building more axmen/archers.

-Colin
 
Back
Top Bottom