AI analysis: The first 100 turns

I agree, the hammers already spent are a thing of the past. However, the hammers remaining to complete whatever is being built should be factored in. Let´s say you need two turns to complete a really expensive wonder - but are under attack from a fairly weak civilization. Continue the wonder, THEN produce defenders, or do so right away?: The appearant value should be "benefit" divided by "hammers to complete". So even a fairly small "benefit" could reach a high value, if the "hammers to complete" is small.
So it is not a trivial decision for the AI, and you will find even humans coming to different conclusions. Switch to Archer, and let someone else get Stonehenge? Maybe I have enough defenders after all? If I get a lucky roll, they will hold long enough... but, on the other hand, if I loose that city? Play safe, or gamble? Finish that missionary (I WILL need one eventually later), or put everything I have into that Axemen-rush?

Not a quick fix for jdog to make here, I think.

Janov

I agree. Now that I think about it, when I was talking earlier about factoring in sunk costs, this is more appropriately what I was getting at. Sunk costs in and of themselves should not be a factor in anyone's decisions, but what they do is create a situation where you can expect the same expected benefit from less future cost. So if you have 20 hammers put into a monument, and need 10 more, and you are deciding between finishing that and building an archer, the choice is not between building a 30-hammer monument and a 25-hammer archer, but between building a 10-hammer monument and a 25-hammer archer.

Now, in order to weigh these variables, the AI would have to take actual costs remaining and expected benefits (and possibly turns until payback) into account. The new additions to the BUG mod actually make this quite easy for humans to do intuitively. I go to build a harbor and find that it will net me 2 commerce and 2 health in actuality.

If I wanted to not rely on my intuition for comparing tradeoffs, I could calculate a payback period or expected net return on investment for every build decision in the game. I could reduce the remaining hammer cost of the harbor, the commerce bonus, and the health bonus to some common currency of worth,* and compare the cost to the benefits.

This common currency need not necessarily assign static equivalencies between different outputs. For example, let's say we call the AI evaluation currency "AIgil." We could say that 1 extra health is worth 4 + 0.5x AIgil, where x is the current amount of unhealthiness in the city. So for a city with more than +8 health, another point of health is essentially evaluated as worthless by the AI. Now, let's say we make 2 commerce = 1 hammer = 1 AIgil, just for simplicity's sake. Now, for this city, the harbot costs 80 AIgil. It gives 1 AIgil per turn (2 commerce + 2 health that aren't worth anything in this city). Expected payback period = 80 turns. The AI could compare that to building a forge (-1 health, +25% hammers): costs 120 AIgil, pays back 3 hammers/turn (3 AIgil/turn), so payback period = 40 turns. In this case the AI would opt to build the forge. But let's say the city already has 6 unhealth. Then the forge costs 120 AIgil and pays back -1*(4 + 0.5*6) +3 AIgil, or -4 AIgil per turn. This structure would never pay itself back in AIgil. Then the AI would not build this building.

These numbers are just hypothetical, but what if the AI, instead of following pre-programmed build tendencies, could dynamically problem-solve for deciding its build orders by reducing all building effects to a common currency of worth and comparing?

Of course, to properly do this, you'd have to figure out how to make the equations of worth reasonable, taking into account variables that will make 1 output (food, beakers, happiness, health, espionage, GPP, military strength) more valuable than another. One would also have to take into account things like: "Oh, this city might be earning 1 commerce and 7 hammers per turn right now, but it will be growing into working mostly cottage towns in the future, meaning that the expected commerce at each subsequent year will be {x, y, z...}, whereas the expected hammers at each subsequent year will be {a, b, c...}, and so if I integrate over the timespan of the rest of the game, with respect to a logarithmic discount rate (based on uncertainty re: being able to keep the city, plus the compounding time advantage of money that makes more stuff now worth more than an equal amount of stuff later), then I can expect my market to make X AIgil over the course of the game, vs. the forge making Y AIgil over the course of the game."

