Once more: FFH and the AI

Bringa

King
Joined
Jan 23, 2006
Messages
678
New AI Minimod ==PROOF OF CONCEPT==

So,

you've got about 12 hours to go until the launch of fire and you don't know what to do with yourself? I've got an answer: play with this!

Is this really a new AI? Hell no. I've hardly changed a thing. I've very carefully touched the bestTech function (the function the AI uses to decide what to research next), and most of my work consisted of changing XML files. I've added eight new flavors and I've given all leaders, techs, buildings, and units flavors where appropriate. Generally my aim was that the Calabim should actually beeline for Feudalism and build Vampires, that the Luchuirp should beeline for Construction and build sculptor's studios and build golems etc. Also, a minor goal was to get a little bit of roleplaying "realism"; for instance, the elves are more likely to go down the archery or recon line now. Finally, I've told the AI not to research magic related things for now. I know, the AI DOES use magic, but my argument is that it doesn't do so in a satisfactory way. Essentially, the AI still handicaps itself by investing bulbs and hammers into magic-related things. I've not disabled the techs, but I've put heavy negative weights on them.

The result is, to me at least, a much more competitive AI. Whereas I'd normally win on Emperor without much trouble, I'm now hard-pressed to survive a Monarch game beyond year 150 (unless the AI really likes me ;P).

I've called this a proof of concept because I consider none of this final. I'm not a good coder, and I'm not a patient planner either, so I've hardly touched the source code and I'm sure my XML modifications are clumsy, to say the least. I'm not proposing that anything in this is actually taken into FfH. All I'm trying to show is, here, this is how it could feel like if the AI performed just a LITTLE better. I'm trying to proof that there's a real need for improvements to the AI (and, well, I've convinced myself: it's a hundred times more fun to play like this to me)

Here's the file:

FfHBetterAI004.rar

It contains:

an xml folder with lots of changed stuff
a CvGameCore.dll (for some reason, I get a bigger .dll than the one that comes with FfH. I swear I didn't put anything nasty inside; I did leave my debug statements in there, so if you notice a significant slowdown, make sure you've turned off logging in your ini. I never noticed any slowdown, but you never know) (I guess you can do without this; the changes in here are minimal and the changes in the xml depend in no way on the changed .dll)
an FfH Editor.xls (this is the Excel file I've been using with the new flavors, in case you want to experiment some more. You'll need to copy it into your main Fall From Heaven 2 016 folder, but do make a backup of the original. I've also prettified the VB in some of the sheets (where there wasn't too much ;P). I don't know who had the idea to put a ' into every empty line, but it looks butt-ugly. Also, there's no law against indenting VB ;P)

Make backups of everything you overwrite and then play a game against the AI on your usual difficulty. I'd love to hear how it went.

(I do realize the silly timing; after Fire comes out I don't expect anyone to play with this, but I'll be working on porting my changes to fire as well)

Spoiler :

Hi,

