Smarter AI Mod

kirbdog

King
Joined
Jun 14, 2005
Messages
898
The title is ambitious, but every little thing we can do to make the AI smarter counts. I've started work on a mod. I've only done one thing so far, in a couple of hours, but it does tell me that progress is possible.

I've never seen the AI win a cultural victory... never! So I figured that would be a good place to start. The AI should at least have a chance of beating other AI to victory with utopia. It involves changing economic/scientific/social systems of the AI, which are significantly easier to mod than tactical systems.

So the only changes I've made so far are to set up what I call tech path "slingshots" for AI players that have culture flavor. They have little garden paths which make the AI more likely to enter them, and once entered, the tech sequence is virtually locked in. The first such "slingshot" puts a high priority on Education and Acoustics. The next "slingshot" simply puts a high priority on Architecture. The third "slingshot" puts a high priority on Astronomy, Navigation, and Archaeology. And the fourth such "slingshot" puts a high priority on Scientific Theory, Electricity, and Radio. In this way I'm hoping that the culture player beelines Opera Houses, Hermitage, Museums, and Radio Towers, preferrably in that order.

I loaded up a game on a standard size large island map, deity level quick speed, and the results were:

T83 Sistine Chapel
T95 Taj Mahal
T108 Louvre
T130 - Egypt hits Modern / Radio and has at least 3 of 5 trees
T136 - Eiffel Tower
T174 - at least 4 of 5 trees for Egypt
T187 - somebody builds hubble
T195 - Rome gets 4 of 5 trees (possibly also pursuing cultural)
T212 - Japan gets 4 of 5 trees
T222 - Egypt wins a cultural victory. This is roughly 330-340 turns on standard.

Spoiler :
34ozvh4.jpg


So I will be doing more to improve the cultural AI strategy and then move on to improve the spaceship and diplomacy strategy. Then I will want to make general purpose improvements of the economic/scientific/cultural variety to the offensive AI and for AI without any victory goal.

I will also go for the low-hanging-fruit that is the AI's valuation of strategics/luxuries/gold per turn and offering of extravagant peace deals.

If I do find a way in to the mess that is the tactical AI, I may do something there too, but I have no idea whether I can and will.

Basically, in this thread I would like to hear constructive ideas on how to improve the AI as modders. This would be very useful to me. I'd love to hear anything people know, even if it is old news.
 
I've mentioned this before, and I'm not sure anything can be done about it without a DLL mode, but the concept is simple;

Currently the AI doesn't value at all your empires production capabilities, or tech, when evaluating whether to DoW. It just looks at your army size and gold. This leads to many suicide missions by an AI that is behind in tech and can be easily out produced and pushed back in a dozen turns or so. I also don't think it takes into account the defense strength of your cities.
 
So far all I've done are some technology tweaks, policy tweaks, and grand strategy tweaks, playing with flavor values. In the last game Rammy did a T200 quick speed culture victory. The AI went Liberty, Tradition, Rationalism, Freedom (switching to culture strategy), and finally Piety. He got late-game wonders like Christo Redentor, so I find this interesting as a kind of emergent property of the system, or even as just a lucky accident, because people don't play this way.

I still need to continue these tweaks and also add some building fixes, specialist fixes, and great people fixes. I'm using FireTuner to watch the AI play and have a few observations.

(1) Rammy got lucky because he had snow! The snow gave some open ground for the great artists to land on. Otherwise great artists will wander around for hundreds of years so that they don't disturb improvements. This needs to be fixed. The same thing happens to great engineers (and I never see them rush wonders).

(2) The AI has no idea where to place the Hermitage and the National College. 99% of the time the best idea is the capital, but 95% of the time they end up somewhere else. I need to figure out how to tell the AI to put these national wonders in the capital, without actually changing the rules of the game.

(3) Specialists are handled poorly, obviously. What may end up being the best solution is making a check with LUA every turn to adjust the specialists "manually."

I have no idea how to do this and would appreciate any pointers (the same goes for the other two things above).
 
I've mentioned this before, and I'm not sure anything can be done about it without a DLL mode, but the concept is simple;

