|
Eile Mit Weile
|
wrapper of a simple RNG with a uniform distribution from 1 to 6 More...
#include <Dice.hpp>
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::Document * | ToJson () const |
Static Public Member Functions | |
| static Dice * | FromJson (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 |
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.
|
private |
Deserialization constructor used by FromJson
|
static |
Deserializes a Dice object from a json object. Used by client to obtain throw_dice_request result.
| unsigned Dice::GetSixCounter | ( | ) |
Returns _six_counter
| void Dice::ResetSixCounter | ( | ) |
Sets _six_counter to 0
| unsigned Dice::RollDice | ( | ) |
Returns a random number from 1 to 6 and increases _six_counter if it returns a 6
|
overridevirtual |
Serializes a Dice object into a json object. Used by server to send throw_dice_request result to client.
Implements Serializable.
|
private |
Uniform distribution from 1 to 6
|
private |
RNG with a Mersenne Twister algorithm
|
private |
The number rolled by the dice
|
private |
Random device used to seed the RNG
|
private |
The number of sixes rolled in a row. Should be reset after a player's turn ends.