This might seem like a truly daunting piece of work (and I am by no means volunteering to flesh it out, :lol: ...for one thing, you'd probably need actual AI memory to have it remember plans to turn city A into a commerce city, etc.), but what I wonder is, over the long term, would it take more work to devise one dynamic problem-solving routine for AI build behavior, or to be constantly tweaking a heuristic model of AI programming? That is, once you have a civ4 AI that can apply a single currency of evaluation to any decision, you no longer would need to mess around with "hardcoded" things like, for example, AI weights for techs. You would just have the AI look and think to itself, "Hmmm, if I researched printing press, I would spend X AIgil to get Y AIgil over the course of the rest of the game, whereas if I research nationalism, I have an X% chance of building the Taj Mahal wonder, which would cost X AIgil but which would give me Y AIgil over the course of the rest of the game." In contrast to: "The programmers gave nationalism a higher AI weight for a warmonger AI like me, so regardless of the fact that, due to the idiosyncracies of this game, I happen to have a huge cottaged empire on an island and no immediate targets, I'm not able to dynamically adapt because I'm hardcoded to pursue a certain tech based on what the programmers thought, on average, would be useful for an AI like me."

(If you wanted to maintain an element of randomness with "AIgil," you could still multiply certain AIgil calculations by some random number in order to make AI decisions random. If you wanted to maintain distinct AI personalities, you could similarly attach certain AIgil multipliers to certain things for certain AI leaders, etc.)

What this would require, of course, would be basically a Manhattan Project of Civ4 programming (you'd need a way for the AI to estimate the remaining length of the game, a way for the AI to remember plans, and a WHOLE bunch of very complicated and co-varying AIgil calculations involving integral calculus), but what you'd get would be an AI that could, in theory, adapt to ANY conceivable circumstance or human-player strategy variation.

Then after that, my ultimate ambition would be to have a Civ4 AI that would log human-player actions throughout every game the human ever played and compile a database of likely human-player decisions, unique to that human-player profile, so that the AI could chuck these human-player probabilities into its equations and actually "learn"(!) to counter specific human players. (You could even momentarily fool the AI by training it with a bunch of games where you always go peacefully wonder-whoring, and then you turn around on the next game and spring an early rush on the AI :lol: ).

Right now the AI tries to think like a human (heuristically) because it was programmed by humans. But the AI doesn't have that mysterious sense of human intuition, so the AI often fails at this imitation (although is still really pretty good (not to disparage firaxis or you awesome BetterAI modders!)). If we really wanted to harness the distinctive type of power of the computer, we would have to really try thinking like machines and program the AI likewise (deductively). Which would mean LOTS and LOTS of equations. Needless to say, like I said, I'm not volunteering. :lol: But we can still dream.....
 
Hello Zeiter,

I think it would be too dangerous to program the Civ4 AI like that, it would reach self-conciousness within a few hours, and then proceed to exterminate all human life on this planet, because it is the better solution ;-)

Seriously, I totally agree with your post, and getting the AI to work like that would be like having one of the most sophisticated chess-computers. It should be able to beat the human almost every time, and we would have to give the AI handicaps for the regular difficulty levels, instead of boni for the higher ones.

I am not sure I would enjoy playing against this "Iceman" oponent, though - and it can probably still be lured into traps, just like modern chesscomputers. They will predictably follow the most probable course, and will be caught off-guard by illogical human moves. Ever played sports against someone who is playing at a significantly weaker level? It will break your own game, because you constantly run to the spot where a good player will aim his return (highest probability shot)...

I think the goal should not be to make the AI unbeatable, it should act like a human opponent. So glaring mistakes are not good, while the occasional inefficiency or decision "tarnished by emotion" make it appear even more human. I like the fact that I can rely on friendly relations with Ghandi, even though his army could mop the floor with me. I know Shaka will attack eventually, even if I sacrifice 50 virgins for him every turn. Sometimes I even like the fact that the AI will suicide it´s units into my city-walls, history is full of examples of military attacks without a good chance of successful outcome. Of course, when it happens too much, the illusion of fighting a "human" opponent is destroyed. The difference is a thin line...

Janov
 
As it happens, the AI does care about sunk costs in few cases:

Code:
// if we are killing our growth to train this, then finish it.
// if less than 3 turns left, keep building current item
// if building a combat unit, and we have no defenders, keep building it
// if we are building a wonder, do not cancel, keep building it (if no danger)

However, we would like something more sophisticated in terms of risk/rewards. I would suggest a cvCity::AI_buildValue() function which takes a possible build choice as an argument, and returns a value. Then CvCityAI::AI_chooseProduction can iterate through all possible build choices and pick the one with the best return per hammer remaining, with a slight weighting towards quicker builds.

If that's too much work, an alternative would be to reverse the current logic around maintaining builds. Instead of telling the AI to always drop its current build, unless certain conditions are met, we tell it to always complete its current build, unless certain conditions are met. Those conditions might include:
1) was building culture for border pop, city now generating culture.
2) city has recently expanded, and we need workers.
3) city has become endangered, and we need defence.

