Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Compile: g++ main.cpp -o main --std=c++11 -O2
- */
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <numeric>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- enum dices { skaven = 6, chaos = 4, cursed = 3, bone = 2 };
- int roll(const vector<int> &s) {
- int i, r;
- r = 0;
- for(i = 0; i < s.size(); i++) {
- //Roll dices
- if(rand() % 6 + 1 <= s[i])
- r++;
- }
- return r;
- }
- vector<int> staticsRoll(const vector<int> &s) {
- int i;
- vector<int> r(s.size() + 1, 0);
- for(i = 0; i < 1000000; i++)
- r[roll(s)]++;
- return r;
- }
- void drawResult(const vector<int> &s, const vector<int> &r) {
- int i;
- cout << "Settings: ";
- for(i = 0; i < s.size(); i++) {
- switch(s[i]) {
- case dices::skaven: cout << "Skaven dice"; break;
- case dices::chaos: cout << "Chaos dice"; break;
- case dices::cursed: cout << "Cursed dice"; break;
- case dices::bone: cout << "Bone dice"; break;
- }
- if(i + 1 != s.size())
- cout << ", ";
- }
- cout << endl;
- for(i = 0; i < r.size(); i++) {
- cout << i << " = " << r[i] / 100 / 100.0 << "%" << endl;
- }
- cout << endl;
- }
- int main() {
- vector<int> settings, result;
- srand(time(NULL));
- settings = {
- dices::skaven, dices::skaven, dices::chaos, dices::chaos,
- dices::chaos, dices::cursed, dices::cursed
- };
- result = staticsRoll(settings);
- drawResult(settings, result);
- /* ------------------------------------ */
- settings = {
- dices::skaven, dices::skaven, dices::chaos, dices::chaos,
- dices::chaos, dices::bone, dices::bone
- };
- result = staticsRoll(settings);
- drawResult(settings, result);
- /* ------------------------------------ */
- settings = {
- dices::skaven, dices::chaos, dices::chaos, dices::chaos,
- dices::bone, dices::bone, dices::bone
- };
- result = staticsRoll(settings);
- drawResult(settings, result);
- /* ------------------------------------ */
- settings = {
- dices::bone, dices::bone, dices::bone, dices::bone,
- dices::bone, dices::bone, dices::bone
- };
- result = staticsRoll(settings);
- drawResult(settings, result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment