Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
dice.hpp
Go to the documentation of this file.
1
11
12#ifndef ZOAPPDICE_H
13#define ZOAPPDICE_H
14
15#include <cstdint>
16#include <random>
17
18#include "phase.hpp"
19
27class Dice {
28public:
33 enum State {
34 UNROLLED, //< The dice have not yet been rolled.
35 PRIMARY_ROLLED, //< Only the first of the dice, the one producing its primary roll, has been rolled.
36 SECONDARY_ROLLED, //< Both dice have been rolled (and no further rolls are permitted)
37 };
38
43 void reset();
44
51 void roll();
52
59 inline bool canRoll() const { return mState != SECONDARY_ROLLED; }
60
66 inline State getState() const { return mState; }
67
76 inline uint8_t getPrimaryRoll() const { return mPrimaryRoll; }
77
87 inline bool getSecondaryRoll() const { return mSecondaryRoll; }
88
115 uint8_t getResult(GamePhase currentPhase) const;
116
117private:
125 uint8_t upgradedRoll() const;
126
131 uint8_t mPrimaryRoll { 1 };
132
137 bool mSecondaryRoll { false };
138
143 State mState { UNROLLED };
144
149 std::random_device mRandomDevice {};
150
155 std::default_random_engine mRandomEngine { mRandomDevice() };
156
161 std::uniform_int_distribution<int> mPrimaryDieDistribution { 1, 4 };
162
167 std::uniform_int_distribution<int> mYesNoDieDistribution { 0, 1 };
168};
169
170
171#endif
The data model used to represent the pair of dice used to play Game of Ur.
Definition dice.hpp:27
bool getSecondaryRoll() const
Gets the value of the secondary die, either Double or Quits.
Definition dice.hpp:87
State mState
The current state of the dice.
Definition dice.hpp:143
std::uniform_int_distribution< int > mYesNoDieDistribution
The range of integer values possible for the secondary die, where each integer has an even chance of ...
Definition dice.hpp:167
uint8_t mPrimaryRoll
The score on the primary die, a value between 1 and 4.
Definition dice.hpp:131
State getState() const
Gets the current state of the dice.
Definition dice.hpp:66
std::default_random_engine mRandomEngine
The engine used to produce random values (I don't really know).
Definition dice.hpp:155
uint8_t upgradedRoll() const
Maps the score of the primary die to its result score if one rolled Double with the secondary die.
Definition dice.cpp:44
std::uniform_int_distribution< int > mPrimaryDieDistribution
A meaningful range of integer values used by the primary die, where each value has an even chance of ...
Definition dice.hpp:161
uint8_t getPrimaryRoll() const
Gets the value of the primary die, between 1 and 4.
Definition dice.hpp:76
bool canRoll() const
Tests whether rolling the dice is presently possible.
Definition dice.hpp:59
bool mSecondaryRoll
The score on the secondary die, either Double or Quits, where true -> Double, false -> Quits.
Definition dice.hpp:137
void roll()
After validating that a roll is possible, rolls one of the dice.
Definition dice.cpp:29
State
Values representing all possible states for this pair of dice.
Definition dice.hpp:33
uint8_t getResult(GamePhase currentPhase) const
Gets the score represented by both dice combined for the current phase of the game.
Definition dice.cpp:7
std::random_device mRandomDevice
The device used as the source of random values.
Definition dice.hpp:149
void reset()
Resets the state of the dice to State::UNROLLED.
Definition dice.cpp:5
GamePhase
A value representing the high level phase of an entire game.
Definition phase.hpp:20
Enums whose values represent the different phases a game can be in.