Looking at the code, it seems to me that the reason people have been
continually complaining about expected value (EV) damage values is that
these values are simply wrong.
The EV statistics are stored as integers, and truncation is done on
each swing. So an Elvish Fighter doing 5-4 with 50% to hit, will have
its EV of damage dealt calculated as 5*.5 = 2.5 = 2, four times, ie. it
will come out at 8 total, instead of the actual value of 10.
The simplest way I thought of fixing this bug is through the attached code
(compiled OK but not tested in actual play). This tries to compensate
for the truncation by randomly adding 1 to the result based on the size
of the discarded fraction. This estimator should approximate the true
EV as the number of swings grows; its expected value is the actual EV.
A better approach would be to keep an integer fraction as well as the
integer EV, or to keep the EV as a floating point number, but this would
clearly be a post-1.0 solution.
However, this code would mean we suddenly start using rand() quite often.
Is this likely to have any ill effects -- are we relying on a particular
sequence of random values to be repeatable given the seed, or will we
suddenly need a better random number generator due to subgroup effects?
And, most important of all, would this fix break the feature freeze?
-- address@hidden
------------------------------------------------------------------------
Index: src/statistics.cpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/statistics.cpp,v
retrieving revision 1.18
diff -u -r1.18 statistics.cpp
--- src/statistics.cpp 20 Jul 2005 08:22:37 -0000 1.18
+++ src/statistics.cpp 10 Aug 2005 12:00:30 -0000
@@ -307,10 +307,16 @@
attacker_stats().damage_inflicted +=
bat_stats.damage_defender_takes;
defender_stats().damage_taken +=
bat_stats.damage_defender_takes;
}
- attacker_stats().expected_damage_inflicted +=
- bat_stats.damage_defender_takes *
bat_stats.chance_to_hit_defender;
- defender_stats().expected_damage_taken +=
- bat_stats.damage_defender_takes *
bat_stats.chance_to_hit_defender;
+ {
+ const double evd = bat_stats.damage_defender_takes
+ * bat_stats.chance_to_hit_defender;
+ int evdi = (int)evd;
+ // randomly approximate fractions
+ if (100.0*(evd - evdi) <= rand()%100)
+ ++evdi;
+ attacker_stats().expected_damage_inflicted += evdi;
+ defender_stats().expected_damage_taken += evdi;
+ }
if(res == KILLS) {
attacker_stats().killed[defender_type]++;
------------------------------------------------------------------------
_______________________________________________
Wesnoth-dev mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/wesnoth-dev