Who defends when multiple units?

That's my point! But you can order an entire stack of units to attack, and the one with the best odds will attack first...but the best defender will fight against that.
That is incorrect. I don't know what order the stack attacks in, but I suspect it's by experience, which is the order they are in when cycling through them. However, once the attacker is chosen, the defender is chosen for that specific attacker.

As the docs say, stack attack is an interface convenience, and has no influence whatsoever on the combat mechanics.
 
That's my point! But you can order an entire stack of units to attack, and the one with the best odds will attack first...but the best defender will fight against that.

The defender is always chosen based upon the individual attacking until. Lets use an example if you are attacking with Knights and Macemen against a city that has Longbowmen and Pikemen defenders. If you attack with a Knight, a Pikeman would defend. If you attack with a Maceman, the Longbowman would defend.

Stack attack works the exact same way - it chooses the best attacker, and then the defense chooses the best defense against that unit. Then once that fight is over, it chooses the second best attacker, and then the defense chooses the best defender against that unit. This continues until combat is over.

The defense always automatically chooses the best unit against the specific attacking unit (except with the Khmer UU).
 
No offense but some of you really don't know what you are talking about. Some of you are assuming that the game just knows to pick the defender with the highest odds of surviving. While that is a pretty reasonable assumption, and to be honest I assumed the same thing until I learned it was not true, as TMIT very correctly pointed out the best defender algorithm is complex and not as straight forward as many of you make it out to be. He kindly gave an example where a caravel would be picked to defend a loaded (not empty!) galleon. Yes, the game does take various things into account like whether the transport has units in it and how valuable they are. The way first strikes factor into the best defender algorithm are not very intuitive IMO and I have seen a very bizzare example of an injured unit with many first strikes defending at approx 40% odds while a stronger unit with fewer first strikes could have had about 70% odds to survive.

The code is in the DLL and for memory searching for "bestdefender" will lead you to the specifics.

EDIT... Attached is the example of the injured drill defender. :)

 
Wow I didn't realize my question would cause such a ruckus! It made no sense to me because from what I remember both SAM and infantry were at 100 health, and I posted because it just really pissed me off as it was a crucial part of the war.

