A Better AI.

Blake

The AI Guy
Joined
Feb 18, 2006
Messages
342
Location
Apolyton
Better AI information:

Please head over to and use the New Better AI Sub Forum.


Sourceforge Project (Downloads for Warlords and Vanilla).

Better AI improves the AI's decision making, enabling the AI to put up a stronger game with less reliance on handicaps and ultimately to play a balanced game more like a human. Better AI improves nearly every aspect of the AI, for example the AI is capable of pursuing Cultural Victories and militarily it is far less of a pushover. It falls into less traps than the normal AI, with superior research choices, the Governor functions are improved for both Human and AI players, the Automated workers are also improved for both Human and AI.

Gameplay compatibility is preserved with the exception of a few bug fixes and other "Grey areas", the most noteworthy being the starting point code, Better AI eliminates very close start points and generally makes starts a bit fairer or less absurd (in a nutshell this is because the starting point code was inadvertently changed in Warlords patch 2.08).
Save game compatibility is also preserved, you can thus start or stop using Better AI at will.

Installation:

Better AI is contained entirely in the CvGameCoreDLL.dll file, it is the only file you need.

To use Better AI for all your games place the DLL in your CustomAssets folder:


To use Better AI as a mod, place the DLL in a \Mods\Better AI\Assets folder:


You can tell if you have it installed correctly if you see "=== Better AI ===" in the score breakdown


You see the score breakdown by holding down alt while mousing over your player name in the 'scoreboard'.


Spoiler Original First Post :

Greetings, Fanatics.

I'm sure many have been intrigued by the improvements to the AI in Warlords Patch 2.08, alas there was little time for doing much improvement and the process was hurried. I have continued to improve the AI and fix various AI/Auto Worker bugs and you can now download the updated AI mod for Warlords Patch 2.08 amd Vanilla Patch 1.61.

Why might you want to use this mod? Firstly it is fully save-game compatible (if placed in CustomAssets) and game rules are completely unchanged. The change log includes some interesting improvements:

- Fix to irrigation chaining bugs which would result in the AI farming excessively and flip-flopping between farms and cottages.
- General worker unit AI improvements to make them more flexible, they will also stack.
- Auto workers now come back and road up resources which had been built before roads were available.
- Workers are now less fearful of enemy units, they should only run away if they are in actual danger of dying.
- Tweaks to auto workers to achieve a better balance of hammers, they should build more mines now.
- Code to add awareness of jungle chopping when choosing research.
- Great People usage improved, the AI should be less Golden Age happy, only starting one if it’ll actually pay off compared with lightbulbs/settling.
- Great Prophet Shrines valued a little more accurately.
- Great Merchant cash bomb logic added.
- AI's will now spend gold to perform deficit (100%) research and will decline to trade gold reserved for such research, enabling them to make better use of gold boons from huts, plunder, refunds, great merchants, etc.
- AI Missionary code adjusted - both when choosing destination and when determining the number needed.
- Awareness of freebie promotions (such as Aggressive Combat I, or Red Cross Medic I) when choosing which unit to train.
- The AI will now chop Wonders and will chop to assist a war effort.
- The AI will no longer pillage Barbarian Cities.
- City Founding logic has been improved, a bug was fixed which could "force" the AI to found on top of resources that it otherwise wouldn't, the AI is also aware of existing culture (it's own) making tiles workable.
- City Founding logic has been diversified, Creative leaders are more "Greedy", grabbing as many resources as possible per city, Organized leaders are the opposite, being more inclined to found cities right next to resources and founding more cities overall.

I now have a Sourceforge project page for source control and distribution, thanks to Iustus of CFC/RBCiv. My intention is to use that for distribution of date-stamped test builds, once a build has been confirmed to be mostly stable without crashes or glaring AI flaws it will be given a version number and uploaded to the major Civilization Sites mod repositories. You can help in this process by testing, both reporting things which appear broken and things which do work, of particular value would be experience on larger maps. I would greatly value any report of experience, even if it's as simple as "I played out a full game and didn't notice any problems". Save games, especially from later in the game (ie before a world war, entering industrial era...), would also be quite useful as testing grounds.

A Vanilla Build is now available, I work on Warlords and the changes are integrated back into Vanilla.

Link to the Sourceforge Project.

Iustus explains how to get the Source via SVN.

Link to the Original Thread at Apolyton.



