Better Ai? If you're 14...

I was in a terrible mood yesterday, and seemed to take it out on the forums. Apologies for any offence caused by bad language to all. The original points still stand.

Again apologies for the way things were phrased.

What original point?


Having an excuse for flaming doesn't make it somehow better. If you get upset, wait until you calm down before you take any sort of action, or your going to make mistakes, inexcusable mistakes.

Saying "Sorry" can't make me un-read offensive posts.
 

What original point?


Having an excuse for flaming doesn't make it somehow better. If you get upset, wait until you calm down before you take any sort of action, or your going to make mistakes, inexcusable mistakes.

Saying "Sorry" can't make me un-read offensive posts.

Just re-read the thread, in isn't incomprehensible by any means. If you don't see the same problems, then good luck to you.
 
I was in a terrible mood yesterday, and seemed to take it out on the forums. Apologies for any offence caused by bad language to all. The original points still stand.

Again apologies for the way things were phrased.

Well, I've certainly gone off on my own online tirade from time to time (and have gotten slammed for it as quickly as you were). I've seen you around on the forums for a long time and have had no reason to expect the kind of display I saw yesterday. I am glad that you apologized.

That said, jdog has done a lot of work for us over the years and has not asked for anything in return. I have never seen him unwilling to address concerns people have, and he always seems ready to take suggestions when given. If you've had issues with certain AI behaviors, you could've brought them up at any time and people here would've heard you out.

If your still standing points are, as stated above, that Better AI has been a total failure and that it's made no progress toward improving the AI, then I would say that you are wrong but still just as insulting to the hard work put into this project. All you've done then is apologized for not being insulting in a more polite way.

On the other hand, if all you're saying is that the AI is still deeply flawed and in need of improvement, I don't think there's a single person here who would disagree with you.

On the very specific point of the AI preferring hordes of obsolete units over smaller armies of advanced units, a couple things:


  1. As stated above, this tactic does work under certain circumstances.
  2. This is ultimately more about the economy than anything else. AI Players upgrade units when they have the money to do so, and they try their best to keep up with the human player technologically. The problem is that the AI isn't particularly good at either making money or keeping up technologically... at least when compared against a good human player. This has, in fact, been the area this project has been focusing on lately. 0.80 saw an overhaul of the improvement system to keep the AI from demolishing one improvement and building another over and over again. Expect more developments like this in the future.
  3. Massive hordes of obsolete units can be tweaked in the XML by increasing the unit costs making it impossible for the AI to support armies that large, and by increasing the power rating of higher-tech units. For example, a Maceman currently has a power rating of 9, and Infantry is 20. So if the AI has 18 Macemen and the human player has 6 Infantry, the AI thinks it's more powerful. Change the Infantry's power to 30, and the AI will think it's weaker if it has 18 Macemen against 6 Infantry. This would make the AI player less inclined to launch attacks against a small but much more advanced force because the increased power ratings would more than make up for the lack of numbers. And this has nothing to do with combat strength. Leave that the same. Just change the power rating.
 
For example, a Maceman currently has a power rating of 9, and Infantry is 20.

It sounds like the power rating is approximately equal to the strength of the unit (modified for bonuses). It should probably be equal to the square of that. This would make a Maceman worth 81, and an Infantry worth 400. I'm going to modify this on my PC and see if I get better unit recommendations from the AI
 
It sounds like the power rating is approximately equal to the strength of the unit (modified for bonuses). It should probably be equal to the square of that. This would make a Maceman worth 81, and an Infantry worth 400.

I want to modify this on my PC. Is it <iPower> in the Civ4UnitInfos.XML? OR <iAsset>?

Yes, it's iPower.

I'd like to see what happens when you make the values that much higher... I don't know if it will have any unintended consequences. Be sure to report back what you find.
 
I'm a grown up... have played Civ since the 1991 gem...

Annoying? YES!
Spoiler? YES!
Off-pisser? YES?

That's why it is better. You have to really consider all aspects of the game, especially in higher levels... how is that not better?