Other little things about the game get on my nerves too, like when I take over a city and then (because it's cultural borders are shrunk) another civ comes in with a settler and sticks a new city right next to mine.

Also, and I know this isn't the best place for this but maybe someone will see it - someone suggested that turning off tech trading would make a new difficulty level easier but I've found it to be harder. Am I doing something wrong? I'm on emp level.
 
I dunno - are we sure the combat odds shown are correct? 3-6 first strikes is a lot - it's quite possible for the attacking infantry will be dead before it gets a chance.
 
hmmmm, the handling of first strikes in the code for choosing the best defender appears rather dubious to me:

Provided the attacker isn't immune to first strikes, a potential defender's strength gets boosted by an additional flat 16% for each first strike of the defender and a flat 8% for each first strike chance. Furthermore there is a similar piece of code that boosts this modified strength of a defender who is immune to first strikes according to the number of first strikes/chances of the attacker.

This leads to the following extreme situation:

BestDefender.jpg


Monty "chooses" to defend with his uber Ironclad (Drill IV, Flanking I+II --> immune to first strikes) against my Drill IV Destroyer. My odds 97.6%
If Monty's Combat II Destroyer were the "best" chosen defender my odds would only be 49.3%.

During the comparison the units' strengths are integers multiplied by 100:

Drill IV, Flanking I+II Ironclad:

strength = 1200, + 10% defense on coast --> 1320
attacker not immune to first strikes: + 3*16% + 3*8% = +72% --> 2270
Ironclad is immune to first strikes, attacker has Drill IV: + 3*16% + 3*8% = +72% --> 3904

Combat II Destroyer:
strength = 3000, + 10% defense on coast + 20% for Combat II --> 3900

3904 > 3900 --> Ironclad is the "best defender" !!

Apart from the special case of cargo units loaded on potential defenders, I can't really see a reason not to let the one unit get chosen as the defender, which simply gets the best combat odds. :confused::dunno:
 
Apart from the special case of cargo units loaded on potential defenders, I can't really see a reason not to let the one unit get chosen as the defender, which simply gets the best combat odds.

Great generals with medic or really anything but CG promotions.
 
hmmmm, the handling of first strikes in the code for choosing the best defender appears rather dubious to me:

Provided the attacker isn't immune to first strikes, a potential defender's strength gets boosted by an additional flat 16% for each first strike of the defender and a flat 8% for each first strike chance. Furthermore there is a similar piece of code that boosts this modified strength of a defender who is immune to first strikes according to the number of first strikes/chances of the attacker.

This leads to the following extreme situation:

BestDefender.jpg


Monty "chooses" to defend with his uber Ironclad (Drill IV, Flanking I+II --> immune to first strikes) against my Drill IV Destroyer. My odds 97.6%
If Monty's Combat II Destroyer were the "best" chosen defender my odds would only be 49.3%.

During the comparison the units' strengths are integers multiplied by 100:

Drill IV, Flanking I+II Ironclad:

strength = 1200, + 10% defense on coast --> 1320
attacker not immune to first strikes: + 3*16% + 3*8% = +72% --> 2270
Ironclad is immune to first strikes, attacker has Drill IV: + 3*16% + 3*8% = +72% --> 3904

Combat II Destroyer:
strength = 3000, + 10% defense on coast + 20% for Combat II --> 3900

3904 > 3900 --> Ironclad is the "best defender" !!

Apart from the special case of cargo units loaded on potential defenders, I can't really see a reason not to let the one unit get chosen as the defender, which simply gets the best combat odds. :confused::dunno:

For one, it sometimes happens that the unit with more first strikes but lower survival odds will on average deal more damage to the attacker. Usually this difference in average damage to the attacker is very small, and in my opinion it still hardly justifies defending with a unit more likely to die.

To be honest, I reckon the only reason the best defender code works this way is that it was implemented before the odds calculator was written. I'm not 100% sure but I recall being told that in the earliest version of vanilla, there were not even any displayed odds at all, which to me suggests the code had not been written, of course.

When the code finally was written, either they decided to leave the best defender code as it was because it wasn't obviously broken. I mean, to be fair, it is pretty rare to see examples as absurd as yours DanF. Or, for some reason maybe they thought it was less computationally expensive. I think using the correct odds calculation routine is a couple layers more complex and calling it for all units in a stack may be slow - I'm not sure.

If possible, maybe the best defender code can just be tweaked so that it is a better approximation to the true odds. As I have mentioned in the thread for PIG mod, I've been wanting to change the way best defender code works, but I have not yet had any bright ideas for how to do it! In particular, first strikes need to be taken into account in a better way. For example, a unit with many first strikes defending against a unit that is immune to first strikes should IMO be actually discouraged from being the best defender since its first strikes may be one of its best assets (e.g. Drill IV units). IMO a Drill 4 musket should not defend against a knight instead of an unpromoted musket. There are advantages either way but that is just my preference.
 
h
strength = 1200, + 10% defense on coast --> 1320
attacker not immune to first strikes: + 3*16% + 3*8% = +72% --> 2270
Ironclad is immune to first strikes, attacker has Drill IV: + 3*16% + 3*8% = +72% --> 3904

Combat II Destroyer:
strength = 3000, + 10% defense on coast + 20% for Combat II --> 3900

3904 > 3900 --> Ironclad is the "best defender" !!

Apart from the special case of cargo units loaded on potential defenders, I can't really see a reason not to let the one unit get chosen as the defender, which simply gets the best combat odds. :confused::dunno:

Thanx for the explaination. Could you tell me where I can change the code (I would like Great general not defending)

Edit: this code is seriously broken. For example, combatI sword attacks combatI sword and longbow. Long bow will defend and have less than 50% winning chance. This is a pretty common situation.
 
Thanx for the explaination. Could you tell me where I can change the code (I would like Great general not defending)

Edit: this code is seriously broken. For example, combatI sword attacks combatI sword and longbow. Long bow will defend and have less than 50% winning chance. This is a pretty common situation.

The best defender code is found at CvPlot::getBestDefender, and CvUnit::isBetterDefenderThan.

Let me know how it goes. If you're successful I might put it in PIG Mod.
 
To be honest, I reckon the only reason the best defender code works this way is that it was implemented before the odds calculator was written. I'm not 100% sure but I recall being told that in the earliest version of vanilla, there were not even any displayed odds at all, which to me suggests the code had not been written, of course.
When vanilla got out it was like this.....

rb1-177.jpg


From the good and ol'most viewed Civ IV SG, RB1 - Cuban Isolationists .... Not non-existant, but without displaying percentages.
 
When vanilla got out it was like this.....

rb1-177.jpg


From the good and ol'most viewed Civ IV SG, RB1 - Cuban Isolationists .... Not non-existant, but without displaying percentages.

Note by "odds" I'm specifically referring to what you are calling the "percentages". The two numbers that show the modified strengths are far from what I'd call the odds.

Obviously the method for calculating the actual combat odds (i.e. probabilities) is much more involved than displaying a couple numbers that have had a few modifiers added onto a base value. ;) This is why it doesn't surprise me that the odds display was not there in the earliest version of the game - just the modified strengths and modifier list.
 