yesterday, out of sheer boredom, a friend and I tried to play a game vs 2 AI. We played on Emperor level because that's normally the best we can manage. Also, recently we've started playing without barbarians again because the phase in the beginning of the game where essentially you spend your entire time fighting back barbarians and rebuilding improvements they pillaged bored us a lot. (This wasn't the only reason why we decided to play without barbs: in an earlier game vs 2 immortal AI with raging barbs on, one of the two AI died to barbs halfway through the game; very, VERY unsatisfying to play) (btw, is there a way to open a multiplayer game in the world editor to undo little annoying things like that when they happen?). We tore the AI to pieces so easily it wasn't even funny. Sure they had lots and lots and LOTS of units, but by the time we hit axemen (slash swordsmen since I was playing Ljosafar) they had NOTHING on us. They kept crowding us with countless warriors (even though they most certainly did have copper) and we leveled our axemen and then proceeded to steamroll their respective countries in no time at all. There was a sort of a challenge to survive early on, but by the time we hit axemen and they just DIDN'T build axemen, it became a travesty.

So I decided to have a look at our performance of one of us vs 1 AI on Emperor. My friend lost three games, but that was probably due to bad placement and other bad luck, and I got kinda stuck in one game because I was having so much fun, but won that game very easily. In that game I noticed the same thing again: the AI had copper, and they WERE running around with crossbowmen and stonewardens, but still, three of their four expansions were guarded only by a number of WARRIORS. By that time I had Rangers and assassins, so really warriors didn't mean anything anymore.

How DOES the AI decide what troops to build? Do they always go for the highest strength unit available? Do they make sure to connect expansions to the capital so they can build the fancy units in their expansions too? I would really like to understand WHY the AI performs so badly in this mod.

Also, maybe our playing without barbs affected the AI's performance? Then again, I have played a number of games with raging barbs and aggressive AI on Emperor where the AI was wiped out by barbs, and that's just no fun at all.

I would also like to know what settings everyone plays at and how challenging they find their games.

I keep thinking if there's something that could be done about barbs that would make them a little less annoying (to ME; I'm very much aware of the fact that this is personal bias and probably not shared by anyone else since from what I'm hearing everyone seems to be enjoying the barbs just fine) and maybe Fire's introducing of the Doviello mechanic for all civs (as hinted at by Kael in another thread; everyone will get to build *weak* axemen without copper and have them upgrade with access to the metal) will help already. Generally I do enjoy hunting barbs for xp, but when it becomes a question of micromanaging my high-level warriors so that I lose the smallest number of improvements per turn, it becomes really tiresome.

But now I'm rambling ;)
 
How DOES the AI decide what troops to build
?

This is a pretty complex question. The end function is CvPlayerAI::AI_unitValue, but by the point that this function is called, the purpose of the potential unit has already been determined, most likely from CvCityAI::AI_chooseProduction.

Now, making the assumption that you're primarily worried about City Defense, here's the rough breakdown:

To be considered valid for UNITAI_CITY_DEFENSE, the unit must have the following:

1) Combat strength.
2) The ability to accept defensive modifiers.
3) A positive city defense modifier.

Note that this alone is a good chunk of the problem. Valid units include: Archer (and variants), Gilden, Heavy Crossbowman (and variants), Longbowman (and variants), Maros, Orthus, Gargolye, Shield Wall (and variants), Warrior (and variants).

So basically until that AI researches Archery, it will consider the Warrior to be the optimal city defensive unit for the purposes of building in most cases.

At that point, the value of any potential unit (that passed the above tests), is evaluated in the following fashion:
1 +
The AI weight for the Unit (from the XML file) +
1/2 the unit's combat value +
the unit's combat value * its city defense modifier %

It will try to build a city defender if the Plot of the city has no defenders.
After it has met a human, if there are no units of AI Type UNITAI_CITY_DEFENSE, it will try to build a city defender (this is lower priority).
At a far lower priority, it will try to build such defenders for Settlers it plans to send out.
In general, City Defenders are considered more valuable the more cities that are in the given area owned by that player.
The lack of the City Defender is one of the higher reasons to rush production (lack of a unit appears to be the highest).
 
I would really like to understand WHY the AI performs so badly in this mod.
There are lots of reasons. Fundamentally, Civ IV has a weak AI that is designed towards a single strength: speed (of execution). The major changes to the tech layout, the importance of resources, and the types and usage of units, as well as prerequisite buildings mean that the already weak AI is even weaker.

What we're going to have to do at some point is to start a concerted effort to improve FfH II's AI. If no one else has started to take a serious stab at it within the next couple of months, I likely will.
 
actually what I understood (but I was merely flushing through the .cpp-files) is that the AI is not building an 'army' but merely sees all units as individuals for special purposes, so basically they do not really 'combine' units and they do only plan for war if they want to go for war.
The simple tactic : 'Attack is the best Defence' that we humans like so much is simply not occuring to the AI at present stage.

So that is the problem with the current setting. The AI is doing an excellent job in outbuilding you, they are choosing techs quite reasonable and they already do a quite good job in settling territory. But they miss overall strategy .. or better .. they do not play for victory ..
Things like war for critical resources, things like the whole concept of 'critical' resources, things like 'punitive expeditions' into the barbarian lands, things like building up an army by using it (experience), things like building up an army of artillery, cavallery, infantry, support.. all these things are missing..
 
It's true the AI doesn't play to win, which is in many ways a problem, but I think many people don't realize that it's also a blessing. An AI that focused on a victory in the way a human would would be very difficult to beat, even on low levels. More importantly the game wouls lose much of it's flavor. As a computer the AI is naturaly much better a squeezing efficancy out of cities, it can crunch all the numbers and find the exact maximum output for a city. I know there are some of you out there who enjoy this sort of thing, but given a direct objective I'm pretty sure the Ai would be much better than you at it.
However, I agree that the AI lingers with warrior defenders far too long. Perhaps if the Ai value of a warrior for city defense was signifacantly lowered it would push the AI to find alternatives and use them ASAP?
 
I also just finished a game, where the AI's had only warriors for defence. It was against 5 opponents and ridiculously easy. Didn't even have to use siege weapons, just a bunch of experienced swordsmen and mr. Bambur (somewhat overpowered with combat V + Heroic str. II = 16str). The difficulty setting was monarch, which usually is enough to be a bit challenging in regular civ.
 
To be considered valid for UNITAI_CITY_DEFENSE, the unit must have the following:

1) Combat strength.
2) The ability to accept defensive modifiers.
3) A positive city defense modifier.

In Rise of Mania archers don't get +50% city defense but +50% versus melee. Yet the AI likes archers better than warriors. So are you sure this positive defense modifier is an absolute requirement, or is it just a part of the general formula you mentioned a little lower?

Anyway, could this mean lowering or removing the city defense bonus of warriors would actually increase AI performance?

What we're going to have to do at some point is to start a concerted effort to improve FfH II's AI. If no one else has started to take a serious stab at it within the next couple of months, I likely will.

I'm always willing to help! I don't know SDK, but I have experience with getting the AI to behave much better from my SMAniaC mod, and I'm a good strategist, so I can offer good thinking patterns to work into the SDK. But I'm wondering, since the FfH SDK changes so often, wouldn't it be practically impossible to keep your own DLL up to date?
 
Obviously what an FFH AI mod would do is to work off the last released SDK. Kael likes to release the SDK when the mod is more or less stable, so probably after the iteration period of Fire (if you happen across this Kael, could you confirm?) But also, since FFH isn't really touching the AI much right now, there would probably not be a lot of conflict.

I, too, would love to help with the AI thing since it's a matter close to my heart. I haven't actually tried to do ANY modding yet but this is simply for time reasons. I am fluent in Python (using it every day at work) and even though I've never used C++, I think I'd find my way around. Most importantly, I'm pretty good at general server maintenance etc, so if we do get a little team together for the AI, I can set us up an SVN server and maintain that.
 
Yeah I have no problem releasing the SDK. I just ask for a week after I release (to give me time to fix bugs) then I will upload the sdk if anyone wants it.
 
In Rise of Mania archers don't get +50% city defense but +50% versus melee. Yet the AI likes archers better than warriors. So are you sure this positive defense modifier is an absolute requirement, or is it just a part of the general formula you mentioned a little lower?
You are correct; I missed the initialization. If this unit is of the correct AI type, it will override the above logic. So assigning the AI types correctly in the XML should override that validity check.

Of course, this still doesn't help the AI in the early game. Looking at the list of units which can have this AI gives a number of units which seem to be bad fits (such as Scout).

Anyway, could this mean lowering or removing the city defense bonus of warriors would actually increase AI performance?
I don't think so; I'd mis-read the code.
 
actually what I understood (but I was merely flushing through the .cpp-files) is that the AI is not building an 'army' but merely sees all units as individuals for special purposes, so basically they do not really 'combine' units and they do only plan for war if they want to go for war.
The simple tactic : 'Attack is the best Defence' that we humans like so much is simply not occuring to the AI at present stage.
I think that you are correct, although I haven't finished reading the AI code by any means.
So that is the problem with the current setting. The AI is doing an excellent job in outbuilding you, they are choosing techs quite reasonable and they already do a quite good job in settling territory. But they miss overall strategy .. or better .. they do not play for victory ..
Things like war for critical resources, things like the whole concept of 'critical' resources, things like 'punitive expeditions' into the barbarian lands, things like building up an army by using it (experience), things like building up an army of artillery, cavallery, infantry, support.. all these things are missing..
Actually, the AI doesn't outbuild, outtech, or out-settle me (and, playing at Emperor, I'm hardly the best player here). The AI Cheats at every difficulty level, but cheats on the majority of things starting at Prince.

Frankly, their Tech selection is horrible; it's one of their fundamental flaws. Simply put, if you don't have Copper, you probably shouldn't be going for the Melee line. It also doesn't specialize (which is optimal in this mod), and it's horrible at infrastructure.

Don't get me wrong- the issues you mention are problems as well.
 
