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 Class Reference

The data model used to represent the pair of dice used to play Game of Ur. More...

#include <dice.hpp>

Public Types

enum  State { UNROLLED , PRIMARY_ROLLED , SECONDARY_ROLLED }
 Values representing all possible states for this pair of dice.
 

Public Member Functions

void reset ()
 Resets the state of the dice to State::UNROLLED.
 
void roll ()
 After validating that a roll is possible, rolls one of the dice.
 
bool canRoll () const
 Tests whether rolling the dice is presently possible.
 
State getState () const
 Gets the current state of the dice.
 
uint8_t getPrimaryRoll () const
 Gets the value of the primary die, between 1 and 4.
 
bool getSecondaryRoll () const
 Gets the value of the secondary die, either Double or Quits.
 
uint8_t getResult (GamePhase currentPhase) const
 Gets the score represented by both dice combined for the current phase of the game.
 

Private Member Functions

uint8_t upgradedRoll () const
 Maps the score of the primary die to its result score if one rolled Double with the secondary die.
 

Private Attributes

uint8_t mPrimaryRoll { 1 }
 The score on the primary die, a value between 1 and 4.
 
bool mSecondaryRoll { false }
 The score on the secondary die, either Double or Quits, where true -> Double, false -> Quits.
 
State mState { UNROLLED }
 The current state of the dice.
 
std::random_device mRandomDevice {}
 The device used as the source of random values.
 
std::default_random_engine mRandomEngine { mRandomDevice() }
 The engine used to produce random values (I don't really know).
 
std::uniform_int_distribution< int > mPrimaryDieDistribution { 1, 4 }
 A meaningful range of integer values used by the primary die, where each value has an even chance of being drawn.
 
std::uniform_int_distribution< int > mYesNoDieDistribution { 0, 1 }
 The range of integer values possible for the secondary die, where each integer has an even chance of being drawn.
 

Detailed Description

The data model used to represent the pair of dice used to play Game of Ur.

Contains methods for querying the current state of the dice, and for performing dice rolls (when valid).

Member Function Documentation

◆ canRoll()

bool Dice::canRoll ( ) const
inline

Tests whether rolling the dice is presently possible.

Return values
trueThe dice can be rolled.
falseThe dice can't be rolled.

◆ getPrimaryRoll()

uint8_t Dice::getPrimaryRoll ( ) const
inline

Gets the value of the primary die, between 1 and 4.

Returns
uint8_t The value of the primary die, between 1 and 4.
See also
mPrimaryRoll

◆ getResult()

uint8_t Dice::getResult ( GamePhase currentPhase) const

Gets the score represented by both dice combined for the current phase of the game.

The table below shows the results returned based on the state of the dice and that of the game:

Primary Roll Secondary Roll INITIATIVE PLAY
- - 0 0
1 - 0 1
2 - 0 2
3 - 0 3
4 - 0 4
1 Quits 1 0
2 Quits 2 0
3 Quits 3 0
4 Quits 4 0
1 Double 5 5
2 Double 6 6
3 Double 7 7
4 Double 10 10

GamePhase::END always produces a score of 0.

Parameters
currentPhaseThe current phase of the game.
Returns
uint8_t The dice score based on game and dice state.

◆ getSecondaryRoll()

bool Dice::getSecondaryRoll ( ) const
inline

Gets the value of the secondary die, either Double or Quits.

Return values
trueThe secondary die says Double.
falseThe secondary die says Quits.
See also
mSecondaryRoll

◆ getState()

State Dice::getState ( ) const
inline

Gets the current state of the dice.

Returns
State The current state of the dice.

◆ roll()

void Dice::roll ( )

After validating that a roll is possible, rolls one of the dice.

If the current state is State::UNROLLED, the primary die is rolled. If State::PRIMARY_ROLLED, the secondary die is rolled.

◆ upgradedRoll()

uint8_t Dice::upgradedRoll ( ) const
private

Maps the score of the primary die to its result score if one rolled Double with the secondary die.

Returns
uint8_t The upgraded value of the current primary die roll.
See also
getResult()

The documentation for this class was generated from the following files: