Documentation
¶
Overview ¶
Package dice provides simple dice-rolling methods allowing rolling of many varieties.
Three methods are exported: Roll(), RollP(), and RollD6(). Roll() receives a textual description of the dice roll (e.g. "3d6+1"), while RollP() receives each parameter separately. RollP() is faster, since it involves no parsing. RollD6() receives the number of 6-sided dice to roll using the D6 system (see README for an explanation).
Index ¶
Examples ¶
Constants ¶
const ( BUFFER_SIZE = 1024 USE_DEV_RANDOM = false )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiceRoll ¶
type DiceRoll struct {
NumberOfDice int
DieFaces int
Adder int
Half bool
Rolls []int
RawTotal int
Total int
}
DiceRoll represents the result of a single dice roll.
NumberOfDice # how many dice are rolled
DieFaces # how many sides on each dice
Adder # static quantity to add to the total of the dice roll
Half # whether a half-die is rolled (in addition to
the number of dice specified in NumberOfDice)
Rolls # the individual dice rolls
RawTotal # the total of all the Rolls, the half-die (if any), and Adder
Total # The maximum of RawTotal and 1
Note that RawTotal can be negative (due to a negative Adder), but Total is never less than 1
func Roll ¶
Roll() generates a new dice roll based on parameters obtained from parsing the passed string.
The expected format is <NumDice>d<DieFaces>[Adder], where NumDice is the number of dice to roll, DieFaces is how many sides per die, and Adder is a static quantity to add to the total. Adder must start with "+" or "-", and NumDice may end with ".5" to indicate a half die.
func RollD6 ¶
RollD6() generates a new DiceRoll based on the D6 system.
The number of dice specified is rolled, the last die being a "wild" die. "Wild" dice trigger an additional "wild" die to be rolled when coming up "6".
func (*DiceRoll) Description ¶
Description returns a textual description of the dice roll. It uses the same format expected by Roll()
Example ¶
dice := RollP(3, 6, -1, false) fmt.Println(dice.Description()) dice = RollP(2, 6, 0, true) fmt.Println(dice.Description())
Output: 3d6-1 2.5d6
Example (Text) ¶
dice, _ := Roll("3d6-2")
fmt.Println(dice.Description())
fmt.Println(dice.NumberOfDice)
fmt.Println(dice.DieFaces)
fmt.Println(dice.Adder)
Output: 3d6-2 3 6 -2