#include "swine.hpp" #include #include #include #include #include "diceroll.hpp" using std::vector; using std::bitset; namespace cs427_527 { SwineGame::SwineGame(int t) { target = t; vector> dice = { vector{1, 2, 3}, vector{4, 5, 6}, vector{1, 3, 5}, vector{2, 4, 6} }; for (const vector& d : dice) { bitset<6> categoryDice; for (int n : d) { categoryDice.set(n - 1); } scoringDice.push_back(categoryDice); } } int SwineGame::countCategories() const { return scoringDice.size(); } int SwineGame::categoryScore(const DiceRoll& roll, int cat) const { int count = 0; for (int d = 1; d <= 6; d++) { if (scoringDice[cat][d - 1] == 1) { count += roll.count(d); } } return count; } SwineScoresheet SwineGame::blankSheet() const { return SwineScoresheet{*this}; } int SwineGame::targetScore() const { return target; } SwineScoresheet::SwineScoresheet(const SwineGame& g) : game(g), scores(g.countCategories(), 0) { } bool SwineScoresheet::isFinished() const { return std::find_if(scores.begin(), scores.end(), [&] (int a) { return a >= game.targetScore(); }) != scores.end(); } void SwineScoresheet::update(int cat, int score) { scores[cat] += score; } int SwineScoresheet::getScore(int cat) const { return scores[cat]; } void SwineScoresheet::output(std::ostream& os) const { os << '['; for (int s : scores) { os << ' ' << s; } os << " ]"; } std::ostream& operator<<(std::ostream& os, const SwineScoresheet& sheet) { sheet.output(os); return os; } }