DiceRoll.h header

#include <ew/app/DiceRoll.h>

Namespace ew::app

DiceRollResult struct

struct ew::app::DiceRollResult

The outcome of rolling a dice expression.

Members

bool ew::app::DiceRollResult::valid = false

Whether the notation parsed. When false the other fields are their defaults.

qint64 ew::app::DiceRollResult::total = 0

The final total: the sum of the kept dice plus the modifier. 64-bit so a large (but bounded) dice pool cannot overflow it.

std::vector<int> ew::app::DiceRollResult::rolls

The individual results of the dice that counted toward the total (after any keep-highest / keep-lowest selection), in roll order.

qint64 ew::app::DiceRollResult::modifier = 0

The flat modifier that was added (or subtracted), e.g. +2.

Functions

DiceRollResult ew::app::rollDice(const QString &notation, quint64 seed)

Rolls a dice expression such as "3d6+2", "1d20", "2d8-1", or "4d6kh3" (roll four six-sided dice, keep the highest three) using seed to drive a deterministic pseudo-random sequence, so the same notation and seed always give the same result – reproducible and unit-testable, and suitable for a shareable "seeded roll". The grammar is NdM (N dice of M sides, N and M at least one) with an optional kh<K>/kl<K> keep-highest/keep-lowest suffix (K clamped to [1, N]) and an optional trailing +X/-X modifier; whitespace and case are ignored. The dice count and side count are bounded to sane maxima so a pathological expression cannot exhaust memory; input that is unparseable, out of those bounds, or has an out-of-range modifier returns a result with valid = false.