# Why Won't You Die

Discussion in 'Civ3 - Strategy & Tips' started by mortalmadman, Dec 23, 2004.

1. ### OffaBretwalda

Joined:
Feb 3, 2002
Messages:
1,255
Location:
Mercia
Calculating the odds with multiple units is extremely difficult, as you have to allow for defender promotions, attacker retreats etc. Sirp has written a utility which does this, but (at least on the version I have) this can't cope with large numbers. The calculations become outrageous.

I therefore use a programme which simulates taking a town lots of times, using the same combat rules as the game. The program is available as a zipped executable jar ( so you would need java) in the utilities subforum: combat

The 82% figure for 6 vet archers v 3 fort reg spear is based on 1 million simulated assaults on a town without walls, taking it 81.6% of the time, losing on average 2.1 archers in the attack.

2. ### PentiumDigital Matter

Joined:
Nov 24, 2004
Messages:
2,673
Gender:
Male
Location:
Ljubljana, Slovenia
It's logical that if you attack with cavalry to rifleman the odds are 50:50. So 2 swordsmen vs. 1 rifleman is also 50:50? What about veterans?

3. ### PentiumDigital Matter

Joined:
Nov 24, 2004
Messages:
2,673
Gender:
Male
Location:
Ljubljana, Slovenia
sorry didn't see your last post.

4. ### FinnMcCoolCrazy in the right way...

Joined:
Nov 12, 2004
Messages:
608
Location:
Walla Walla Washington (really)
phew! another "zip file quick-answer"!! Skoff skoff.

Nah. Offa, your post makes it sound like you created a VisBasic program that sets up the params for a city assault, and you ran it a million times. I find that hard to believe. What I was asking was, where does the CIV program calculate odds? Can that be answered? And can it be viewed? Will we ever know the crazy logistics of calculating odds in this game??

Ferinstance,

ODDS=INT(RAND(A))/INT(RAND(D))*100 is the old-style way of making a percent chance of the attack succeeding. "RAND(A)" is just a number calculated from 0 to A, A being the Attack value of the unit. Likewise, "RAND(D)" is random 0 to D, D being the defense value. Grossly simplified. Well, even calling it "grossly" is gross...

In what file are combat odds calculated? And can we view it? Does it require installing VisualBasic on our system? (and even then, can it be viewed??)

5. ### OffaBretwalda

Joined:
Feb 3, 2002
Messages:
1,255
Location:
Mercia
The way in which the game calculates battles is well established. I would recommend bomberEscorts combatexe thread. My programme does as I said. It's java, not VisBasic.

Combat consists of multiple rounds, in which each round of combat is calculated separately. The chance of the attacker winning a given round is

p = attack power / ( attack power + modified defender power).

A random number is generated ( I believe the game uses integers 1 to 1024) to test whether the attacker wins that round or not. Your formula would imply 2 random numbers are needed per round, which would be unnecessary.

Retreats and promotions also have to be calculated.

6. ### FinnMcCoolCrazy in the right way...

Joined:
Nov 12, 2004
Messages:
608
Location:
Walla Walla Washington (really)
OK, fair enough Offa.

You're probably right, that only one random number is generated, but in my example I was only being hypothetical. I don't know what the actual equation is, that's why I'm so interested in finding out where its done. You mentioned a file combat.exe, and I suppose that's a good clue...

However, I suspect that the actual calculation is based on a flat curve. It's like rolling a 20-sided die to generate a number from 1 to 20. There's an equal chance of a 1 coming up as a 20. In contrast, if you roll 3 6-sided dice, it will generate a number between 3 and 18 (a similar range) but the chance of a 3 or 18 coming up is only 1.5%, and the chance of a 10 coming up is ... oh cripe, if I calculate the exact number I'll be logged off! But the chance of 10 being the result is the highest probability of all numbers. That's a "bell curve".

I suspect Civ uses the flat curve method, which is partly why so many random events seem to happen.

7. ### FinnMcCoolCrazy in the right way...

Joined:
Nov 12, 2004
Messages:
608
Location:
Walla Walla Washington (really)
Simple example.

