roll.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // roll.hpp
  3. // dice-roll
  4. //
  5. // Created by Sam Jaffe on 12/1/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <vector>
  10. #include "die.h"
  11. #include "random.h"
  12. namespace dice {
  13. // Describe the actual result of rolling (+/-)NdM
  14. struct die_roll {
  15. // Collapse this roll into its actual value
  16. operator int() const;
  17. // Is this being added, or subtracted from the total
  18. sign sign;
  19. // Since this roll was composed on NdM, rolled.size() == N. Each element
  20. // of rolled is within the integer range [1, M].
  21. std::vector<int> rolled;
  22. };
  23. // Describe the actual result of rolling an arbitrary set of dice with mods
  24. struct dice_roll {
  25. // Collapse this roll into its actual value
  26. operator int() const;
  27. // A vector of component roll results, each on representing a single NdM
  28. // expression.
  29. std::vector<die_roll> sub_rolls;
  30. // A vector of every modifier attached to the system.
  31. std::vector<mod> modifiers;
  32. };
  33. class roller {
  34. public:
  35. roller();
  36. roller(engine::random && g);
  37. /**
  38. * @param d Some dice roll structure, containing any number of dice sets 'NdM'
  39. * as well as any number of roll modifiers (fixed numbers). Additionally,
  40. * can contain a repetition parameter.
  41. * @return A vector of actualized rolls, where `vector.size() == d.num`.
  42. */
  43. std::vector<dice_roll> operator()(dice const & d);
  44. private:
  45. engine::random gen;
  46. };
  47. /**
  48. * Print out the component elements of an actualized dice roll.
  49. * Use instead `out << int(r)` to print the final summation.
  50. */
  51. std::ostream & operator<<(std::ostream & out, dice_roll const & r);
  52. }