Class AverageRollExtensions

Namespace
Wolfgang.D20
Assembly
Wolfgang.D20.Dice.dll

Extension methods that compute the average roll of a die or collection of dice, rounded to a whole number.

public static class AverageRollExtensions
Inheritance
AverageRollExtensions
Inherited Members

Remarks

The average roll is the midpoint of the possible results, (MinValue + MaxValue) / 2, which is always a whole number or a half. These methods round that midpoint to an int, which is convenient for tabletop rules that call for average damage rounded a particular way — for example, half damage on a successful save is conventionally rounded down.

Methods

AverageRoundedDown(IDice)

Returns the average roll of the dice, including the modifier, rounded down to the nearest whole number.

public static int AverageRoundedDown(this IDice dice)

Parameters

dice IDice

The dice to average.

Returns

int

The midpoint of MinValue and MaxValue, rounded down.

Examples

// 2d6 averages 7; half damage on a successful save, rounded down, is 3.
int half = new Dice(2, 6).AverageRoundedDown() / 2; // 3

Exceptions

ArgumentNullException

dice is null.

AverageRoundedDown(IDie)

Returns the average roll of the die, rounded down to the nearest whole number.

public static int AverageRoundedDown(this IDie die)

Parameters

die IDie

The die to average.

Returns

int

The midpoint of MinValue and MaxValue, rounded down.

Examples

int average = new Die(6).AverageRoundedDown(); // 3.5 -> 3

Exceptions

ArgumentNullException

die is null.

AverageRoundedUp(IDice)

Returns the average roll of the dice, including the modifier, rounded up to the nearest whole number.

public static int AverageRoundedUp(this IDice dice)

Parameters

dice IDice

The dice to average.

Returns

int

The midpoint of MinValue and MaxValue, rounded up.

Examples

int average = new Dice(2, 6).AverageRoundedUp(); // 7.0 -> 7

Exceptions

ArgumentNullException

dice is null.

AverageRoundedUp(IDie)

Returns the average roll of the die, rounded up to the nearest whole number.

public static int AverageRoundedUp(this IDie die)

Parameters

die IDie

The die to average.

Returns

int

The midpoint of MinValue and MaxValue, rounded up.

Examples

int average = new Die(6).AverageRoundedUp(); // 3.5 -> 4

Exceptions

ArgumentNullException

die is null.