In fact there was even people that didn't wanted the game to have displayed combat odds in those days :crazyeye: Something about avoiding certain discussions of "T'm losing battles with 80% odds" :D ( like if winning all the battles with 80% odds would not make them 100% win odds battles :p )

But yes, most likely the combat odds code was made later ( and it is still not completely unbugged after all this years :D )
 
[...]

The Chariot's +100% vs Axemen is only for attacking, not defending.

That's interesting. I always assumed that the "vs. specific unit (type)" is for defending AND attacking. Spears/Pikes do receive the "vs. mounted" bonus only while attacking? Is this the case for all these bonuses?
 
That's interesting. I always assumed that the "vs. specific unit (type)" is for defending AND attacking. Spears/Pikes do receive the "vs. mounted" bonus only while attacking? Is this the case for all these bonuses?

It says rather clearly "+100% vs Axeman when attacking" on the Chariot. Another example is Grenadiers' attack bonus against Rifles; it doesn't apply when defending. Most of the bonuses work either way (except withdrawing).
 
Also, and I know this isn't the best place for this but maybe someone will see it - someone suggested that turning off tech trading would make a new difficulty level easier but I've found it to be harder. Am I doing something wrong? I'm on emp level.

I have also been playing emperor level with tech trading switched off recently. I think it's harder in the early game because:
1) the AIs get a head start with free techs and bonuses and its more difficult to catch up without tech trading
2) the AIs generally tech better on emperor because of their bonuses so tech trading would be more useful than it would on say noble level
3) perhaps most importantly you can't use tech trading/gifting for diplomacy so it is harder to avoid being attacked

Having said that, if I survive to the renaissance era in any kind of decent shape I find I start to accelerate away from the AIs in tech pretty rapidly.

If you want to make it easier I would recommend the 'no tech brokering' option. This seems to slow the AIs down quite a lot, while you can still do well out of tech trades by going for techs that the AIs haven't got.
 
It says rather clearly "+100% vs Axeman when attacking" on the Chariot. Another example is Grenadiers' attack bonus against Rifles; it doesn't apply when defending. Most of the bonuses work either way (except withdrawing).

Ah, thanks Silu! :)

Actually, I never read this, as I never use chariots. My mistake...:crazyeye:
 
Back
Top Bottom