-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRollTest.cpp
113 lines (92 loc) · 3.6 KB
/
RollTest.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "probabilityx/Roll.hpp"
#include "probabilityx/dice/RegularDie.hpp"
#include "probabilityx/dice/Modifier.hpp"
#include "probabilityx/dice/MappedRoll.hpp"
#include "probabilityx/dice/XdYRoll.hpp"
#include "probabilityx/Compositors.hpp"
#include "probabilityx/compositors/Common.hpp"
#include "probabilityx/Factory.hpp"
#include "probabilityx/D20.hpp"
#include<ranges>
#include<random>
#include<print>
int main() {
probx::dice::RegularDie die{6};
auto printRoll = [](probx::Rollable auto && roll) {
for(auto outcome : roll) {
std::print(std::cout, "Odds of {}: {:%}\n", outcome, oddsOf(roll, outcome));
}
};
printRoll(die);
std::print(std::cout, "Odds of at least rolling a 3: {:%}\n", probx::oddsAtLeast(die, 3));
std::print(std::cout, "Odds of at most rolling a 2: {:%}\n", probx::oddsAtMost(die, 2));
std::print(std::cout, "Odds of rolling less than 5: {:%}\n", probx::oddsLessThan(die, 5));
std::print(std::cout, "Odds of rolling more than 4: {:%}\n", probx::oddsMoreThan(die, 4));
probx::dice::Modifier mod{3};
printRoll(mod);
std::print(std::cout, "Mean of Regular Die: {:.3f}\n", probx::mean(die));
std::print(std::cout, "Median of Regular Die: {}\n", probx::median(die));
std::print(std::cout, "Max of Modifier: {}\n", probx::max(mod));
std::map<probx::Outcome, probx::BigInt> map;
map[1] = 1;
map[2] = 1;
map[3] = 1;
map[4] = 7;
probx::dice::MappedRoll mapped{map};
printRoll(mapped);
std::minstd_rand engine{std::random_device{}()};
static_assert(std::uniform_random_bit_generator<std::minstd_rand>);
std::print(std::cout, "Randomly generated outcome: {}\n", mapped(engine));
using probx::compositors::adder;
auto twoDSix = probx::composite(adder, die, die, die, probx::dice::Modifier(5));
printRoll(twoDSix);
std::vector<probx::dice::RegularDie> dice;
dice.emplace_back(4);
dice.emplace_back(6);
auto d4d6 = probx::composite(adder, dice);
printRoll(d4d6);
dice = {};
for(int i = 0; i < 4; i++) {
dice.emplace_back(2);
}
auto fourDTwo = probx::composite(adder, dice);
printRoll(fourDTwo);
probx::RollFactory factory{};
std::visit(printRoll, factory.getXdYRoll(2, 6, 2));
std::visit(printRoll, factory.getXdYRoll(1, 6, 2));
auto d5OddD7Even = probx::ternaryComposite(
probx::compositors::evenodd{},
probx::dice::RegularDie{6},
probx::dice::RegularDie{5},
probx::dice::RegularDie{7}
);
printRoll(d5OddD7Even);
namespace d20 = probx::d20;
d20::AttackRules attackRules;
attackRules.attackMod = 5;
attackRules.damageDice = {probx::dice::RegularDie{6}, probx::dice::RegularDie{6}};
attackRules.damageMod = 3;
auto l1Greatsword = d20::getAttackRoll(attackRules);
std::print(std::cout, "\nNow Testing a Level 1 Greatsword!\n\n");
printRoll(l1Greatsword);
std::print(std::cout, "\n=== Mean: {:.3f}\n\n", probx::mean(l1Greatsword));
attackRules.damageRerollThreshold = 2;
auto l1GreatswordGwf = d20::getAttackRoll(attackRules);
printRoll(l1GreatswordGwf);
std::print(std::cout, "\n=== Mean: {:.3f}\n", probx::mean(l1GreatswordGwf));
attackRules.extraAttackDice = {probx::dice::RegularDie{4}};
probx::dice::XdYRoll native3D6{3, 6};
auto factory3D6 = factory.getXdYRoll(3, 6);
printRoll(native3D6);
std::visit(printRoll, factory3D6);
std::print("\n");
/*std::map<probx::Outcome, int> counts;
for(int i = 0; i < 1'000'000; i++) {
counts[native3D6(engine)]++;
}
for(auto [outcome, count] : counts) {
std::print("{:2} : {:5} ({:7.3f}%)\n", outcome, count, count / 10'000.00);
}*/
probx::dice::XdYRoll native400D20{400, 20};
printRoll(native400D20);
}