Enjoy,
Blake.

PS. For feedback and stuff, this thread is as good a place as any for now. I'm also crossposting this over on Poly and will check both threads.
 
Your improved AI in Warlords 2.08 is just great.I was achieving some victories at prince level before your AI improvements and now i'm stuck at this level and it's unlikely i will go to monarch now.I hope your successful efforts to improve AI will be noticed by firaxis for future civ games.
Thank You
 
I cannot find a custom assets folder, just an assets folder with Python, XML and other folders thierin. Where exatcly should I be extracting this file to?

Also the link has two files to download, should I download both of them?


Oh and thanks Blake.
 
Same question as phungus420.

Any instruction on what exactly to do, since I've never used a mod in my life.

Do we need put all the extracted files together in one folder in custom assets? ;o
 
There is just one DLL file and a readme.
You should put it in Custom Assets folder, which is in "My Documents\My Games\Warlords" folder.

P.S.
My Documents could be called something else, depending from your user name in Windows.
 
While these AI improvements are very impressive, the AI is improved so greatly that one wonders if it's reasonable to play against it with mere Monarch penalties/bonuses, let alone Emp/Im/Deity penalties/bonuses.

To put it another way: the more intelligent the AI becomes, the more overwhelming the AI handicaps become. Even without these further improvements, the 2.08 AI is tearing up on Prince.
 
Awesome work, Blake! As I see it, the AI still remains CivIV's achilles heel(although I am proud of firaxis finally firmly addressing the problem as of the latest patch). So I am hoping to see your project go the rest of the way to address this, good luck to that end. By the way, you don't exactly state whether you will at some point start addressing overall strategy as well as tactics, as in the AI launching lengthy military campaigns...are there plans for this? I hope so anyways. I can only drool at the possibilty of my enemies' forces becoming a serious threat at equal or lesser numbers, rather than just a slight hindrance to my eventual domination.

And I agree with Zoolooman, as this mod progresses the need for handicaps will only diminish. Maybe they should be readjusted so that at the lesser difficulty levels, the AI gets large negative bonuses to nerf it for beginners? I would love to actually have the positive bonuses dissapear completely, actually, if that can ever be possible. Really having a completely non-cheating AI that is still very challenging would be the ideal scenario.
 
I agree totally with this last post. Tweaks to the AI are great...but it sure does a number on your understanding of the game and the difficulty levels. Just because now I have to go from monarch to prince or noble...How has that improved the game??Does the AI now have too much of a helping hand at monarch and higher. A truly balanced game would have no need for such rudimentary leveling tactics.
 
While these AI improvements are very impressive, the AI is improved so greatly that one wonders if it's reasonable to play against it with mere Monarch penalties/bonuses, let alone Emp/Im/Deity penalties/bonuses.

From reading the original AI improvement thread my understanding is that the ultimate aim of Blake's project is to make the AI challenging enough that the human player doesn't need to give it bonuses - to make it so that higher difficulty levels are unneccesary.
 
Thedrin said:
From reading the original AI improvement thread my understanding is that the ultimate aim of Blake's project is to make the AI challenging enough that the human player doesn't need to give it bonuses - to make it so that higher difficulty levels are unneccesary.


The only levels needed would be to lower the difficulty of the AI to give the human a better chance, so that effectively a even playing field would be the hardest highest level and that only the very best human players would be able to compete with the AI in this setting.

As it should be, like good Chess programs.

Zoolooman said:
Even without these further improvements, the 2.08 AI is tearing up on Prince.

Not in any of the games I've played, or been witness to.
 
drkodos said:
Not in any of the games I've played, or been witness to.

The AI is still a horrible warmonger. However, it has become a fairly effective builder. This means that I can't play Prince difficulty in a "lazy" manner.

Edit: Blake, I've got a question. Have any of your improvements attempted to alter the tech-trading behavior of the various Civilizations? Currently, it *seems* like there is an AI conspiracy to trade fairly amongst themselves while they deny trades to me (or ask for absurd deals).
 
Excellent work Blake, I'll be keeping a close eye on your changes.

Edit: Blake have you labeled you code changes in the .cpp and .h files? I would like to merge your AI changes in with other changes I have made. Thanks.
 
Zoolooman said:
The AI is still a horrible warmonger. However, it has become a fairly effective builder. This means that I can't play Prince difficulty in a "lazy" manner.

I concur.


Long term strategic thinking is the bane of all AI. The only way that IBM was able to beat Kasparov with the computer was to have a human being give the computer some stealth help. The computing power of the AI is always superior, but it still cannot think strategically, which often calls for counter-intuitive thinking and planning. Knowing when the odds do not matter and one should plow ahead regardless only comes from wisdom, not intelligence.

It is also good to know (as a human) that illogic has it moments when it produces the best results and that the sci-fi idea of being controlled by the machines we build is still very far in the future.

I hesitate to even call what CIV has an AI. Intelligence learns from experience. That is the definition of intelligence. A true AI actually learns and makes better decisions all on its own based on the experiences it has had. I do not see that happening in this game anytime soon.

To me, it is more a simple computing engine than an artificial intelligence.
 
I think the changes to the AI so far only make aggressive warmongering even more essential. Not good in promoting different ways to play the game.

It's a good job, so congrats on that :goodjob: But unless adjustments are made to accommodate the changes, I fear I will only lose interest in the game after installing the new patch. And not installing the patch just feels wrong because I'd be out of step with the public when discussing the game in these forums. Maybe you can help Firaxis make the adjustments for a future patch? :D
 
[Repost of What I said on Poly]

First thing: Usage.

The zip you need is the one not containing the word "Source", the source means source code - you don't need that as a user.

In the zip you'll find a folder called BetterAI and inside that folder you'll find CvGameCoreDLL.dll. You can either place the betterAI folder inside your Mods folder then load it as a mod in game (using Advanced Menu), or you can take the CvGameCoreDLL.dll file and place it directely inside your CustomAssets folder (not any of the sub folders), which if you go to My Documents should be:
My Games/Warlords/Custom Assets/

To return to normal play simply delete the CvGameCoreDLL.dll file.

Both methods work equally well, I reccomend using the mod method if you use other mods, and the Custom Assets method if you don't play with mods.



Okay other things mentioned many times...

Difficulty Levels:
The first thing I want to point out is that my mod primarly addresses the mid to late game AI incompetence, where the AI starts to spin it's wheels and not go anywhere, like the AI couldn't make use of Biology at all. It is not much harder at the start of the game, I mean sure, I improved some things like workboat and worker gettage, and I've ensured the AI wont be left without critical techs like Pottery or Iron Working (if Jungled). The main thing, is you can't rely on the AI stagmenting, it's not enough to get a lead at one point in the game then sit on your laurels, trusting the AI's to stagment. Now the AI's can leverage many more techs and gain an advantage.
You certainly need a REAL edge to beat the AI's at Monarch+, you can't just rely on their incompetence to be their undoing. For example you can use smart wonder usage, or you can use the crutch of warmongering, altough I've noticed the AI is certainly capable of bogging down an invasion under sheer weight of units (and now I've made them chop during wars, yikes...).

My long term plan is to tie play style to difficulty level, there's a few things which could change by difficulty level. Firstly, the skill in taking cities, a higher level AI would only attack when it knows it will win, while the lowbies will continue with "lemming attacks" (or as I like to call it, "Whack a mole" gameplay). Other possibilities are things like city placement, with the higher level AI's going for more cities overall (I've noticed newbie players tend to place cities far too spread out). Also chopping and whipping tend to be used more by skilled players and I might make the AI do that.

For now, the advantage gained, is that the game is more "balanced" - it's no longer just an early game where you gain an advantage then cruise to victory. You can lower the difficulty level, and I hope, have a more interesting later game. Also I'm also adding more variety in the AI play styles, you'll probably recognize this the first time you see an AI switch to Pacifism, or if you download my new mod, when a Great Merchant appears on your borders - in other words, not only have I made the AI play stronger in the same way handicap bonuses do, I've also taught it new tricks.


Another topic: Tech Trading.
I have not changed this other than making them put a higher priority on Alphabet (in one monarch game I played every AI had alphabet by 1AD, I didn't, yikes, but that's an exception not the rule). The AI's have generally far better research power. With my newer mod, not only do they have the stronger economy, they can also leverage gold boni into research, what's more they no longer squander Great People, meaning they might use that mid game GS to pop Education and thus win liberalism rather than wasting him on a GA, the AI who bags the Economics GM will probably use him for a Cash Bomb, resulting in another burst of research. As far as I can tell, most of the AI's higher tech speed is from their sheer researching speed moreso than any change in tech trading - they just really do reserach that fast. My AI seems to have reached the point where on Monarch they research faster than old Emperor AI's, I'm very reliant on tech trading tricks I used to do on Emperor, like Compass for one.
 
Reponses:

upstart said:
Awesome work, Blake! As I see it, the AI still remains CivIV's achilles heel(although I am proud of firaxis finally firmly addressing the problem as of the latest patch). So I am hoping to see your project go the rest of the way to address this, good luck to that end. By the way, you don't exactly state whether you will at some point start addressing overall strategy as well as tactics, as in the AI launching lengthy military campaigns...are there plans for this? I hope so anyways. I can only drool at the possibilty of my enemies' forces becoming a serious threat at equal or lesser numbers, rather than just a slight hindrance to my eventual domination.
Okay I'll state that I do plan to add better strategy and tactics altough this may be limited with save game compatability. Sooner or later I'll get around to adding new city attack logic. At that point a human will be hard pressed to stop an AI like Napoleon from smashing right through their empire, mainly because the AI wont actually engage in combat unless it can already win, it will be evasive and only strike when it has local superiority, no more suicidial smashing of attack forces against city walls.

The AI will use a basic attack approach like this:
1) Get a stack bigger than the enemy can kill.
2) Park it next to a city on a defensive tile if possible.
3) Blast the city defenses down to zero (skip turn for other units).
4) Soften the city up with siege or low exp units.
5) Kill the defenders with the best city attackers.
6) Move in if it wont split up the stack too badly.