Currently the AI doesn't value at all your empires production capabilities, or tech, when evaluating whether to DoW. It just looks at your army size and gold. This leads to many suicide missions by an AI that is behind in tech and can be easily out produced and pushed back in a dozen turns or so. I also don't think it takes into account the defense strength of your cities.

Hm. Now I remember why they didn't add productive qualities into the game. The human does not have access to this figure (until the production popup appears) therefore the AI cannot know this (as that would be cheating)
 
Hm. Now I remember why they didn't add productive qualities into the game. The human does not have access to this figure (until the production popup appears) therefore the AI cannot know this (as that would be cheating)

Most of the AI decisions are informed by the same "advisors" that the human has access to (or the formulas represented by their advice). What would happen is that the economic advisor would say something like "the Roman empire has over twice our production, we must fix this!" And then the AI and human would both have this info.
 
I lol'd at this comment in the C++ source code:

// If we somehow got to 5 branches...

It seems like the developers understood how bad their AI were at culture vics. :D

LOL, later in the same file:

// if by some fluke we are very close to winning the election, by all means switch focus
 
I lol'd at this comment in the C++ source code:

// If we somehow got to 5 branches...

It seems like the developers understood how bad their AI were at culture vics. :D

LOL, later in the same file:

// if by some fluke we are very close to winning the election, by all means switch focus
It's like you can feel the developers soul slowly dying as they code. lol
 
I like this. Please let me know if I can playtest any of this for you.

Thanks. I will definitely need playtesters once I have enough done that I feel most people would notice the difference from the standard AI.

Today / last night I struggled with something I called "libraries everywhere," which forced the AI to build a library ASAP in every non-capital city. Finally got it working (mostly difficult due to undocumented API). This is part of a general scheme to get the AI to get more use out of the National College and off to a better start technologically. I decided to extend this to "infrastructure everywhere" so that the build order of buildings in cities is semi-predeterimined. Something like Library, Monument, Water Mill (if allowed), Granary, University, Lighthouse (ditto), Workshop. To make this work, I would have to allow some military build orders through as well, of course. It's not too hard to check if the AI is building a unit and leave the city alone if so. I could also have some logic for ignoring the unit order, like if it takes a very long time, or letting through partially completed buildings or letting happiness buildings complete.

Today I want to start coding something I call "rubber band technologies." The AI will go very aggressively down military techs if they are in a war, and this is fine, up to a point. At the extremes, Napoleon will research Gunpowder before Writing. So I went to establish certain technologies as "rubber bands," so that if the AI stretches to these before going through the science techs, they get pulled back into a tech bee-line, much like a player would, say, rush for Education after getting Machinery/Gunpowder and not continue on to grab Chemistry before Education. This will break compatibility with anything that alters the tech tree, but my project really would be an order of magnitude harder if the policies and technologies were not fixed.
 
I decided to extend this to "infrastructure everywhere" so that the build order of buildings in cities is semi-predeterimined. Something like Library, Monument, Water Mill (if allowed), Granary, University, Lighthouse (ditto), Workshop.
I'm guessing the 'hard core players' don't use mods, but I know when they do they tear up stuff like this - once they know the AI is being forced down path X, they figure out how to abuse the crap out of that lol

Not saying it's a bad idea, just curious about flexibility and how that will turn out in play testing.

But, as a wise person once told me; build what *you* want to play :)
 
Not saying it's a bad idea, just curious about flexibility and how that will turn out in play testing.

Yeah, a lot of my design philosophy has been that a generally good choice is better than a random one. There's still a lot of random left.

I don't think it's possible to write a good prince-level AI, but I do hope it'll take people out of their comfort zone. Of course, I'm curious how it turns out too. We'll see!
 
The AI is also a crazy daft wonderwhore, for the most part. I need to put in some of the same kind of checks players do as to whether they have a real shot (tech lead, production capability). I don't think all the AI's doing Great Library at once is helping them.
 
You could extended to them the same information Wonder Race provides players (you are being beat to a wonder, or you are beating another player to a wonder). Then they can do something about it; e.g. change their city focus, switch to produce some other thing, etc.

I've gotten some (a very small number) of complaints that it's giving away info people shouldn't have...e.g. cheating, but I think that's kind of silly since that info is given you when you lose or win the race now anyway (The Great Library has been built in a distant land - and I know that how, if we want to be all non-cheaty?) To me, the 'cheat' is already there. Exposing it just made sense.
 