I think the goal should not be to make the AI unbeatable, it should act like a human opponent.

Let's worry about that when it happens.
 
I think the goal should not be to make the AI unbeatable, it should act like a human opponent. So glaring mistakes are not good, while the occasional inefficiency or decision "tarnished by emotion" make it appear even more human. I like the fact that I can rely on friendly relations with Ghandi, even though his army could mop the floor with me. I know Shaka will attack eventually, even if I sacrifice 50 virgins for him every turn. Sometimes I even like the fact that the AI will suicide it´s units into my city-walls, history is full of examples of military attacks without a good chance of successful outcome. Of course, when it happens too much, the illusion of fighting a "human" opponent is destroyed. The difference is a thin line...

I agree. Even if one were to code a dynamic problem-solving AI, I would still want certain fudge factors and randomness generators involved to give the AI a bit of personality, unpredictability, and occasionally humor in its play. (Something I have noticed...whenever the AI decides to attack a stoutly-defended city with a stack, it seems to attack with the whole stack, no exceptions. Even if the first 10 attackers die without making a dent, it will still go on. Does the AI use a sort of stack-attack like coding? Or does it pause and consider whether it is worth going on, or worth retreating, after each battle? I know I do the latter always. If I have 7 axes vs. 3 archers, and the first 3 axes die freak deaths while inflicting very little damage, there's no point throwing good money after bad. The probabilities don't get better for subsequent battles just because you just got screwed on the last ones (although it is a common psychological misconception to think that they do). But the AI will not do this. Oddly enough, in this respect the AI behaves more like a drunk, desperate gambler than I do. "C'mon, I'm good for a win this time!...Monty needs a new skullhat, c'mon!...." :lol:

1) was building culture for border pop, city now generating culture.

In general, I agree, but in this case, I would just go ahead and finish the culture building. More culture per turn always comes in handy. (Or were you talking about building just straight culture? In which case, yeah, I agree...but I imagine that the AI already stops building culture after the border pop. I know it stops automatically assigning artist specialists after the 1st border pop).
 
I am not a deity civ4 player so i can hardly comment about anything optimal in this thread.

I think the current plan is to reduce deadlocks, holdups and wasted growth and production. A human beating AI is out of scope for now.

The algorythm for hammers left to complete sounds resonable and easy to implement.

Another option might be a 'priority' queue. E.g. for workers to built city improvements or escort military (which does not generally have to come from the same city).

The growth and holdup problems we have seen in this thread are mostly related to a single city and thus can be solved locally.

We cannot see in this simulation how the AI does handle wonders, national buildings or its army. This does include
  • the scret palace being built right next to the capital.
  • The AI attacking a 5x archer city with 60% defense with 10 axes and no catapults.
  • ai getting weiry about a stack of doom parked right outside it's borders.
  • ai being unable to specialize it's cities into commerce, science, production

It might be interesting to see a game where all 4x players are played by the AI and the same game where one AI is replaced by a human player and later comparing those games. So De Gaulle of France as AI has 3x cities (5(*), 4,1), techs (....).
De Gaulle of France as Human has say 4x cities (5(*), 4, 3,1), techs (....).

the main problem i guess is the write ups and summaries that look like they are a lot of work and seem managable for small empires. I imagine that middle to end games with 10+ cities will be hard to summaries / debug / optimize.

P.S.: Thank you jdog5000 for this thread.
 
A little update on where things went from this thread and the ideas from player logs in the other thread ...

