-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiceRoller.cpp
49 lines (42 loc) · 1.31 KB
/
DiceRoller.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
//
// Created by mfbut on 1/23/2018.
//
#include "DiceRoller.h"
#include "MonopolyUtility.h"
Monopoly::DiceRoller::DiceRoller(const std::string& file_name,
const int num_dice_rolled,
const int min_die_value,
const int max_die_value)
: file(file_name), num_dice_rolled(num_dice_rolled), min_die_value(min_die_value), max_die_value(max_die_value) {}
/**
* Roll the specified number of dice and return their sum
* @param numDiceToRoll
* @return
*/
int Monopoly::DiceRoller::getDiceRoll(int numDiceToRoll) {
int num = 0;
prev_die_rolls.clear();
for (int i = 0; i < numDiceToRoll; ++i) {
file >> num;
num = min_die_value + (num % (max_die_value - min_die_value + 1));
prev_die_rolls.push_back(num);
}
return Utility::vector_sum(prev_die_rolls);
}
int Monopoly::DiceRoller::getDiceRoll() {
return getDiceRoll(num_dice_rolled);
}
/**
* Check if any multiples were rolled in the previous roll
* @return
*/
bool Monopoly::DiceRoller::multiplesRolled() const {
for (auto die1 = prev_die_rolls.cbegin(); die1 != prev_die_rolls.cend(); ++die1) {
for (auto die2 = die1 + 1; die2 != prev_die_rolls.cend(); ++die2) {
if (*die1 == *die2) {
return true;
}
}
}
return false;
}