#include "diceroll.hpp" namespace cs427_527 { DiceRoll::DiceRoll() { reroll(); } bool DiceRoll::allSame() const { int num = 0; while (num < NUM_SIDES && counts[num] != NUM_DICE) { num++; } return num < NUM_SIDES; } int DiceRoll::total() const { int sum = 0; for (int i = 0; i < NUM_SIDES; i++) { sum += (i + 1) * counts[i]; } return sum; } int DiceRoll::count(int n) const { return counts[n - 1]; } void DiceRoll::reroll() { for (int n = 0; n < NUM_SIDES; n++) { counts[n] = 0; } for (int i = 0; i < NUM_DICE; i++) { int roll = rand() % NUM_SIDES; counts[roll]++; } } std::ostream& operator<<(std::ostream& os, const DiceRoll& roll) { os << '['; for (int d = 1; d <= DiceRoll::NUM_SIDES; d++) { for (int i = 0; i < roll.count(d); i++) { os << ' ' << d; } } os << " ]"; return os; } }