Eile Mit Weile
Loading...
Searching...
No Matches
Dice Class Reference

wrapper of a simple RNG with a uniform distribution from 1 to 6 More...

#include <Dice.hpp>

Inheritance diagram for Dice:
UniqueSerializable Serializable

Public Member Functions

 Dice (std::string id, unsigned number, unsigned six_counter)
 
unsigned RollDice ()
 
void ResetSixCounter ()
 
unsigned GetSixCounter ()
 
unsigned GetNumber ()
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
- Public Member Functions inherited from UniqueSerializable
std::string GetId () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override
 
- Public Member Functions inherited from Serializable
virtual rapidjson::DocumentToJson () const
 

Static Public Member Functions

static DiceFromJson (const rapidjson::Value &json)
 

Private Member Functions

 Dice (std::string id, SerializableValue< unsigned int > *number, SerializableValue< unsigned int > *six_counter)
 

Private Attributes

std::random_device _rd
 
std::mt19937 _gen = std::mt19937(_rd())
 
std::uniform_int_distribution _distr = std::uniform_int_distribution<>(1, 6)
 
SerializableValue< unsigned > * _number
 
SerializableValue< unsigned > * _six_counter
 

Additional Inherited Members

- Protected Member Functions inherited from UniqueSerializable
 UniqueSerializable ()
 
 UniqueSerializable (std::string id)
 
- Protected Attributes inherited from UniqueSerializable
std::string id
 

Detailed Description

wrapper of a simple RNG with a uniform distribution from 1 to 6

The dice also keeps track of the number of sixes rolled in a row, which is used to determine whether a player gets an extra turn or needs to move his unsafe figures home.

Constructor & Destructor Documentation

◆ Dice()

Dice::Dice ( std::string  id,
SerializableValue< unsigned int > *  number,
SerializableValue< unsigned int > *  six_counter 
)
private

Deserialization constructor used by FromJson

Member Function Documentation

◆ FromJson()

Dice * Dice::FromJson ( const rapidjson::Value json)
static

Deserializes a Dice object from a json object. Used by client to obtain throw_dice_request result.

◆ GetNumber()

unsigned Dice::GetNumber ( )

Returns _number

◆ GetSixCounter()

unsigned Dice::GetSixCounter ( )

Returns _six_counter

◆ ResetSixCounter()

void Dice::ResetSixCounter ( )

Sets _six_counter to 0

◆ RollDice()

unsigned Dice::RollDice ( )

Returns a random number from 1 to 6 and increases _six_counter if it returns a 6

◆ WriteIntoJson()

void Dice::WriteIntoJson ( rapidjson::Value json,
rapidjson::Document::AllocatorType &  allocator 
) const
overridevirtual

Serializes a Dice object into a json object. Used by server to send throw_dice_request result to client.

Implements Serializable.

Member Data Documentation

◆ _distr

std::uniform_int_distribution Dice::_distr = std::uniform_int_distribution<>(1, 6)
private

Uniform distribution from 1 to 6

◆ _gen

std::mt19937 Dice::_gen = std::mt19937(_rd())
private

RNG with a Mersenne Twister algorithm

◆ _number

SerializableValue<unsigned>* Dice::_number
private

The number rolled by the dice

◆ _rd

std::random_device Dice::_rd
private

Random device used to seed the RNG

◆ _six_counter

SerializableValue<unsigned>* Dice::_six_counter
private

The number of sixes rolled in a row. Should be reset after a player's turn ends.


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