A=RND(1) generates a number between 0 and 1.
A1=(RND(1)+1) generates a number between 1 and 2.
Acurve=(RND(1)+RND(1)+RND(1) generates 3 numbers between 0 and 1, and adds them. The result is either 0,1,1,1,2,2,2 or 3. Average is 1.5

In contrast, Aflat=RND(3) generates a number between 0 and 3
NOTE: the number is a decimal, and doesn't include 3. In order to make the number an integer, and to make it include 3, you need:
Aflat1=INT((RND(3)+1)) generates 0,1 or 2, and adds 1, making it 1,2 or 3.
Average is 2, but the probability curve is flat. 1 comes up just as often as 3.

8. ### OffaBretwalda

Joined:
Feb 3, 2002
Messages:
1,255
Location:
Mercia
It is as I said. One random number determines the outcome of each round of combat. The random number generator for this should have a flat distribution, and indeed is thought to function correctly.

In any given combat there are several rounds, with the loser losing one HP each time until the attacker retreats or either the attacker or defender reduces to 0HP (ie dies). The game does not directly calculate the probability of an attacker winning, although this is fairly straightforward. With an assault on a town with multiple units the situation becomes quite complicated and very difficult to calculate precisely.

9. ### FinnMcCoolCrazy in the right way...

Joined:
Nov 12, 2004
Messages:
608
Location:
Walla Walla Washington (really)
Now that this thread can be considered officially hijacked, let me add:

I agree with your assessment, Offa, but what I'm trying to find is a way to narrow down tactics so that planning becomes actually beneficial to combat. At this stage, the only thing you can do is fling overwhelming numbers at an enemy and hope for the best. It often doesn't even matter whether you're using terrain bonuses or not. The experience level of a unit is often the detirmining factor. I've seen Veteran Warriors on a grassland take out 3 Regular Immortals (or some equally odd outcome) too often.

It would sure be nice to find the place where such odds are actually calculated, and hack into it and change it.

Joined:
Nov 5, 2002
Messages:
149
There are, Finn. You can:

change terrain bonuses
change base HP for higher powered units
change base attack and defend values
etc.

Now, if you want to hack it so that when an individual battle which would normally be a 3:1 odds to 4:1 odds, I can't help you there. The odds are calculated such that if the odds are 3:1, assuming the RNG runs from 0-1023, any number greater than 255 is considered a win. Then you have to factor in the effect of hit points (ie, it takes one more success to kill a 3 HP spear than a 2 HP spear, even though each hit is equally likely to succeed) The hit points are what gives the bell curve effect.

Really, the base odds are transparent and based on unit stats plus bonuses. The difficulty is when a defender promotes, because that increases the number of hit points and thus the number of attacks needed to successfully attack, and when an attacker retreats, thus resulting in fewer attempted attacks. If a defender is successful twice in a single turn, it automatically promotes. Assuming one knows the chances of retreat and first-defense promotion, one could conceivably program that in, but it makes the calcs extremely complicated. Ignoring those two effects gives a fairly simple algorithm for computing success, but the answer will be off (the defender will be more likely to succeed than indicated).

11. ### FinnMcCoolCrazy in the right way...

Joined:
Nov 12, 2004
Messages:
608
Location:
Walla Walla Washington (really)
Dangerboy hits it right on the head:

ie, it takes one more success to kill a 3 HP spear than a 2 HP spear, even though each hit is equally likely to succeed) The hit points are what gives the bell curve effect.

Hit points can be tweaked in the Editor, but to keep "balance" (haw!) ALL units would have to be tweaked... I'm not sure if say, doubling all units' HPs would increase the advantage of planning, but it's a good idea.

What I'm hoping to do is change the combat calculation at the basic Random Number Generator step itself. If this CENTRAL, CORE number is created with a bell curve, its effect spreads out into all, other combat odds modifiers. If the curve is flat, and one side gets a +25% for being in forest (or whatever), the curve is still flat... But if the basic RND step in the program is curved, it magnifies all bonuses without having to go through them all and add to them.

Good feedback tho