The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
attack_prediction.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2025
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
21
struct
battle_context_unit_stats
;
22
23
// This encapsulates all we need to know for this combat.
24
/** All combat-related info. */
25
struct
combatant
26
{
27
/** Construct a combatant. */
28
combatant
(
const
battle_context_unit_stats
&u,
const
combatant
*
prev
=
nullptr
);
29
30
/** Copy constructor */
31
combatant
(
const
combatant
&that,
const
battle_context_unit_stats
&u);
32
33
combatant
(
const
combatant
&that) =
delete
;
34
combatant
&
operator=
(
const
combatant
&) =
delete
;
35
36
/** Simulate a fight! Can be called multiple times for cumulative calculations. */
37
void
fight
(
combatant
&opponent,
bool
levelup_considered=
true
,
bool
use_biased_rng=
false
);
38
39
/** Resulting probability distribution (might be not as large as max_hp) */
40
std::vector<double>
hp_dist
;
41
42
/** Resulting chance we were not hit by this opponent (important if it poisons) */
43
double
untouched
;
44
45
/** Resulting chance we are poisoned. */
46
double
poisoned
;
47
48
/** Resulting chance we are slowed. */
49
double
slowed
;
50
51
/** What's the average hp (weighted average of hp_dist). */
52
double
average_hp
(
unsigned
int
healing = 0)
const
;
53
54
#if defined(BENCHMARK) || defined(CHECK)
55
// Functions used in the stand-alone version of attack_prediction.cpp
56
void
print
(
const
char
label
[],
unsigned
int
battle,
unsigned
int
fighter)
const
;
57
void
reset();
58
#endif
59
60
const
battle_context_unit_stats
&
u_
;
61
62
private
:
63
static
const
unsigned
int
MONTE_CARLO_SIMULATION_THRESHOLD
= 50000u;
64
65
/** Summary of matrix used to calculate last battle (unslowed & slowed).
66
* Invariant: summary[1].size() == summary[0].size() or summary[1].empty() */
67
std::array<std::vector<double>, 2>
summary
;
68
};
prev
map_location prev
Definition
astarsearch.cpp:64
print
static void print(std::stringstream &sstr, const std::string &queue, const std::string &id)
Definition
fire_event.cpp:30
label
std::string label
What to show in the filter's drop-down list.
Definition
manager.cpp:201
battle_context_unit_stats
Structure describing the statistics of a unit involved in the battle.
Definition
attack.hpp:72
combatant
All combat-related info.
Definition
attack_prediction.hpp:26
combatant::operator=
combatant & operator=(const combatant &)=delete
combatant::slowed
double slowed
Resulting chance we are slowed.
Definition
attack_prediction.hpp:49
combatant::fight
void fight(combatant &opponent, bool levelup_considered=true, bool use_biased_rng=false)
Simulate a fight! Can be called multiple times for cumulative calculations.
Definition
attack_prediction.cpp:2348
combatant::combatant
combatant(const combatant &that)=delete
combatant::hp_dist
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
Definition
attack_prediction.hpp:40
combatant::poisoned
double poisoned
Resulting chance we are poisoned.
Definition
attack_prediction.hpp:46
combatant::MONTE_CARLO_SIMULATION_THRESHOLD
static const unsigned int MONTE_CARLO_SIMULATION_THRESHOLD
Definition
attack_prediction.hpp:63
combatant::u_
const battle_context_unit_stats & u_
Definition
attack_prediction.hpp:60
combatant::summary
std::array< std::vector< double >, 2 > summary
Summary of matrix used to calculate last battle (unslowed & slowed).
Definition
attack_prediction.hpp:67
combatant::average_hp
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
Definition
attack_prediction.cpp:2514
combatant::untouched
double untouched
Resulting chance we were not hit by this opponent (important if it poisons)
Definition
attack_prediction.hpp:43
Generated by
1.9.8