dice

package
v1.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2024 License: MPL-2.0 Imports: 7 Imported by: 9

Documentation

Overview

Package dice simulates dice using standard roleplaying game notation.

Index

Constants

This section is empty.

Variables

View Source
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

func ExtractDicePosition(text string) (start, end int)

ExtractDicePosition returns the start (inclusive) and end (exclusive) index of the Dice specification. If none can be found, -1, -1 will be returned.

func Roll

func Roll(spec string, extraDiceFromModifiers bool) int

Roll the dice. This is short-hand for New(spec).Roll(extraDiceFromModifiers).

Types

type Dice

type Dice struct {
	Count      int
	Sides      int
	Modifier   int
	Multiplier int
}

Dice holds the dice information.

func New

func New(spec string) *Dice

New creates a new Dice based on the given spec.

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

func (dice *Dice) Average(extraDiceFromModifiers bool) int

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) Hash added in v1.10.0

func (dice *Dice) Hash(h hash.Hash)

Hash writes this object's contents into the hasher.

func (*Dice) IsEquivalent

func (dice *Dice) IsEquivalent(other *Dice) bool

IsEquivalent returns true if this Dice is equivalent to another Dice. Normalizes both Dice.

func (Dice) MarshalText

func (dice Dice) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Dice) Maximum

func (dice *Dice) Maximum(extraDiceFromModifiers bool) int

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

func (dice *Dice) Minimum(extraDiceFromModifiers bool) int

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) Normalize

func (dice *Dice) Normalize()

Normalize the internal state.

func (*Dice) PoolProbability

func (dice *Dice) PoolProbability(target int) float64

PoolProbability return the probability that at least one die will be equal to or greater than the target value.

func (*Dice) Roll

func (dice *Dice) Roll(extraDiceFromModifiers bool) int

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) String

func (dice *Dice) String() string

func (*Dice) StringExtra added in v1.3.0

func (dice *Dice) StringExtra(extraDiceFromModifiers bool) string

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

func (dice *Dice) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL