The Battle for Wesnoth  1.17.10+dev
attack_prediction.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2022
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <vector>
19 #include <array>
20 #include <cstring>
21 
23 
24 // This encapsulates all we need to know for this combat.
25 /** All combat-related info. */
26 struct combatant
27 {
28  /** Construct a combatant. */
29  combatant(const battle_context_unit_stats &u, const combatant *prev = nullptr);
30 
31  /** Copy constructor */
32  combatant(const combatant &that, const battle_context_unit_stats &u);
33 
34  combatant(const combatant &that) = delete;
35  combatant& operator=(const combatant &) = delete;
36 
37  /** Simulate a fight! Can be called multiple times for cumulative calculations. */
38  void fight(combatant &opponent, bool levelup_considered=true);
39 
40  /** Resulting probability distribution (might be not as large as max_hp) */
41  std::vector<double> hp_dist;
42 
43  /** Resulting chance we were not hit by this opponent (important if it poisons) */
44  double untouched;
45 
46  /** Resulting chance we are poisoned. */
47  double poisoned;
48 
49  /** Resulting chance we are slowed. */
50  double slowed;
51 
52  /** What's the average hp (weighted average of hp_dist). */
53  double average_hp(unsigned int healing = 0) const;
54 
55 #if defined(BENCHMARK) || defined(CHECK)
56  // Functions used in the stand-alone version of attack_prediction.cpp
57  void print(const char label[], unsigned int battle, unsigned int fighter) const;
58  void reset();
59 #endif
60 
61 private:
62  static const unsigned int MONTE_CARLO_SIMULATION_THRESHOLD = 50000u;
63 
65 
66  /** Summary of matrix used to calculate last battle (unslowed & slowed).
67  * Invariant: summary[1].size() == summary[0].size() or summary[1].empty() */
68  std::array<std::vector<double>, 2> summary;
69 };
double untouched
Resulting chance we were not hit by this opponent (important if it poisons)
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
std::array< std::vector< double >, 2 > summary
Summary of matrix used to calculate last battle (unslowed & slowed).
double average_hp(unsigned int healing=0) const
What&#39;s the average hp (weighted average of hp_dist).
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:217
const battle_context_unit_stats & u_
combatant(const battle_context_unit_stats &u, const combatant *prev=nullptr)
Construct a combatant.
combatant & operator=(const combatant &)=delete
void fight(combatant &opponent, bool levelup_considered=true)
Simulate a fight! Can be called multiple times for cumulative calculations.
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:51
double slowed
Resulting chance we are slowed.
All combat-related info.
static void print(std::stringstream &sstr, const std::string &queue, const std::string &id)
Definition: fire_event.cpp:30
static const unsigned int MONTE_CARLO_SIMULATION_THRESHOLD
map_location prev
Definition: astarsearch.cpp:66
double poisoned
Resulting chance we are poisoned.