Hit stats: Track number of hits/misses by CTH in statistics::stats objects.
This commit is contained in:
parent
352d8838f8
commit
38641d667a
3 changed files with 30 additions and 6 deletions
|
@ -1096,14 +1096,16 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context& stats)
|
|||
? (dies
|
||||
? statistics::attack_context::KILLS
|
||||
: statistics::attack_context::HITS)
|
||||
: statistics::attack_context::MISSES, damage_done, drains_damage
|
||||
: statistics::attack_context::MISSES,
|
||||
attacker.cth_, damage_done, drains_damage
|
||||
);
|
||||
} else {
|
||||
stats.defend_result(hits
|
||||
? (dies
|
||||
? statistics::attack_context::KILLS
|
||||
: statistics::attack_context::HITS)
|
||||
: statistics::attack_context::MISSES, damage_done, drains_damage
|
||||
: statistics::attack_context::MISSES,
|
||||
attacker.cth_, damage_done, drains_damage
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -300,6 +300,7 @@ config stats::write() const
|
|||
res["expected_damage_inflicted"] = expected_damage_inflicted;
|
||||
res["expected_damage_taken"] = expected_damage_taken;
|
||||
|
||||
// TODO add by_cth here and throughout this file
|
||||
res["turn_damage_inflicted"] = turn_damage_inflicted;
|
||||
res["turn_damage_taken"] = turn_damage_taken;
|
||||
res["turn_expected_damage_inflicted"] = turn_expected_damage_inflicted;
|
||||
|
@ -455,11 +456,15 @@ void attack_context::attack_expected_damage(double attacker_inflict_, double def
|
|||
}
|
||||
|
||||
|
||||
void attack_context::attack_result(hit_result res, int damage, int drain)
|
||||
void attack_context::attack_result(hit_result res, int cth, int damage, int drain)
|
||||
{
|
||||
attacker_res.push_back(res == MISSES ? '0' : '1');
|
||||
stats &att_stats = attacker_stats(), &def_stats = defender_stats();
|
||||
|
||||
if(res != MISSES)
|
||||
++att_stats.by_cth[cth].hits;
|
||||
++att_stats.by_cth[cth].strikes;
|
||||
|
||||
if(res != MISSES) {
|
||||
// handle drain
|
||||
att_stats.damage_taken -= drain;
|
||||
|
@ -479,11 +484,15 @@ void attack_context::attack_result(hit_result res, int damage, int drain)
|
|||
}
|
||||
}
|
||||
|
||||
void attack_context::defend_result(hit_result res, int damage, int drain)
|
||||
void attack_context::defend_result(hit_result res, int cth, int damage, int drain)
|
||||
{
|
||||
defender_res.push_back(res == MISSES ? '0' : '1');
|
||||
stats &att_stats = attacker_stats(), &def_stats = defender_stats();
|
||||
|
||||
if(res != MISSES)
|
||||
++def_stats.by_cth[cth].hits;
|
||||
++def_stats.by_cth[cth].strikes;
|
||||
|
||||
if(res != MISSES) {
|
||||
//handle drain
|
||||
def_stats.damage_taken -= drain;
|
||||
|
@ -683,4 +692,9 @@ int sum_cost_str_int_map(const stats::str_int_map &m)
|
|||
return cost;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& outstream, const struct statistics::stats::by_cth_t& by_cth) {
|
||||
outstream << "[" << by_cth.hits << "/" << by_cth.strikes << "]";
|
||||
return outstream;
|
||||
}
|
||||
|
||||
} // end namespace statistics
|
||||
|
|
|
@ -52,6 +52,14 @@ namespace statistics
|
|||
long long damage_inflicted, damage_taken;
|
||||
long long turn_damage_inflicted, turn_damage_taken;
|
||||
|
||||
struct by_cth_t {
|
||||
int strikes; //< Number of strike attempts at the given CTH
|
||||
int hits; //< Number of strikes that hit at the given CTH
|
||||
friend std::ostream& operator<<(std::ostream& outstream, const struct by_cth_t& by_cth);
|
||||
};
|
||||
/// A map of chance-to-hit percentage to a 'struct by_cth_t'.
|
||||
std::map<int, struct by_cth_t> by_cth;
|
||||
|
||||
static const int decimal_shift = 1000;
|
||||
|
||||
// Expected value for damage inflicted/taken * 1000, based on
|
||||
|
@ -80,8 +88,8 @@ namespace statistics
|
|||
enum hit_result { MISSES, HITS, KILLS };
|
||||
|
||||
void attack_expected_damage(double attacker_inflict, double defender_inflict);
|
||||
void attack_result(hit_result res, int damage, int drain);
|
||||
void defend_result(hit_result res, int damage, int drain);
|
||||
void attack_result(hit_result res, int cth, int damage, int drain);
|
||||
void defend_result(hit_result res, int cth, int damage, int drain);
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue