Is win_chance correct ?

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Post Reply
louis94
Hardened
Posts: 270
Joined: Thu Apr 25, 2013 10:17 pm
Location: Belgium

Is win_chance correct ?

Post by louis94 »

Hello,

I was reading the online documentation when I found this page: "Maths of Freeciv". As a physics student I couldn't resist and I began reading.

I found that the win_chance function does not handle the following case correctly (looking at the source code confirmed that) :
Suppose we have a combat between an ultra-weak defender and an ultra-strong attacker. I mean att_P_lose1 = 0 (the attacker will win every single round). It is obvious such an attacker will win.
But, because each term is multiplied by att_P_lose1 = 0, the function concludes the attacker has no chance at all of winning (because 0 + 0 + ... + 0 = 0 ;) ).

Am I wrong ?

Thank you for making such a good piece of software, and for using it ! (and also for reading me)
Louis

Edit : win_chance is at common/combat.c: 230
cazfi
Elite
Posts: 3069
Joined: Tue Jan 29, 2013 6:54 pm

Re: Is win_chance correct ?

Post by cazfi »

Given that I remember always seeing 99% win chance for attacker against defense 0 units, I doubted your theory.

Note that the very first term (before the loop) is not multiplied by att_P_lose1:

double binom_save = pow(def_P_lose1, (double)(def_N_lose - 1));
double accum_prob = binom_save; /* lr = 0 */
// def_P_lose1 would be 1.00 here so no matter def_N_lose, accum_prob = binom_save = 1 (100%)
louis94
Hardened
Posts: 270
Joined: Thu Apr 25, 2013 10:17 pm
Location: Belgium

Re: Is win_chance correct ?

Post by louis94 »

Thanks for your reply,

As you said, I didn't see accum_prob was 1 at the beginning. (As written in the doc, that is unclear because 0^0 is undefined...)
I experimented and got results that showed the function was correct. I'm sorry for the noise :oops:

Louis
Post Reply