Using 0.82, I ran 10 (well, 11 actually ... counting is hard sometimes) games with this tiny map through 100 turns to see how the players did on average.

French
Avg Score: 719
Power: 77
Cities: 3.3
Total Pop: 11.7

Aztec
Avg Score: 893
Power: 119
Cities: 4.4
Total Pop: 18.1

Ethiopia
Avg Score: 796
Power: 98
Cities: 3.5
Total Pop: 14.5


Then, after making some tweaks to early city build priorities, I ran another set of tests:

French
Avg Score: 782
Power: 76
Cities: 4.0
Total Pop: 14.2

Aztec
Avg Score: 814
Power: 129
Cities: 4.8
Total Pop: 16.4

Ethiopia
Avg Score: 978
Power: 137
Cities: 5.0
Total Pop: 18.7


I created a monster, and his name is Zara Yaqob. Zara's average score after 100 turns is now 23% higher and he averages one and a half more cities founded in the first 100 turns. He also has 40% more unit power after 100 turns.

If you look at the starts for the three, Zara's got a sweet setup for pumping out workers and settlers early. In 0.82, every single game of the test set he built warrior, settler, worker, then finally an escort for his settler. With the settler/worker sequence Zara's capital was still pop 1 at turn 36 with no infrastructure yet each time, and he never founded his second city until turn 45-50. It was a travesty.

Anyway, Zara now goes warrior (he starts with just a scout), worker, escort, settler. On turn 36 Aksum is at pop 3 with both pigs and sheep corralled and his second city is also founded on turn 36 as well, beating Monte to that primo land. This huge improvement early puts him on his now dominating course.

Monte takes a hit in score as he always won the first settler race before and got the awesome second city site. His average population is lower which drags down his score but he still averages more cities founded and more units produced than before. I'm also still working on the first worker build logic as the changes which worked so well for Zara aren't triggering right for Monte yet, so he's now putting off his first worker far too long which hurts him in the early going.

Another interesting note, Monte will now often begin war plans against Zara or De Gaulle in the first 100 turns while he never did before. There are a couple reasons for this, including that Monte gets hemmed in early by Zara's cities and also produces more military units earlier. He even declared war on turn 96 in one game. Most of the time, Monte postpones his war plans once or twice because his cities are still building infrastructure and won't switch to pumping out attack units (the AI needs a certain number of attack troops before it declares). Remarkably, Monte starts war plans on turn 48 in one game ... the city logic for supporting offensives simply doesn't kick in until the city is established, makes perfect sense in the mid-game but means the AI will never really rush.

The French have gotten a 10% score bump mainly from getting more cities in 100 turns now as well.

I've got more changes planned for early game AI logic. I would really like to see the AI be able to rush some defenses together if it's attacked early by an aggressive human player. Another thing which human players do that the AI does not is use the forests around their first cities as early game production boosts. It would be amazing to see Monte chop an early axe/jag invasion in response to losing that great city site and getting cramped in his corner of the map ...
 
I'm not sure what to say other than "Wow", 23% is a big improvement, especially for one release cycle.

Getting Monty to be able to rush a bunch of axe's would be icing on the proverbial cake.

Also, I've gotten reports from a few RoM users that they are now falling behind and losing games with the new .82j Better AI. :lol: That's good news, in a way.
 
You didn't create a monster, he always was. Creative + Orginised = monster rapid expansion combi. I realised that again when I was playing him in this scenario.

But giving the AI the ability to create an escort before the unit that needs that escort even exists is really wow, and I expect this to make all the difference.