While I think there are some exceptions, the AI mostly plays with the same information that the player does. I'd like to keep that design philosophy. My project is to make a smarter AI, not an AI that is granted additional raw power (whether omniscience or any lesser form of it).

The player knows a lot from demographics, so something like that may be taken into account, and then only to remove some of the more obvious cases (30+ turns late to renaissance or later era, or not able to build the Great Library before another AI/player, for example). Just trying to save some hammers for some of the AI... some of the others will hopefully risk it, to get an advantage and keep the player on their toes.
 
I finished putting together my "rubber-band technologies" code. Based on triggers for reaching certain technological progress points, which are a bit further down on the tree than the science techs themselves, the game will steer the AI towards Writing, Philosophy, Education, or Plastics. I felt it better to leave Scientific Theory to be discovered naturally.

The game will flip a coin when doing the detour to Writing and to Education. If heads, the game will do horseback/math/construction (based on its own die roll) before writing. If tails, it will do one of these immediately after writing. Certain civs will have the military tech hard-coded (such as Horseback Riding for Greece and Iron Working for Hiawatha). Construction is twice as likely as horseback riding or math, and it is also researched for any civ that doesn't have it when doing the Philosophy detour. Once again the same mechanic will roll dice to research Chivalry/Machinery/Physics before or after Education. And once again certain civs will have overrides on the military tech of choice, with Steel and Gunpowder as the military techs only for civs like Japan and America. Finally, for the industrial era units granted to Sweden, Russia, and Austria, they'll bee-line them after Education. I also told Babylon to go Writing first (silly Nebby).

I decided to make the infrastructure order much more freeform, apart from putting library first. Instead I'd like simply to block out certain buildings, like barracks and garden, if clearly better buildings are available. I'll use a CanConstruct event handler to modify this for the AI.

I just observed a game on King level where Hiawatha launched a T224 quick (~336 standard) spaceship. I'm pretty amazed at how much it is possible to do with so little changed. If nothing else, this will make it more of a time crunch to win before the AI.
 
I'm not going to have time to work on this again until Friday, so I've decided to put up my very early work to get some very early feedback, criticism, and suggestions. You should expect bugs (try to help me identify them), and there is a lot to go. Things on my TO-DO list that are not in yet:

(1) Logic for controlling AI great artists, scientists, and engineers (e.g., Nebby seems to always pop instead of plants his first GS)
(2) Better tweaking of the variables of the grand strategies
(3) Further economy/build tweaks
(4) Wonder-hammer-conservation techniques
(5) Diplomacy making AI stingy on gold and especially lump sum gold
(6) Anything remotely tactical

Things that are in there (still experimental!):

(1) Rubber-banding technologies, herding AI back on to the science tech path if they stray too far
(2) Libraries everywhere, making the AI build libraries first in non-capital cities once they can, up to the point where they have National College.
(3) National College and Hermitage build in the capital as soon as they can be.
(4) Lower priority buildings (barracks, etc.) don't get queued before higher-priority buildings (monument, etc.). If there's a unique building replacement, though, it is allowed to be built.
(5) General tweaks to the policy trees, mostly to force Collective Rule, Representation, Free Thought, and Planned Economy down the throat of most AI (the rest should go Piety or Freedom as their alternate branch for culture).
(6) Several modifications to the culture grand strategy flavors, which probably need to be re-modified (I am curious whether I made it too likely a VC to pursue for the AI).
(7) Make the AI use scientists more, or artists if going culture (this clearly is buggy at least because the AI often overrides this with its focus setting).

Please feel free to download it, play with it on your favorite difficulty setting, and let me know what you discover in your playtesting. Your feedback at this early stage is fuel for future development. :)
 

Attachments

Download and looked this over. I'm impressed with what you've done so far. A lot of work and some impressive results. I haven't tried using it yet, but I will be watching with interest. I remember the old WWGD mod that wasn't nearly as complex, but had the idea of making the AI more likely to be less hostile. It got rolled into CivUP then the original mod appears to have died. So, this is welcome and needed IMHO.

The code looks well designed and written also. Nice work all around :)
 
Is there any way to code better teching without hardcoding techs into it?
 
Back
Top Bottom