-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice_roll.h
38 lines (30 loc) · 820 Bytes
/
dice_roll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef DICE_ROLL_H
#define DICE_ROLL_H
#include <QRandomGenerator>
#include <exprtk/exprtk.hpp>
#include "diceroll.h"
#include "dicerolltracker.h"
template <typename T>
struct dice_roll : exprtk::ifunction<T>
{
dice_roll()
: exprtk::ifunction<T>(2)
{
exprtk::disable_has_side_effects(*this);
}
DiceRollTracker* tracker = nullptr;
inline T operator()(const T& v1, const T& v2) override
{
T sum = T(0);
for (quint32 i = 0; i < quint32(v1); ++i) {
T val = T(QRandomGenerator::global()->bounded(quint32(1), quint32(v2) + 1));
if (tracker != nullptr) {
DiceRoll d = DiceRoll(v2, val);
tracker->append(d);
}
sum += val;
}
return sum;
}
};
#endif // DICE_ROLL_H