It's true the AI doesn't play to win, which is in many ways a problem, but I think many people don't realize that it's also a blessing. An AI that focused on a victory in the way a human would would be very difficult to beat, even on low levels. More importantly the game wouls lose much of it's flavor. As a computer the AI is naturaly much better a squeezing efficancy out of cities, it can crunch all the numbers and find the exact maximum output for a city. I know there are some of you out there who enjoy this sort of thing, but given a direct objective I'm pretty sure the Ai would be much better than you at it.
However, I agree that the AI lingers with warrior defenders far too long. Perhaps if the Ai value of a warrior for city defense was signifacantly lowered it would push the AI to find alternatives and use them ASAP?

The problem isn't (in my mind) the lower levels (The AI can be penalized into stagnation in any case). It's the mid-upper levels, where the cheats it uses to try to stay competitive aren't that useful without stronger AI to exploit them.

In any case, if an AI change makes the game less fun, it can always be removed (or more likely, never even merged into the main mod).
 
I, too, would love to help with the AI thing since it's a matter close to my heart. I haven't actually tried to do ANY modding yet but this is simply for time reasons. I am fluent in Python (using it every day at work) and even though I've never used C++, I think I'd find my way around. Most importantly, I'm pretty good at general server maintenance etc, so if we do get a little team together for the AI, I can set us up an SVN server and maintain that.

My AI is a bit archaic (I took a number of classes, and created one, but it's been roughly a decade), and my Python is weak (it's not one of my top ten programming languages). C++ is probably one of my 5 strongest programming languages these days. I'd be happy to work on a modmod as an individual or part of a team or a contributer to another's mod to try to improve the AI. However, my time in the immediate future (next several weeks) is extremely limited, and I'm presently also doing work on the Wiki (I'm semi-automating that work, but the Fire changes are likely to set that effort back by a few weeks). Roughly 2 months is a reasonable estimate for when I could start serious work, and even then, it would be in the single digits of hours/week.
 
It wouldn't be much more here, xanaqui, but I think that might be okay. If we have a look around the source together (and I've started doing that as well, just that I don't have any fancy ide for C++ that could look up functions for me etc) (actually I am using Eclipse at work; might give loading the sdk into that one a try) and try to first reconstruct the model the ai currently uses for most decisions, I feel confident that even with only a few hours a week invested we can start making small improvements. I think part of our effort will also be really identifying the AI's weaknesses, and I feel that will involve a LOT of games vs the AI.

Have you given any thought to making the AI understand FFH's magic system?
 
If you two plan on messing around with the AI, I suggest that you first enable cheat mode so that you could see exactly what the AI by pressing Ctrl-z. You could also just let the AI play only by pressing ~ and typing into the console that appears "game.aiplay x" where x is the number of turns you want the AI to play for. Just don't set x to be 500 or something like that because once you start, you can't stop it without terminating the game.
Spoiler :
To enable cheat mode if you do not already know, go into the config file and on the line that says "CheatCode" make sure the entire line reads "CheatCode = chipotle"
 
I've had a look at the flavor values attached to techs and leaders. They don't seem really polished. Some are just exact copies of the vanilla techs even though their content has completely changed. So I think it should be easy to improve AI research strategies a lot by just XML and a couple python changes.
 
I've had a look at the flavor values attached to techs and leaders. They don't seem really polished. Some are just exact copies of the vanilla techs even though their content has completely changed. So I think it should be easy to improve AI research strategies a lot by just XML and a couple python changes.

That would be cool, I would love to see what you come up with.
 
Is there somewhere where I can look up what all the things in the XML files mean?

[edit] Also, Maniac, if you and me already start messing around with this, we might want to document:

1) what problems with the AI we have identified
2) what problems in the source of the mod we have found (flavour settings in the XML that don't fit the tech etc)
3) what we have done and how it has helped so far

I'd suggest a simple system where we can just jot down what we've done/found/etc. A wiki could be the way to go. We could ask the guys from the civ4 wiki if it's cool with them that we make a page for this sort of stuff or else I can host a wiki on my own box.
 
Not being a modder i would like just to know one thing:
I read somewhere that to make AI capable to use spells, should be added new strings to AI.
Considering that also Blake in his Better AI mod hasn't yet touched Spy missions (which should be as hard to code as spells), is there any chance in the future that AI could be made capable to use all the spells efficiently?
 
Not knowing anything about code wrangling, but couldn't a stop gap measure be allowing the AI units stationed in a city to gain XP up to 17. This way all AI warrior defenders would be lvl4 and be much tougher to kill in early stages of the game?

Just a thought...
 
Back
Top Bottom