Documentation ¶
Overview ¶
Package dice simulates dice using standard roleplaying game notation.
Index ¶
- Variables
- func ExtractDicePosition(text string) (start, end int)
- func Roll(spec string, extraDiceFromModifiers bool) int
- type Dice
- func (dice *Dice) ApplyExtraDiceFromModifiers()
- func (dice *Dice) Average(extraDiceFromModifiers bool) int
- func (dice *Dice) Hash(h hash.Hash)
- func (dice *Dice) IsEquivalent(other *Dice) bool
- func (dice Dice) MarshalText() (text []byte, err error)
- func (dice *Dice) Maximum(extraDiceFromModifiers bool) int
- func (dice *Dice) Minimum(extraDiceFromModifiers bool) int
- func (dice *Dice) Normalize()
- func (dice *Dice) PoolProbability(target int) float64
- func (dice *Dice) Roll(extraDiceFromModifiers bool) int
- func (dice *Dice) RollWithRandomizer(rnd rand.Randomizer, extraDiceFromModifiers bool) int
- func (dice *Dice) String() string
- func (dice *Dice) StringExtra(extraDiceFromModifiers bool) string
- func (dice *Dice) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var GURPSFormat = false
GURPSFormat determines whether GURPS dice formatting should be used. A value of true means the die count is always shown and the sides value is suppressed if it is a '6', while a value of false means the die count is suppressed if it is a '1' and the sides value is always shown.
Functions ¶
func ExtractDicePosition ¶ added in v1.4.0
ExtractDicePosition returns the start (inclusive) and end (exclusive) index of the Dice specification. If none can be found, -1, -1 will be returned.
Types ¶
type Dice ¶
Dice holds the dice information.
func (*Dice) ApplyExtraDiceFromModifiers ¶
func (dice *Dice) ApplyExtraDiceFromModifiers()
ApplyExtraDiceFromModifiers alters the Dice, converting modifiers greater than or equal to the average result of the base die to extra dice. For example, 1d6+8 will become 3d6+1.
func (*Dice) Average ¶
Average returns the average result. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) IsEquivalent ¶
IsEquivalent returns true if this Dice is equivalent to another Dice. Normalizes both Dice.
func (Dice) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Dice) Maximum ¶
Maximum returns the maximum result. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) Minimum ¶
Minimum returns the minimum result. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) PoolProbability ¶
PoolProbability return the probability that at least one die will be equal to or greater than the target value.
func (*Dice) Roll ¶
Roll returns the result of rolling the dice. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) RollWithRandomizer ¶ added in v1.3.0
func (dice *Dice) RollWithRandomizer(rnd rand.Randomizer, extraDiceFromModifiers bool) int
RollWithRandomizer returns the result of rolling the dice. If 'rnd' is nil, rand.NewCryptoRand() will be used. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) StringExtra ¶ added in v1.3.0
StringExtra returns the text representation of the Dice. 'extraDiceFromModifiers' determines if modifiers greater than or equal to the average result of the base die should be converted to extra dice for the purposes of this call. For example, 1d6+8 will become 3d6+1.
func (*Dice) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.