The main problem will probably be getting the AI's to defend against such brutal tactics, I would give an AI like Gandhi no chance of survival against Napoleon, if they start together (just like Gandhi has no chance of survival against a human attack). So the game will end up with small, fast teching peacemongers like Mansa Musa, who manage to avoid being the target of a warmonger, then all devouring and conquering monsters like Napoleon, Caesar and Alexander, killing off their neighbours and building a massive war machine. Human strategy will be a matter of out-racing the warmongers to domination, or trying to tech to space while avoiding the wrath of a warmonger (since even if you survive, the war would be very punishing).

cf_nz said:
Edit: Blake have you labeled you code changes in the .cpp and .h files? I would like to merge your AI changes in with other changes I have made. Thanks.
Nope. You'll have to do a diff (ie WinMerge) against the stock 2.08 SDK or maybe 2.00 if you're talking about merging into 1.61.

I tend to make changes all over the place so the labels would get really quite messy.


drkodos said:
I hesitate to even call what CIV has an AI. Intelligence learns from experience. That is the definition of intelligence. A true AI actually learns and makes better decisions all on its own based on the experiences it has had. I do not see that happening in this game anytime soon.

To me, it is more a simple computing engine than an artificial intelligence.

"The real question is not whether machines think but whether men do." ;).

In my opinion, CIV4 is relatively formulamatic. You can use formulas for developing cities, for sieging bases etc. I have a mind which is good at seeing the formulas (ie I try to reverse-engineer intution) and can I thus have little trouble teaching the AI the same formulas for success. The Pinacle of CIV gameplay seems to be learning all the formulas for everything. Not that much about CIV is fuzzy, hard logic tends to rule.

Where the AI is fundamentally most lacking is co-ordination, things like slingshots, or bringing in war allies... in short, the AI isn't good at timing stuff, it's not a good puppet master. I think the AI can learn tactics, it can learn strategy. It'll have the most trouble with metastrategy.

What I certainly don't agree with is that the AI has to do it's own learning. Humans share experience an awful lot, often in the form of rules of thumb and such. like "If you're boxed in you'll probably need to go to war to acquire more territory", what is the difference between learning this the hard way, and just being taught you need to bust out from such a sitution?

I do agree that it's not really an AI, it's more accurately described simply as a Computer Player, as opposed to Meat Players.
 
Blake,

I opened a thread on it but would like to see your opinion on it
and perhaps this belongs to this "better AI" topic:

So

When on auto-pilot, or AI:
do the workers take into consideration when working for a city
that what the city governor's emphasies are set to?

Thread:
http://forums.civfanatics.com/showthread.php?t=191739
 
Does this change any of the AI controlled player side, like worker automation?

Was wondering because in a couple of games I was also seeing the workers doing the chain farm thing when on auto.

And does it have any effect on what the advisors suggest (which is often useless anyway, but...).
 
Top Bottom