anyways...
 
I've done it in the past, both in source and in XML (changing the power value of military units). The game did not obviously break, and stronger (read: higher tech) empires ended up with a higher power rating.

Note that things like city walls and technologies that grant iPower stopped mattering -- iPower became the current size of your military, and everything else faded to being inconsequential.

On top of that, you could generate a 'stealth' military increase by stockpiling cash and then spike-upgrading your forces. In normal Civ, your huge supply of potential increase would make your stealth military not work. However, pulling this off as a non-AI is challenging, and the AI isn't programmed to do this.

(This is useful, because enemies build up their military to match yours. This is why early game axe-rushes rely on building large numbers of axes in a short window, so your AI opponent doesn't react with mass-building archers before you get there, and not just on building large numbers of axes).

Making it happen with the AI improvments in BetterAi would be interesting.
 
To be a bit more constructive than saying BetterAI is bad:

The power rating isn't calculated correctly leading to some overestimation of the strength of low tech units.

If you want to measure the power of a unit just by its capability to kill other units then power should have a relation to strength as power = strength ^ 1.3. Because stronger units will also be able to heal more often because they survive battles, power = strength ^ 1.5 will probably be even more correct in most games. Power = strength ^ 2 is too much.

In the power rating lots of other elements are also included like population, some points for certain buildings and some points for some technologies. These elements aren't very good to estimate the potential military power of a civilisation. You'd want points for the ability to build certain units combined with the production strength of the civilisation. It's not too hard to create a formula that is a good estimate of the ability of a civilisation to create new units of high strength.

The fact that a horde of units of lower technology can defeat a smaller force of high tech units is just a result of the mechanics of the game and is not related to the AI. Those mechanics can be changed so that units that are 2 or more eras ahead of the competition very easily beat the enemy while a single era of advancement still works exactly the same as it does now. This requires some creative adjustment of the unit classes but it does work. But it has nothing to do with the AI but with game mechanics.
You can also make a single era of advancement so strong that units of a previous era can't compete, but that will destabilise the balance of the game so that a single technology of advancement can make a decisive effect on all battles. Then technology controls everything in the game and the game is nothing more than a technological race.
 
Is there a minimum power at which AIs will declare war, to prevent the AI stomping over the human player with their starting archers? Or is it a minimum turn?

If you want to measure the power of a unit just by its capability to kill other units then power should have a relation to strength as power = strength ^ 1.3. Because stronger units will also be able to heal more often because they survive battles, power = strength ^ 1.5 will probably be even more correct in most games. Power = strength ^ 2 is too much.

May I ask where you get those figures from?

Having played around with a spreadsheet, I can get ^1.3 by looking at cases where one high strength unit is defending against many low strength units with no modifiers, and seeing how many low strength units you need to defeat it. But this ignores casualties taken.

Another way of looking at a similar situation would be to see how many more casualties a higher strength defender can cause before dying. For example, suppose we are defending against 20 attackers with strength 3, and we can either do that with 5 defenders with strength 3, or 10 defenders of strength 2. The higher strength defenders get to afflict 2.5 casualties on average, while the lower strength defenders only afflict 1 casualty on average. Here, increasing the strength by 50% and decreasing the numbers by 50% has increased the casualties caused by 150%. I believe that suggests that power is around strength ^ 2, in this case.
 
Is there a minimum power at which AIs will declare war, to prevent the AI stomping over the human player with their starting archers? Or is it a minimum turn?

I recall someone saying that there is a minimum turn.



May I ask where you get those figures from?

You take a unit A of high strength and calculate how many units B of lower strength you'd need to defeat it. Say that it's 2.4 units of lower strength (the last one has hitpoints remaining, the figure 2.4 is just an example). Then you calculate exponent a in (Strength A/Stength B)^a = 2.4. a is close to 1.3.
The difficulty in the calculation is getting to the value of how many lower strength units are required to beat a higher strength one. You also need to do this for various strength values to make sure that the approximation is accurate in more than a single instance. It would take a long post to describe these calculations. If you really want to see them, then I can look them up. I posted them before here somewhere.

Having played around with a spreadsheet, I can get ^1.3 by looking at cases where one high strength unit is defending against many low strength units with no modifiers, and seeing how many low strength units you need to defeat it. But this ignores casualties taken.

The higher strength units take lower casualties, that's true. But the loss of a single higher strength unit will also hurt more.
The elements that are ignored in the above calculation is that in some ingame battle situation the high strength unit might heal between subsequent battles. So the player who uses the lower strength units might not always efficiently exchange his lower strength units against higher strength units. It depends a bit on the tactics used by the players. A good player may use his low strength units very efficiently to kill the high strength units, a weak player won't.

To account for the healing of high strength units in between battles, I suggested using an exponent of 1.5 instead of 1.3. That's a big change.

Strength 10 vs strength 20 unit
exponent 1.3: power 20.0 vs power 49,1, power ratio 2,46
exponent 1.5: power 31.6 vs power 89.4, power ratio 2,83

Another way of looking at a similar situation would be to see how many more casualties a higher strength defender can cause before dying. For example, suppose we are defending against 20 attackers with strength 3, and we can either do that with 5 defenders with strength 3, or 10 defenders of strength 2. The higher strength defenders get to afflict 2.5 casualties on average, while the lower strength defenders only afflict 1 casualty on average.

The assumption here is that the damage inflicted on the attackers which isn't fatal is completely inconsequential. That's not true.

The stronger side also has the higher numbers in this case which means that weakening by fighting a higher number of weak units doesn't take place. If the power between low strength units and high strength units is to be compared and we want to say something like 10 low strength units equal the power of 4 high strength units, then we have to compare them in such matchups. Letting the 4 high strength units face 2 low strength units 5 times in a row while healing in between isn't a good comparison of power. It ignores the fact that the higher number of weak units won't wait until the high strength units are healed.

Here, increasing the strength by 50% and decreasing the numbers by 50% has increased the casualties caused by 150%. I believe that suggests that power is around strength ^ 2, in this case.

I want to see how you get to ^2 here... What's the mathematical basis?
 
You take a unit A of high strength and calculate how many units B of lower strength you'd need to defeat it. Say that it's 2.4 units of lower strength (the last one has hitpoints remaining, the figure is just an example). Then you calculate exponent a in (Strength A/Stength B)^a = 2.4. a is close to 1.3.

Ok, that matches with my own calculations. However, I don't think this is reflective of the true value of high strength units, because it is an optimal situation for the low strength units: an evenly matched encounter. In lopsided situations, the advantage of higher strength units becomes clear.

If the power between low strength units and high strength units is to be compared and we want to say something like 10 low strength units equal the power of 4 high strength units, then we have to compare them in such matchups.

I disagree. One side will normally have a significant local advantage, even if they are evenly matched overall. If we are to assess the relative benefit of high strength vs high numbers, we need to look at three situations:
* Situations where we are locally dominant
* Situations where we are locally dominated
* Situations where we are evenly matched.

I want to see how you get to ^2 here... What's the mathematical basis?

It was a back of the envelope calculation, and on closer inspection it was an underestimate. Here's the full working:

Situation: we are defending against a large number of S3 attackers, and we are certain to lose the city. We want to inflict maximum casualties (and damage) before we are destroyed. We can choose to populate our city with either S2 defenders or S3 defenders. How many S2 defenders is an S3 defender worth, in this situation?

The combat mechanics tell us that each S3 defender will kill 0.5 attackers, on average, while each S2 defender will kill 0.1 attackers, on average. Working on demand. Therefore one S3 defender is worth five S2 defenders, in this situation.

Suppose that Power = Str ^ Exp. Then we have:

3^Exp = 5 x 2^Exp

Thus, Exp ~= 4, since:
3^4=81
5 x 2^4 = 80

Therefore, in this situation, Power ~= Strength ^ 4.
 
Ok, that matches with my own calculations. However, I don't think this is reflective of the true value of high strength units, because it is an optimal situation for the low strength units: an evenly matched encounter. In lopsided situations, the advantage of higher strength units becomes clear.

The power estimate of two forces is only interesting to calculate when it's not clear from the outset. If the civilisation with the stronger units also has numerical equality or advantage, then it will have a huge power advantage if power is calculated as strength^1.5

Only when the civilisation with the weaker units has far more units, it might get to power balance and then battles will typically be between large numbers of weak units and few strong units. It will not be battles between large number of strong units and few weak units.

It was a back of the envelope calculation, and on closer inspection it was an underestimate. Here's the full working:

Situation: we are defending against a large number of S3 attackers, and we are certain to lose the city. We want to inflict maximum casualties (and damage) before we are destroyed. We can choose to populate our city with either S2 defenders or S3 defenders. How many S2 defenders is an S3 defender worth, in this situation?

The combat mechanics tell us that each S3 defender will kill 0.5 attackers, on average, while each S2 defender will kill 0.1 attackers, on average. Working on demand. Therefore one S3 defender is worth five S2 defenders, in this situation.

Suppose that Power = Str ^ Exp. Then we have:

3^Exp = 5 x 2^Exp

Thus, Exp ~= 4, since:
3^4=81
5 x 2^4 = 80

Therefore, in this situation, Power ~= Strength ^ 4.

(log 5)/(log 1.5) to be exact which is very close to 4. I knew your calculation was off or I wouldn't have called you on it.

Now calculate the power ratio between a S3 attacker and a S3 defender in this situation knowing that you lose twice as many S3 defenders as S3 attackers in this battle.
 
Some clarifications are sorely needed here:

- AFAIK ( feel free to correct me ) there is no war-free period in civ IV. What happens is that the AI is coded to not start a war until it has a CITY_ATTACK unit and a 4 unit mini-SoD ( atleast it was what I read from DanF somewhere ). Even on Deity, that is not automatic ( because archers normally can't get the CITY_ATTACK ), and either way, the AI would have to meet the civ and trigger the warplan before all of that.

-By various reasons, the number of soldiers that each unit has ( the number that is behind the power calculations, along with some buildings, wonders and the city pop ) and it is unrelated with the strength of the unit ( just for a example, a archer and a warrior have the same soldier count IIRC ). Some of this has to do with flavour concerns, but also with the diferent promo lines and other similar considerations ( a 16 str mounted unit can't be considered in any way equal to a str 16 siege unit or to a str 16 gunpowder unit, or to a 16 str ship )...
-Now my personal pet peeve: the power graph does not have in cosideration the promotions of the units. having a rookie army, for the eyes of the AI, is the exact same thing than having a highly promoted one, like if the odds of winning vs a C3 rifle were the same of winning vs a unpromoted one....

@OP

You may not like the idea that 3453534 knights submerging your 15 infantry , but that, like DP II pointed, those are the rules of the game. This project has not changed those rules, it simply taugth the AI to play better along those rules. For what is worth, Civ IV is a game where zerging sometimes works... so why forbid one of the players of the game of doing it if it has the chance? If you don't like that aspect of the game, your complaints should be directed not to jdog, not even to Blake, but to Soren, alexman, Shaefer and co, that were the ones that inserted it in vanilla. No one in the both Better AI projects had anything to do with it.
 
The power estimate of two forces is only interesting to calculate when it's not clear from the outset. If the civilisation with the stronger units also has numerical equality or advantage, then it will have a huge power advantage if power is calculated as strength^1.5.

It will have a bigger power advantage if power is calculated as strength^2. This larger power advantage is more accurate. This makes a difference when a warmonger is trying to decide whether to attack a small civilisation with good tech, or a large civilisation with bad tech. As a player, I will often choose the large civilisation, as I know that I can stomp over it, gaining experience, while taking few casualties. The power graph and AI decisions should reflect that reality.

Only when the civilisation with the weaker units has far more units, it might get to power balance and then battles will typically be between large numbers of weak units and few strong units.

That's not my experience. I find that battles in such a civilisation match-up will typically be a mix of two types:

* Several weak units vs several strong units (eg 10xS2 vs 10xS3). The strong units are attacking. These end with the weak units being wiped out while inflicting negligible casualties. Power ~= Strength ^ 4 (in this instance).

* huge numbers of weak units vs a few strong units (eg 20xS2 vs 5xS3). The weak units are attacking. These end with the strong side being wiped out while taking down many of the weak units. Power ~= Strength ^ 1.3.

The ideal exponent is presumably somewhere between 1.3 and 4, as I think we both agree. However, I think 1.5 is too low. I might go for something like 1.8, based on strength alone. When we add factors such as experience, war weariness, and upkeep, I still think strength^2 is fair.
 
A naive way to measure power is to work out what the expected damage to a high-strength unit is when killing a lower-strength unit.

At 100%, the hit ratio is (Attacker Strength)/(Defender Strength).

The damage ratio is [(3 * A + D) / (3 * D + A)]^2. If you graph (3A+D)/(3D+A) you end up with a function that is similar to sqrt(A/D) over a reasonable range. As we are squaring it (for both damage sides)...

So the attacker loses about (D/A)^2 fraction of their HP, on average, killing a defender with strength D, if all have 100% HP to start.

The next problem is that your ability to hit drops as you lose hp. Your hit ratio (against a target with 100% HP) is (A*(100%+HP%)/2)/D

So when you lose 25% of your HP, your (first approximation to) power isn't no longer A^2 * 75%, but instead A^2*(.875)*75%. Ie, that damage you took is more important than it looked, and you cannot repeat the task 4 times, so your power was overestimated.

Using goal seeking on making the average of 100% to 5% in 5% increments as close in ratio to a power curve, I get 1.32. Dividing the naive curve of ^2 by 1.32 gives us a 1.52 power curve once we take into account the fact that damaged units are weaker than the naive approximation assumed.

:)

Another thing to take into account is the power flux of each side. You could calculate this based on, say, X years of imperial production producing the highest power efficiency unit, where X varies based on game speed. This misses, however, being close to a new technology that will allow massive upgrades...
 
I know why the AI is doing that to you and it's because your playing the sameway every single game.

Let me guess, you start off totally focusing on taking over whatever landmass you start on. You then ramp tech up all the way once you conquered the starting landmass and build a bunch of wonders. Am I right so far? You prob. don't have many AI friends throughout the game, maybe 1 or 2 that follow the same religion, but they are prob. just "Pleased" with you.

The AI at some point decides your getting way to advanced and knows that it can't keep up, so it decides it needs to invade and at least destroy some cities and try to get as many other AI's to declare on you. Orginal BTS AI would do the same thing, but instead of 150 units it would send 20 and get maybe one far off AI to declare on you that meant nothing. That's the difference in Better AI.
 
I know why the AI is doing that to you and it's because your playing the sameway every single game.

Let me guess, you start off totally focusing on taking over whatever landmass you start on. You then ramp tech up all the way once you conquered the starting landmass and build a bunch of wonders. Am I right so far? You prob. don't have many AI friends throughout the game, maybe 1 or 2 that follow the same religion, but they are prob. just "Pleased" with you.

The AI at some point decides your getting way to advanced and knows that it can't keep up, so it decides it needs to invade and at least destroy some cities and try to get as many other AI's to declare on you. Orginal BTS AI would do the same thing, but instead of 150 units it would send 20 and get maybe one far off AI to declare on you that meant nothing. That's the difference in Better AI.

Not quite the above scenario, but similar results. And for me, you've encapsulated the problem in a nutshell.

Players fall into two categories basically, those that just "play to win", and those that like a teensy bit of RP, and basically play "for the fun of it". I couldn't fall into the second category any clearer. For me, it hasn't been about "winning" for a very, very long time. I've beaten the game many times on every meaningful level, on varied maps. I absolutely don't directly play to win any more. Of course, just by carrying on the game that may be the end result, but that isn't the object of playing.

Personally I've just played game changing Mods for a long time, as they offer different choices from the original. In short they make the game fun.

The AI at some point decides your getting way to advanced and knows that it can't keep up, so it decides it needs to invade and at least destroy some cities and try to get as many other AI's to declare on you. Orginal BTS AI would do the same thing, but instead of 150 units it would send 20 and get maybe one far off AI to declare on you that meant nothing. That's the difference in Better AI.
This is to me, where Blake and others started down a road many others disagreed with. The ai in this case, isn't even playing "to win" it's basically just playing in a spoiler role. I still have problems, understanding why anyone would want the ai to do this. By mindlessly attacking the strongest player (and ok they might temporarily get a city or two, at the cost of their entire army), and thus almost guaranteing their own ultimate destruction, they are basically giving up there and then.

Fair enough, if people want an ai that is just programmed as a spoiler, but that's not for a lot of folks. As you inadvertently said above, while "Better" ai doesn't radically alter this behaviour, it allows such behaviour to be executed in a much more efficient manner. When combined with the abysmal lack of any proper diplomacy in Civ IV (which is purely the Original Programmers fault), this initiates the situation, where such spoiler behaviour becomes almost unstoppable. When various ais have been attacking me (on roughly an every game basis) in this manner, often I'm not just vastly superior in Military Tech, but often even superior in power rating.

When BTS came out, I had many arguements with Blake about "suicidal" ais. While "Better" ai has made great strides in some directions, it has just exasperated the problems in others.
 
By mindlessly attacking the strongest player (and ok they might temporarily get a city or two, at the cost of their entire army), and thus almost guaranteeing their own ultimate destruction, they are basically giving up there and then.

Whether the AI is guaranteeing its own ultimate destruction depends heavily on the personality of the player they are attacking. Some players will "forgive" the AI for doing this, and go on to win a diplomatic/space/cultural victory. Other players will respond to a declaration of war by attempting to destroy the warmonger at any costs. This type of revenge motive is neither historical nor rational, so you shouldn't expect the default AI to plan for it.
 
Interesting view of the purpose of a 'Better AI'... It reminds me that I once read a post from Soren saying that he could have made an AI which was harder to beat, but he decided against it, as it wouldn’t have been any more ‘fun’ for the player.

Does increased military efficiency on the part of the AI reduce fun/role play?
 
The AI at some point decides your getting way to advanced and knows that it can't keep up, so it decides it needs to invade and at least destroy some cities and try to get as many other AI's to declare on you. Orginal BTS AI would do the same thing, but instead of 150 units it would send 20 and get maybe one far off AI to declare on you that meant nothing. That's the difference in Better AI.

At least part of this is wrong because the AI doesn't get another AI to declare war. I should know since I added the code into my mod that lets it do this.

While I'm less familiar with other parts of the AI code, I don't think the AI has any kind of "spoiler" programming where it wardecs the tech leader. It's almost certainly that the smaller, high-tech force just isn't registering as being as powerful as the low-tech horde.

Now, why is the AI building so many friggin' units? My guess is this: The AI sets war plans against particular players every so often... especially the more aggressive AI players. But that war doesn't always start. Sometimes they AI will have a set war plan against another player and then it'll just cancel it before it ever fires a shot. But the AI is much better now at properly building up for a war. The problem is, if the war doesn't come, it's sitting on this enormous force that it just keeps around. Ironically, this huge military force costs the player gold thus burdening its economy with the cost and driving its research slider down to compensate. That leads to the player falling ever farther behind which means they will never have either the techs or the gold necessary to upgrade their units.

There's also the opportunity cost factor. If the AI's building tons of military units, it's not building libraries or granaries or workers to get its economy straight.

I would say that you and DrewBledsoe are incorrectly assuming that this convergence of problems is somehow a design philosophy of the Better AI folks or Blake even. In fact, I would argue that it's rather the unintended consequences of improvements made in particular areas.
 
Back
Top Bottom