My first 74 turns' decisions log, unfortunately with a few holes and not complete until turn 100 so I goubt it's worth that much :p :
Spoiler :
T0 Hut for 86gold, AH, Worker
T7 Hut near montezuma for 36gold
T8 AH finishes, BW
T12 worker finishes, warrior, hut gives wheel
T13 religion founded by jdog,T14 by montezuma
T20 BW finishes, IW
T22 scout gets wodsman2
T23 warrior->warrior
T26 pop4, warrior->settler
T32 montezuma slavery
T33 hut gives map with another hut
T34 settler->settler, IW->agri I have iron!
T35 hut gives masonry
T36 founded Gondor on suggested city location ->worker
T41 jdog slavery, me agri->pottery
T44 another religion for montezuma
T45 founded Lalibela->granary, aksum worker again, monte organized religion,
T47 c2 worker->granary
T49 Aksum worker->settler
T55 settler->axeman
T57 addis ababa ->gran
T58 axeman->gran
T60 slavery
T63 rush gran in lali, aksum gran->lib, research on again (I had completely forgotten I had turned it down at some point, with probably delayed my victory but w/e)
T65 aksum rush, ->axe
T67 gondor 2 pop rush gran
T69 2 pop rush barracks
T74 aksum settler->barracks

The gist of it: fast settling (turn 36) of the contested area towards Monte (captital goes worker->warrior->warrior->settler) then towards the French (probably not as contested location but on turn 45 city #3 is founded between corn and gem). Techs: AH first, no discussion, BW reveals that no bronze is near and a hut gave me wheel, therefore IW next.
City #5 gives me access to ivory, for the Shock Elephants.
Turn 100 Scores:
  • Me 1601 (899 pop/521 land/149 tech/32 wonder)
  • French 821 (328/336/125/32)
  • Monte (war since turn 89 or so) 286 (65/68/137/16)
Turn 133 I take the last French city and I end the game by Conquest with a score of 113401.
 

Attachments

  • AutoSave_BC-0375.CivBeyondSwordSave
    AutoSave_BC-0375.CivBeyondSwordSave
    61.9 KB · Views: 133
  • 100TT-39.jpg
    100TT-39.jpg
    280.4 KB · Views: 164
  • 100TT-100x1.jpg
    100TT-100x1.jpg
    300.4 KB · Views: 168
  • 100TT-100x2.jpg
    100TT-100x2.jpg
    220.9 KB · Views: 145
Fascinating stuff. A couple of points:

When Zara selects Sailing, he has no coastal cities and no settlers on the way. Makes me wonder if that's being evaluated correctly or what benefit Zara is expecting.

Since sailing unlocks trade on rivers, and Zara has a river route to Aztec lands, could he be factoring that in for the commerce boost?

Yeah, defensive swords is one thing the AI does which I never would ... in terms of strength, they seem like a decent choice in the archer era which is probably why the AI chooses them.

I might be misinterpreting things, but isn't this because the swordsman is flagged with <UnitAIType>UNITAI_CITY_DEFENSE</UnitAIType>? If so it might be worth a quick browse through CIV4UnitInfos.xml to see what other units have sub-optimal associations. I agree that a combination of axes and spears (and archers) would make for a better city defending force, and by eliminating swords from that category I suppose that would come about, in a way.
 
I agree that a combination of axes and spears (and archers) would make for a better city defending force, and by eliminating swords from that category I suppose that would come about, in a way.

Swords are better defenders than archers, axes, or spears against catapults, though not as good as longbows or crossbows. They have a legit city defence role, but only in that narrow case.
 
Swords are better defenders than archers, axes, or spears against catapults, though not as good as longbows or crossbows. They have a legit city defence role, but only in that narrow case.

Good point, I hadn't considered that. I'm not sure how the AI decides which unit to build for a particular task, such as defending, but if equal weight is given to any unit with the UNITAI_CITY_DEFENSE tag, I would be surprised if swords weren't being chosen for this purpose in more than their fair share of occasions.
 
Good point, I hadn't considered that. I'm not sure how the AI decides which unit to build for a particular task, such as defending, but if equal weight is given to any unit with the UNITAI_CITY_DEFENSE tag, I would be surprised if swords weren't being chosen for this purpose in more than their fair share of occasions.

Perhaps there should be a UNITAI_COUNTER_SIEGE or something of the like, for units like the Swordsman.
 
To counter siege, you need cavalry and attacking them, not swordman.

Swordman look better against siege, but since they will do nothing against collateral damage, I think that either building more archer or building something that flank and making sure it attack ennemy SoD is a far better idea.
 
Swords are better defenders than archers, axes, or spears against catapults, though not as good as longbows or crossbows. They have a legit city defence role, but only in that narrow case.

Good point. In any case, this does not apply to Monty's UU, which could definitely do without the CITY_DEFENSE tag.

And like someone else mentioned, horse archers are the real defense against siege. Now, the question I would have is, does the AI take into account the value of flanking siege when deciding whether to attack a stack or not with HA's? Or does the AI just evaluate its odds against the top defender?

P.S. Awesome job on the Zara tweaking! Yeah, setting up the AI to actually have the escort to be able to use its first settler right away is huge.
 
Swordman look better against siege, but since they will do nothing against collateral damage, I think that either building more archer or building something that flank and making sure it attack ennemy SoD is a far better idea.

Swords take less collateral damage than archers, and they're more likely to kill attacking catapults. Ideally, this will slow down the attackers long enough for the defender to get a counter-stack (with flanking+seige) into position.

I'm more concerned that the AI appears to build swords as city defence units before anyone discovers Construction.
 
Swords take less collateral damage than archers.

That's plain wrong. Or, to be more precise, it's so small an effect that the AI should not rely on that. I can understand that they build sword to smash attacking SoD, but they ARE bad city defender against catapult. Especially since they are more expensive.

You should try a reality check : does humans player keep garrisoned swords as anti-siege defense ? No, because it don't work. They use sword mainly to smash city, and then to attack things on the field, and maybe to defend on plain tile because there is no %def to apply here.

The AI should do the same (and maybe they do : I'm not enough of an AI guru to be sure that "defensive" does not include counter-attack troop). Any kind of justification of garrisoning sword because they are sword (as opposed to "because we only have that here to help defend", for example) are plain wrong.
 
Swordsman(6) 40 hammers - Strength per hammer = 0.15
Archer(3) 25 hammers - Strength per hammer = 0.12
Axeman(5) 35 hammers - Strength per hammer = 0.14286
Spearman(4) 35 hammers - Strength per hammer = 0.1143

Note swordsmen have best power to hammer ratio.

Generally I dont build many swordsman, but at the sametime I dont do many Axerushs.

In the last game I player I built alot of swordsman instead of axes/spears/archers. I noticed my power rating seemed to be considerably higher than usual. I didnt get attacked by the AI during the early game which humans sometimes fall behind on.

I would suggest this is because I built swordsmen instead of axe's / spears and my power rating was therefore much higher so the AI picked what seemed weaker targets.

The best form of defense is attack but the second best form is not to get attacked.

Building lots of swordsmen also had the advantage that it was cheaper to upgrade to macemen which are a good unit.

Personally I dont really see the problem is with the AI building a few swordsmen for defence.

I think this problem has been discussed before that the power bar does not always tell the whole picture in particular it does not take into account unit special abilities. For instance the Archer is much better than suggested above. But know I've thought about it I can see why the AI will attack if you garrison with a defense force of Archers/Spears.

I mean for 210 hammers you can could either build

5 swordsmen + 10 hammers = 30 Strength
3 Axemen + 3 Spearmen = 27 Strength
8 Archers + 10 hammers = 24 strength

Arguably the 3 Axemen 3 Spearmen is the best choice but to the AI the 5 swords men look stronger so they are less likely to attack you. Plus you have 10 hammers :)
 
Actually just realised this is why Praetorian's are such double hard *******.

Praetorian(8) 45 hammers - Strength per hammer = 0.178

When I've played as Rome in the past ive built Praetorian's as attack unit and archers as defenders, but I've just realised I should just build Praetorian's by the time i've put in the 25 hammers for the archer its a waste not to put in the final 20 for the Praetorian. (unless I desperately need to finish a wonder).

This is even more important if your not playing an aggressive game but a building game. Its very important not to fall behind in the power charts and also you want to get the most power for the least maintenance.

An even if you are attacking a larger power bar can be very important for vassalage and when the enemy will surrender.
 
Swordsman(6) 40 hammers - Strength per hammer = 0.15
Archer(3) 25 hammers - Strength per hammer = 0.12
Axeman(5) 35 hammers - Strength per hammer = 0.14286
Spearman(4) 35 hammers - Strength per hammer = 0.1143
Does this take into account unit special abilities ? Like city defense, first strike, Melee bonus ?
 
Back
Top Bottom